2

I'm using Low Search to search a business directory where individual businesses are tagged with the Solspace Tag module. The search form has a field for keywords and a drop-down list of tags.

Here's the code I have that's working:

      {exp:low_search:form 
        collection="vendors" 
        search_mode="all" 
        result_page="resources/marketplace/search_results"
        query="{freebie_4}"
        loose_ends="yes"
      }
        <fieldset>

            <label for="keywords">Search by keyword</label>
            <input type="search" name="keywords" value="{low_search_keywords}" />

            <label for="search:vendor_services">I need:</label>
            <select name="search:vendor_services">
              <option></option>
              {exp:tag:cloud
                status="open"
                tag_group_name="vendor_service_tags"
              }
              <option{if low_search_search:vendor_services == '{tag}'} selected{/if} value="{tag}">{tag} ({count})</option>
              {/exp:tag:cloud}
            </select>

            <button type="submit">GO</button>

        </fieldset>
      {/exp:low_search:form}

But I'm having trouble getting Low Search to search for an exact match in the tags custom field. For instance, if I search for the tag "farm" I get results with the "farmers market" tag as well.

Adding an '=' sign for an exact match like value="={tag}" only matches if that's the only tag.

Reading this post, it sounds like it might not be possible since I'm trying to do an exact match with multiple values.

Is this possible with Low Search? Or should I be using Solspace's Super Search instead since is has a tag parameter specifically for searching tags?

1
  • 1
    The next version of Low Search, coming next week, will support multiple exact matching like this. Drop me an email at hi at gotolow dot com if you want to give it a go before its official release. – Low Feb 1 '13 at 8:57
0

Unfortunately, there's no way to do this with Low Search at this time. I think there are only two solutions to this problem:

  1. Use Solspace Super Search which includes a method for searching tags.
  2. Use categories instead of Solspace Tags since they are queried via their IDs instead of their actual names.

I went for option 2.

The closest thing getting this to work is to search a field using the "\W" trigger at the end of the term.

<select name="search:vendor_services">
  <option value="foo\W">Foo</option>
  <option value="bar\W">Bar</option>

  …
</select>

This searches for a full word, not a partial word match. It works the same as the search:field-name parameter in the channel entries tag:

http://ellislab.com/expressionengine/user-guide/modules/channel/channel_entries.html#search-field-name

When doing a “Contains” search, ExpressionEngine is literally just looking for matches on the combination of letters given. For instance using “cat” in a “Contains” search would match entries with “cat”, “cats”, “category”, “vocation”, etc. If you need “Contains” matching, but only want entries that include the term as a whole word on its own, you can add the special trigger \W after the term.

The problem with this solution is that Solspace Tags can be multiple words. For instance, searching "farm\W" will find the "farm" tag and ignore a "farmers market" tag, but it would also match a tag like "ant farm" since it also contains a the whole word "farm."

The only way to have this work correctly would be to write an extension for Low Search that searches the tables Solspace Tag creates to store tag data.

3
  • FYI, I'm working on an extension that will allow for better Low Search / Solspace Tag compatibility. Should be finished this week. I'll announce it on Twitter when it's ready. – Low Feb 25 '13 at 9:32
  • Said extension: github.com/lodewijk/low_search_tag – Low Feb 26 '13 at 8:06
  • Perfect! Just what I needed! – Alex Roper Mar 5 '13 at 10:50
0

Low just released an add-on to address searching Solspace Tags. It's called Low Search Tag.

I used the following code to solve my problem:

<select name="tag_id:vendor_service_tags[]">
   <option></option>
   {exp:tag:cloud
     status="open"
     tag_group_name="vendor_service_tags"
   }
     <option value="{tag_id}"{if tag_id IN ({low_search_tag_id:vendor_service_tags})} selected="selected"{/if}>{tag} ({count})</option>
   {/exp:tag:cloud}
</select>

I also added the require_all="tag_id" parameter to the search form since I have multiple selects for searching multiple tag groups at once.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.