Examine Search Results With Multiple Checkboxlists
Hi there
My first time implementing Examine / Lucene search and I choose to do so with 5 checkboxlists - arghh !
My desired result is that the user can make multiple choices across any or all of 5 checkbox lists and my search results will display accordingly.
To kick things off here is my code for filtering on the selections of the first checkbox list
// Set criteria var criteria = ExamineManager.Instance.SearchProviderCollection["RFCRecordsSearcher"].CreateSearchCriteria();
//Make initial selection of all items in the index var query = criteria.NodeTypeAlias("changeRequest");
//If any project managers have been selected add filter if (countProjectMgrs > 0) { var selectedProjectManagerValues = (from item in cblITProjectManagers.Items.Cast<ListItem>() where item.Selected select item.Text).ToArray(); var selectedProjectManagerValuesJoined = (countProjectMgrs > 1 ? "(+" + string.Join(" +", selectedProjectManagerValues) + ") " : cblITProjectManagers.SelectedValue); query = query.And().GroupedAnd(new[] { "iTProjectManager" }, selectedProjectManagerValuesJoined); }
If I only tick one Project Manager I am getting the correct results. However if more than one is ticked I get no results.
Being new to Examine and the Fluent query language, this is just a guess :-)
Could it be that you need to use the BooleanOperation.Or to get the correct Lucene searchterm? Right now it seems that you're performing a search in Lucene with the query being: "+ property:SearchTerm" where you would need it to be something like "property:SearchTerm" instead.
but I still get the same output - no data on multiple selection, correct data on single selection.
I need to keep Googling - the article you reference was written by Peter Gregory who recently provided training for Level 1 and 2 so I might send him a note...
O.k, so 1952 and 1740 seems to be Node id's ? :-) And your Examine index is set to index those aswell?
Also, just to break it down, have you tried to hardcode some values into the search criteria to see if it shows up? If not, try to hit your web.config and upload it again to recycle the application. This should force your index to be created again.
Alright, well I've been searching a bit on this and all I could find is a semi-ugly approach when searching in one field for n values. Something like this (put on your "ugly-but-should-work-glasses" now):
var searchTerms = new string[] { "1952", "1740" }; foreach(string term in searchTerms) { query = query.And().Field("iTProjectManager", term); }
Again, not sure on the syntax.
Anyway, it's getting late here, so I better hit the sack instead of keep pushing some random non-working cowboy-code your way ;-)
Examine Search Results With Multiple Checkboxlists
Hi there
My first time implementing Examine / Lucene search and I choose to do so with 5 checkboxlists - arghh !
My desired result is that the user can make multiple choices across any or all of 5 checkbox lists and my search results will display accordingly.
To kick things off here is my code for filtering on the selections of the first checkbox list
If I only tick one Project Manager I am getting the correct results. However if more than one is ticked I get no results.
Can anyone please advise where my code is wonky ?
Thanks
Nigel
Hi Nigel,
Being new to Examine and the Fluent query language, this is just a guess :-)
Could it be that you need to use the BooleanOperation.Or to get the correct Lucene searchterm? Right now it seems that you're performing a search in Lucene with the query being: "+ property:SearchTerm" where you would need it to be something like "property:SearchTerm" instead.
There's a more in-depth article on this here: http://umbraco.com/follow-us/blog-archive/2011/9/16/examining-examine.aspx
.. at about half-way down the page.
Don't know if this is of any help at all (?)
- Bo
Hi Bo
Thanks for your reply but no joy yet..
I tried:
and I tried:
but I still get the same output - no data on multiple selection, correct data on single selection.
I need to keep Googling - the article you reference was written by Peter Gregory who recently provided training for Level 1 and 2 so I might send him a note...
Thanks again.
Nigel
Hi Nigel,
Alright, was worth a shot.
Have you checked which values there's in your string array? Just to be sure the values actually exists :-)
- Bo
Ahh good point - will do some checking now...
N
OK...
For a single selection the data benig input is just the node ID which is valid data and returning correct matches.
For multiple selections the data is being formatted as:
I have also tried changing it to simply output
this also didn't work.
Thanks for your help Bo - will be a happy chap when I can crack this one...
Nigel
Hi Nigel,
O.k, so 1952 and 1740 seems to be Node id's ? :-) And your Examine index is set to index those aswell?
Also, just to break it down, have you tried to hardcode some values into the search criteria to see if it shows up? If not, try to hit your web.config and upload it again to recycle the application. This should force your index to be created again.
- Bo
Hey Bo
You are correct the ID's are Node ID's and that is what is being indexed.
A single selection of Project Manager is returning correct values so the index appears to be correctly setup.
I truly appreciate your proactive thinking and participation - thank you.
Nigel
Hi Nigel,
No worries, i'm just curious on this really :-)
Can you please try to set your query variable to this:
var query = criteria.GroupedOr(new string[] { "Id" }, new string[] { "1952", "1740" });
(forgive me if the syntax is incorrect, writing straight in the editor)
Just to see if there's any output at all..
Thanks!
- Bo
Hi Bo
No go on that either I'm afraid...
My code was:
as iTProjectManager is the field being indexed.
A single selection returns correct results, a multiple selection returns no results. So again it is very close, but yet so far....
Thanks again for your time / assistance - time to take a break from it I think and come back to it later...
Cheers
Nigel
Hi Nigel,
Alright, well I've been searching a bit on this and all I could find is a semi-ugly approach when searching in one field for n values. Something like this (put on your "ugly-but-should-work-glasses" now):
var searchTerms = new string[] { "1952", "1740" };
foreach(string term in searchTerms)
{
query = query.And().Field("iTProjectManager", term);
}
Again, not sure on the syntax.
Anyway, it's getting late here, so I better hit the sack instead of keep pushing some random non-working cowboy-code your way ;-)
- Bo
Hi Bo
Perseverance paid off...
The (rather verbose) code is:
Hope this helps someone else at some stage.
Nigel
Hi Nigel,
Glad you solved it! I'm sure this will be helpful for others aswell.
- Bo
is working on a reply...