Filtering by multiple values on a field with lucene local indexes.

Michael Legacy asked on October 14, 2019 15:47

Hey all, I am wondering if there is any syntax for searching multiple values on a Field in lucene?

For example, I have a field called "employmentType" and I want to filter by the possible values of "Full - Time" and "Part - Time". All my filters work if there is only 1 value selected.

I have tried multiple ways and done some searching on Google but nothing that really matched what I need. Would prefer if there was a way to do using the built in Smart Search and not building a custom indexer class since that's the way it's currently built.

Any help is appreciated.

Correct Answer

Dmitry Bastron answered on October 15, 2019 10:32

That's really strange. Could you show how do you perform search in the code? White space analyzer and this search request +fld_jp_position_category_code:(nursing OR professional OR alliedhealth) should work fine. It works for me.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Dmitry Bastron answered on October 14, 2019 16:12

Hey Michael,

A few steps to achieve this (based on your example):

  • In "employmentType" index field you should store keys (non-display names) joined by " " (space), i.e.: "full_time" and "part_time" in your case
  • Then in Search fields menu in your Page Type settings for field "employmentType" you should tick Searchable and Tokenized tickboxes
  • Rebuild your search index
  • After these steps you should be able to perform this Lucene search: +employmentType:(full_time) +employmentType:(part_time)

Key thing is to store no-space keys joined by space. When you select "tokenize" setting then the system will break this field by space automatically. From my experience, I store GUIDs instead of keys there.

0 votesVote for this answer Mark as a Correct answer

Michael Legacy answered on October 14, 2019 16:20 (last edited on October 14, 2019 16:24)

Dmitry, is this possible without doing a custom indexer class? Or no? Those values do actually get displayed on the front-end, so I can't alter them in the custom table to not have the spaces. I am able to achieve the search using a single value filter with the space by escaping the space and dash IE:

+employmentType:Full\ \-\ Time

Any documentation on how to acheive the below? I am a bit unclear on how to do this:

"Key thing is to store no-space keys joined by space. When you select "tokenize" setting then the system will break this field by space automatically. From my experience, I store GUIDs instead of keys there."

I already have the fields I need multiple values set as "Searchable" and "Tokenized". Currently using the "Whitespace Analyzer" as my analyzer.

Just for reference, this is a custom table, not a page type. I doubt that changes anything, but food for thought.

0 votesVote for this answer Mark as a Correct answer

Michael Legacy answered on October 14, 2019 19:27 (last edited on October 14, 2019 19:31)

Okay, I actually just kind of tried a "hack" and made a second field in my custom table, and when importing this data, I'm removing all spaces and dashes and setting them to underscores. That gives me data like "full_time" and "part_time".

The new fields is set as "Searchable" and "Tokenized" in the custom table "Search Fields" area. Still not able to query off multiple as you put in your answer. Any idea why that might be? An example below of a real query I'm trying with a similar field:

+fld_jp_position_category_code:(allied_health) +fld_jp_position_category_code:(food_services)

This query is not working in Luke where i am testing everything. Should i try something other than the Whitespace analyzer?

I do see in the "Explain structure" tab of Luke that both of those clauses are "MUST" types and I'm looking for more of a "food_services" OR "allied_health" type of query. Bit confused.

0 votesVote for this answer Mark as a Correct answer

Michael Legacy answered on October 14, 2019 20:14

Making some headway. Went even further and removed the underscores from the imported data as well in the second fields. So now allied_health is just alliedhealth and so on.

This syntax now works in Luke, but it's not working in Kentico. Any suggestions would be helpful:

+fld_jp_position_category_code:(nursing OR professional OR alliedhealth)
0 votesVote for this answer Mark as a Correct answer

Michael Legacy answered on October 15, 2019 23:40

Dmitry,

I ended up getting it to work. I think after I figured out that final syntax i posted above, i needed to refresh my indexes and everything started working.

Have a functioning filter now! Thanks so much!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.