All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Page links in a search result are not working when the search keyword is a space or blank

Eric 15 Jan 2012 03:02 problem, complete

Hi, I'm working on a site that uses Low Search with 2 collections: pages and news. The News entries are managed by EE and the Pages entries are managed by Structure. So, to get the search result links to work for both types of entries, I used the following:
{title}

According to the developers, I need use {page_url} or {page_uri} for links to pages managed by Structure.

Now, everything works fine if you search using a word or letter. However, if you search with a blank keyword or type in one or more spaces and search, none of the link urls created from {page_url} work, but the ones created from {comment_url_title_auto_path} do work.

When I search with one or more spaces and then a letter, {page_url} works like it should.

Are there any other variables I can use in place of {page_url}? I tried {auto_path} but it didn't generate any correct urls.

I guess if there's no fix for this I can just block those types of searches. I've prevented blank searches by using required="keywords" in the {exp:low_search:form} tag, but how do I prevent searches containing only spaces?

Replies

  1. Low 15 Jan 2012 13:52

    Hi Eric,

    I cannot reproduce the problem with the {page_uri} and {page_url} variables not working. Searches without keywords (or spaces only, which are treated the same way) still parse the two vars.

    Can you show me the exact template code you're using? You can use pastie.org to copy/paste your code without it being mangled by GetSat.

  2. Eric 15 Jan 2012 18:09

    Here's the search form: http://pastie.org/private/ytfoilyehvd...

    and the results page: http://pastie.org/private/omjxkqv1d58...

    Thanks,
    Eric

  3. Low 15 Jan 2012 18:41

    Okay, here's what's going on. The keyword-less search doesn't perform an actual search on the custom index table, it just sets the right parameters for you so the channel entries are filtered correctly. That's why there's no low_search_score per entry, but more importantly in your case, no association with a search collection. The variable {low_search_collection_name} will be empty because of that.

    Instead of using that variable for your conditional, try using the channel short name, e.g.:

    {if channel_short_name == 'pages'}{page_url}{if:else}{comment_url_title_auto_path}{/if}


    Let me know if that helps.

  4. Eric 15 Jan 2012 19:19

    That fixed it... I forgot I could still use exp:channel:entries variables. Thanks!

  5. Low 15 Jan 2012 19:22

    Cool, glad it works now.