1

I have a Field Pack - Checkbox field (named doctors_schedule_now) with the following values:

nephrology : Nephrology
pediatric-nephrology : Pediatric Nephrology

In my entry, I'm checking the box for Nephrology. This populates in my DB field like this:

nephrology

Then I'm using Low Search to search in this custom field. This is the parameter I'm passing in the exp:low_search:results tag:

search:doctors_schedule_now='nephrology'

This search parameter will return entries that have both "pediatric-nephrology" and "nephrology" checkboxes chosen. This is not what I want, so I modified the search parameter like this (with exact matching):

search:doctors_schedule_now='=nephrology'

This will return only entries with the "nephrology" checkbox chosen - great! But wait. If I choose both checkboxes - "nephrology" and "pediatric-nephrology", it populates my DB like this:

nephrology(paragraph return)pediatric-nephrology

Now I can no longer use the exact parameter because the field has multiple values. And, I still need to return entries ONLY entries with "nephrology" chosen. So, I cannot use the parameter like this:

search:doctors_schedule_now='nephrology'

Because it returns entries that have either "nephrology" OR "pediatric-nephrology" checkboxes chosen. In other words, this search parameter returns not only "nephrology" but also "pediatric-nephrology"

1
  • I think you have to decide what search you want to carry out if both boxes are ticked - you say that if just 'Nephrology' is ticked you get the search that you want, but that if both boxes are ticked you don't. This implies that you want the same search results to be generated regardless of whether 'Pediatric Nephrology' is ticked: in which case I wonder why you have included it in the form... If actually you want to run a different search if both are ticked, knowing what this other search is would help work out what you need to do. – JCOGS Design Oct 22 '16 at 0:18
1

You're looking for EE's \W suffix, see the docs:

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.

search:body="cat\W"

The above example will return all entries that contain the whole word “cat”. It will not match entries where the phrase “cat” only lies within another word.

This behaviour is achievable by setting the contains_words parameter in Low Search, see the docs on the Field Search filter.

Given your example, combining parameters like this should give you the desired results:

search:doctors_schedule_now='nephrology' contains_words='search:doctors_schedule_now'

Edit

Actually, the query generated with those rules, will be a MySQL regexp with word boundaries. Which, according to MySQL means:

A word is a sequence of word characters that is not preceded by or followed by word characters. A word character is an alphanumeric character in the alnum class or an underscore (_).

This means a dash (-) is considered a word boundary, and therefore, both entries will be returned in the above scenario. If you change the value from pediatric-nephrology to pediatric_nephrology, then the above parameters can differentiate between the two.

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.