I used a similar technique to search in a category hierarchy. I use the following method to build a query, leaving the hard work to the QueryParser class. Usually I add this query to BooleanQuery.
QueryParser usually does a great job of this, I often use it to create most of my Lucene queries - it seems to work better than me when you create a specific query a lot of time!
Another thing you can do is use QueryParser to create it, then set a breakpoint and see how the query was created, and then update the code using a specific type of query.
private Query GetQuery(Sitecore.Data.ID id)
{
string categoryId = id.Guid.ToString();
StandardAnalyzer analyzer = new StandardAnalyzer();
QueryParser parser = new QueryParser("categories", analyzer);
Query query = parser.Parse(categoryId);
return query;
}
source
share