I have this code to build a dynamic Query with Examine:
var criteria = searchProvider.CreateSearchCriteria(IndexType.Content); IBooleanOperation query = ????? ;
if (!string.IsNullOrEmpty(q)) query = query.And().GroupedOr(new[] { "title", "bodyText", "abstract" }, new[] { q }); if (!string.IsNullOrEmpty(Request["type"])) query = query.And().Field("type", Request["type"].Escape()); if (!string.IsNullOrEmpty(Request["tag"])) query = query.And().Field("tags", Request["tag"].Escape());
var results = searchProvider.Search(query.Compile());
But I'm not sure how go get from criteria to Iboolean operator where all clauses are optional. (well there should be at least one, but it can be any one)
I could create each permutation but that would be messy.
If you don't have any common operation between the queries you can't do what you want. Looking at your logic it'd be possible to get through the if statements without any condition being hit.
If you've got a pre-existing query you can create a local variable of type IBooleanOperation which doesn't have an assignment, it's only assigned in the IF statement.
You'd just have to make sure your conditionals cover all paths or your app wont compile ;)
Examine - Dynamic Queries
I have this code to build a dynamic Query with Examine:
But I'm not sure how go get from criteria to Iboolean operator where all clauses are optional. (well there should be at least one, but it can be any one)
I could create each permutation but that would be messy.
If you don't have any common operation between the queries you can't do what you want. Looking at your logic it'd be possible to get through the if statements without any condition being hit.
Thanks, "no" is a perfectly valid answer :-) ... BTW, I'd have an earlier condition to check that any one of 'tag', 'type' or 'q' is set.
If you've got a pre-existing query you can create a local variable of type IBooleanOperation which doesn't have an assignment, it's only assigned in the IF statement.
You'd just have to make sure your conditionals cover all paths or your app wont compile ;)
is working on a reply...