Force location search to only look at starting letters?

This topic contains 8 replies, has 3 voices, and was last updated by  Kiran 4 years, 1 month ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #537758

    Duane Siebert
    Expired Member
    Post count: 37

    Hello, GD support folks.

    Is there any way to force location search to only match starting letters?

    IMHO it is absolutely idiotic (I’m not one to hold back…) for the search to look for matches appearing anywhere in the city/state string.

    As an example, no one who is looking for a city that starts with “Tav” has any interest in cities like “Altavista” or “Batavia” just because “tav” happens to appear deep within the city name.

    From the attached screenshot you will see there are only two cities that should appear from among our listings and they are, “Tavares” and “Tavernier”.

    All of the other suggested cities are absolutely worthless.

    In concert with that, is there a way to force the search to be a “Near” search (instead of an “In” search) so listings within a particular radius are automatically included?

    (Since website visitors are quick to leave a site I don’t want to have to include extra explanatory info to tell them to “Start your search with “Near: ” and then type your city, state in after that” since most will never do that and be disappointed with a smaller number of results and bolt.)

    Even if I make that suggestion, the search results come up incomplete (as shown in images 2 and 3).

    If I search on “Near: tav” not only do cities appear for which I have no listings, it also does not include all cities for which I do have listings (is there any way to make GD return results only for a particular country?)

    It returns Tavares, FL, but leaves out Tavernier, FL.

    If I search on “Near: tave” it finally includes Tavernier (which should have been a match for cities beginning with “tav” in the first place).

    I have learned within the last week or two that implementing SOLR would address all of these problems but the cost to do that is many times more than the cost of a GD annual subscription.

    Making the search match on “cities that begin with ‘tav’…” seems so fundamental.

    I’m open to any/all suggestions (as long as they don’t cost hundreds or thousands of dollars more than GD costs.)

    Rant over… (for now, at least)

    Thank you,

    Duane

    #537826

    Alex Rollin
    Moderator
    Post count: 27815

    Thanks for your post, the developers will take a look if they can recommend anything about that.

    #537898

    Duane Siebert
    Expired Member
    Post count: 37

    Thank you, Alex.

    Just that one “Search from the first characters” tweak would be a huge improvement!

    BTW, is there a way to force it to always display “Near” results in the dropdown of city/state vs. “In”?

    Also, in “Near” searches, is there a way to force GD to only display listings in the USA?

    Those things would get us far closer to where we want to be.

    Thank you, again, Alex,

    Duane

    #537992

    Kiran
    Moderator
    Post count: 7069

    Hi Duane,

    Try following PHP snippet to force location search to only look at starting letters

    
    
    /**
     * Force location search to only look at starting letters.
     */
    function gd_snippet_200402_search_by_starting_letters( $sql, $args, $params ) {
    	if ( !empty( $args['search'] ) ) {
    		$search = "'%" . wp_slash( $args['search'] ) . "%'";
    		$replace = "'" . wp_slash( $args['search'] ) . "%'";
    		$sql = str_replace( $search, $replace, $sql );
    	}
    	return $sql;
    }
    add_filter( 'geodir_location_get_locations_sql', 'gd_snippet_200402_search_by_starting_letters', 20, 3 );

    is there a way to force it to always display “Near” results in the dropdown of city/state vs. “In”?

    Try to submit search without selecting autocomplete result.

    In “Near” searches, is there a way to force GD to only display listings in the USA?

    Select United States from the location autocomplete results.

    Kiran

    #538033

    Duane Siebert
    Expired Member
    Post count: 37

    Thank you, Kiran.

    Though I have been working on our site for quite some time, I apologize in advance for not being an expert.

    So, where would that PHP code you created be inserted?

    As for your answer regarding, “Is there a way to force it to always display “Near” results?”

    “Try to submit search without selecting autocomplete result.”

    I can do that for myself, but to have to somehow explain to each and every visitor “Don’t Click On The Links!” is not appealing, at all (not to mention how many people would read the admonition and how many fewer people would follow that advice?)

    It would be so much nicer in the backend to have settings to “Display In: results? Yes/No” “Display Near: results Yes/No”

    With regard to “Select United States from the location autocomplete results” is that a backend setting or are you once again suggesting we somehow explain to visitors to ignore the dropdowns for countries they aren’t interested in?

    Thank you, Kiran.

    Duane

    #538039

    Duane Siebert
    Expired Member
    Post count: 37

    It looks as if that code worked. Thank you!

    Now my life would be complete (okay, I apparently don’t have very lofty goals…) if the search could be forced to return “Near:” results and not “In:” results.

    (I already have a “radius” feature on our homepage where if someone ends up on the Near: option they can specify 10, 20, 30, 40 or 50 miles)

    So, close…!

    If we could force it to display “Near: ” results my life would be golden!

    Thank you, Kiran.

    Duane

    #538096

    Alex Rollin
    Moderator
    Post count: 27815

    Hi,

    What Kiran means is that anything you type into the Near search field is a Near search.

    It is only possible to do an IN search if the IN autocomplete recommendation is selected.

    You can now disable the recommendations for that field, which makes it possible to insure that the user enters a city or some other location there.

    We also have some CSS to hide near or near me selections individually here:

    https://wpgeodirectory.com/docs-v2/faq/common-examples/#gd_search

    Scroll the box to see all the CSS there.

    #538133

    Duane Siebert
    Expired Member
    Post count: 37

    Thank you, Alex.

    That’s still the “problem” as I see it.

    A visitor won’t know (nor will care) what “Near” vs. “In” means (without significant explanation, at least, which, as I mentioned, I am trying to avoid).

    For me (the average mope…) if I start typing something in and suggestions appear, I am going to click on the match I was going for.

    So, if I do that in this case, though the field started out saying “Near”, the autocomplete suggestions are “In” and when selected render our radius option unusable.

    When you say, “You can now disable the recommendations for that field, which makes it possible to insure that the user enters a city or some other location there.”, are you referring to GD > Advanced Search > Autocompleter Settings?

    We’ll try the CSS options you provided and see if we can nail it.

    Hoping for success!

    Thank you, as always, Alex!

    Duane

    #538195

    Kiran
    Moderator
    Post count: 7069

    Hi Duane,

    Un-tick “GeoDirectory > Settings > Locations > Enable location search autocompleter?” to disable autocomplete search on search form.

    OR

    Try following CSS to hide In: results.

    
    
    .geodir-listing-search ul.gdlmls-neighbourhood,
    .geodir-listing-search ul.gdlmls-city,
    .geodir-listing-search ul.gdlmls-region,
    .geodir-listing-search ul.gdlmls-country {
    	display: none !important;
    }

    Thanks,
    Kiran

Viewing 9 posts - 1 through 9 (of 9 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket