I have a field in examine that I want to query against. This field typically has a comma separated value like this:
["Military","Graduates","Apprentices"]
I want to be able to pass through another list of terms to see if there is a match i.e. return result if page/media contains "Graduates","Apprentices".
Does anyone know how to do this? I suspect I'd use the GroupedOr, but I can only see how you pass through multiple fields but only a single value and not multiple values.
Okay so the first thing to note is that Examine doesn't like commas. So I would advise hooking into indexing events and updating the index value to replace comma's with spaces.
(Note: Callum's Search Extensions package might do this for you, I've not played with it yet, but it looks awesome).
As for searching, you would do a grouped or like this:
As I'm comparing two lists against each other, would this approach still work?
If I changed the list from using commas to using spaces (so it looks like a sentence basically), what would the string array of values be? will it still work if the values are still comma separated?
So in the index, this:
["Military","Graduates","Apprentices"]
becomes:
Military Graduates Apprentices
But the values I pass through are still this: Military, Graduates
In your case you'd code would be simpler as it would take a string, split it on ,'s to turn it into an array of string and index the array as individual items
Then that search I suggested would do the following:
if myFieldCleaned contains any of my search terms, return the result
Searching in examine - one field multiple values
Hi,
I have a field in examine that I want to query against. This field typically has a comma separated value like this:
["Military","Graduates","Apprentices"]
I want to be able to pass through another list of terms to see if there is a match i.e. return result if page/media contains "Graduates","Apprentices".
Does anyone know how to do this? I suspect I'd use the GroupedOr, but I can only see how you pass through multiple fields but only a single value and not multiple values.
Thanks
Hey Paul,
Okay so the first thing to note is that Examine doesn't like commas. So I would advise hooking into indexing events and updating the index value to replace comma's with spaces.
(Note: Callum's Search Extensions package might do this for you, I've not played with it yet, but it looks awesome).
As for searching, you would do a grouped or like this:
.GroupedOr(new [] {"fieldAlias"}, myStringArrayOfValues)
This should create you the correct lucene I believe.
Cheers
Nik
Hi Nik,
Thanks for the speedy response :)
As I'm comparing two lists against each other, would this approach still work?
If I changed the list from using commas to using spaces (so it looks like a sentence basically), what would the string array of values be? will it still work if the values are still comma separated?
So in the index, this:
["Military","Graduates","Apprentices"]
becomes:
Military Graduates Apprentices
But the values I pass through are still this: Military, Graduates
Thanks
So you have different options to be honest.
What I do these days is the following.
Doing something a bit like this (my example is handling MNTP's)
In your case you'd code would be simpler as it would take a string, split it on ,'s to turn it into an array of string and index the array as individual items
Then that search I suggested would do the following:
if myFieldCleaned contains any of my search terms, return the result
At least that is my understanding
Also your search term would need to be like this:
Which will put it in the right format.
Hi Nik,
Where would this code go? Do I need to put it into a component?
Thanks
For anyone else reading this. I did indeed have to create a component to run this code.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.