Matching exactly a field

Hello,
I'm using a search that generates that query
http://hostname/trova-prodotto/incoll...

The point is that, for field "criteri_affinamento_3" (it's a checkbox), low matches also "non combacianti" results.
Where I have to use "exact" parameter?
By the way I need this for all parameters. At the moment my result tag is:

{exp:low_search:results
limit="6"
channel="prodotti"
require_all="child:cosa_incolla_relationship|criteri_affinamento_0|criteri_affinamento_1|criteri_affinamento_2|criteri_affinamento_3|criteri_affinamento_4|criteri_affinamento_6|criteri_affinamento_7|criteri_affinamento_8|criteri_affinamento_9|criteri_affinamento_10|criteri_affinamento_11"
orderby="ranking"
sort="asc"
}

Html of the field is

name="search:criteri_affinamento_3[]"

Thanks.

Diego
1 person has
this question
+1
Reply
  • Low (Official Rep) September 07, 2018 13:24
    The tricky thing with checkbox fields is that the value stored are the checked items, each one on a new line.

    Say, for example, you have a checkbox field with the following items:

    - blue
    - dark blue
    - navy
    - sky
    - sapphire

    If you select 'dark blue' and 'sky', the data stored will be:

    dark blue
    sky


    Now, by default, the search:field="foo" parameter generates a substring search, so something like "WHERE field LIKE '%foo%'".

    In the case of the above field, if you search for 'blue' (search:field="blue"), you'd get "WHERE field LIKE '%blue%'" which means it also matches entries where 'dark blue' is selected.

    Now, the exact="" param, which triggers native syntax like this: search:field="=foo", changes this to an exact match, so "WHERE field = 'foo'". When using this in the example above, you'd get "WHERE field = 'blue'", which does not match the entry above, but it will only match entries where only 'blue' is selected -- remember that the field will store each selected item in the field. So, 'blue' != 'blue\nsky' (where \n is a new line).

    This is can be confusing. The "exact" matching applies to the whole content of the field, not to each item of the checkbox list.

    EE does offer some sort of solution (see https://docs.expressionengine.com/lat...) by using search:field="blue\W" you'd not match something like "lightblue", but again, you would get entries for both "blue" and "dark blue", as the query does not differentiate between checkbox items; it just sees the selected items as one string to search on.

    This whole thing can be avoided by using Value/Label pairs https://docs.expressionengine.com/lat... and making sure the values are unique, single-word, and not sub-strings of other labels.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited kidding, amused, unsure, silly

  • Hello, thanks for clarification. By the way, my fields are saved like "field1|field2". But, for data import reasons, sometimes they are saved like "field1|" (with the trailing pipe). Do you think that with an exact match, searching for "field1" will not return "field1|", right? So it's better I change values, if I understand. I used human readable values for SEO reasons, to be honest.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited kidding, amused, unsure, silly

  • Low (Official Rep) September 07, 2018 13:47
    Using a pipe instead of a new line will have the same effect, yes.

    Using human readable values does not do anything for SEO, as the search results use a form that needs to be submitted. As far as I know, search bots do not submit forms and therefore have no access to any search result URLs.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited kidding, amused, unsure, silly

  • Yep, but we thought about linking most common results page on the site. But we will go for another solution.
    Thanks for you help, you are always very helpful!

    Diego
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited kidding, amused, unsure, silly