I am a bit confused as to how to structure an examine query the requires a single Field of value X Or Y Or Z - in my cast Wine Type of Red, White or Other.
Below is the search I am running. If I select just one type of wine from the options I get all the wines of that type as expected. If however I select more than one the OR statement is ignored and I only get the first wine type selected. The code executes correctly and inspecting the filter shows that the required wine types did get added but they are not reflected.
var criteria = ExamineManager.Instance.SearchProviderCollection["WineSearcher"].CreateSearchCriteria();
IBooleanOperation filter = null;
foreach (ListItem li in chkWineType.Items.Cast<ListItem>().Where(li => li.Selected))
if (filter == null)
{
filter = criteria.Field("WineType", li.Text.Escape());
}
else
{
filter.Or().Field("WineType", li.Text.Escape());
}
// no error checking yet that filter was set
mSearchResults = ExamineManager.Instance.SearchProviderCollection["WineSearcher"].Search(filter.Compile());
The 2nd option may not work right, I haven't really tested the default boolean operation change. But the reason you aren't getting the results you need is that the first statement in the fluent API defaults to an AND statement, meaning you get this:
+WineType:White WineType:Red +__IndexType:content
And that's why the first one is always there. GroupedOr is your safest bet IMO.
Examine query syntax - Or().Field ignored
I am a bit confused as to how to structure an examine query the requires a single Field of value X Or Y Or Z - in my cast Wine Type of Red, White or Other.
Below is the search I am running. If I select just one type of wine from the options I get all the wines of that type as expected. If however I select more than one the OR statement is ignored and I only get the first wine type selected. The code executes correctly and inspecting the filter shows that the required wine types did get added but they are not reflected.
Travis,
Change your code
to
i have done something similar although mine was and not or.
Regards
Ismail
You can solve this in 1 of 2 ways, by using the GroupedOr statement or changing the default boolean operation.
GroupedOr
This will create a grouped statement using WineType and the items in the check box list, resulting in this Lucene query when you compile:
Changing default boolean operation
Then you can use the original code and you should get this:
The 2nd option may not work right, I haven't really tested the default boolean operation change. But the reason you aren't getting the results you need is that the first statement in the fluent API defaults to an AND statement, meaning you get this:
And that's why the first one is always there. GroupedOr is your safest bet IMO.
Thanks! I was starting to look at GroupedOr last night when I ran out of energy.
is working on a reply...