views:

149

answers:

1

I'm using Sitecore and have a multilist field I'd like to use Lucene to search on. The problem I have is that the field is a pipe-delimited list of actual values and there could be between 0 and an infinite (theoretically speaking, actually there's probably only a thousand or two possibilities) number of items in this list. I haven't been able to successfully use a wildcard query and I can't envision how to break this field up into multiple fields since there's an unknown number of items in the list.

+2  A: 

I've used a similar technique in searches to search within a category heirarchy. I use the following method to build the query, leaving the hard work to the QueryParser class. I usually add this query to a BooleanQuery.

The QueryParser usually does a great job, I often use it for building most of my Lucene queries - it seems to do a better job than me when building a specific query a lot of the time!!

Another thing you can do is to use the QueryParser to build it, then set a breakpoint and have a look at how the query has been created, then update your code with the specific query type.

private Query GetQuery(Sitecore.Data.ID id)
{
    string categoryId = id.Guid.ToString(); //turn ID to string
    StandardAnalyzer analyzer = new StandardAnalyzer(); //use standard analyzer
    QueryParser parser = new QueryParser("categories", analyzer); //search inside category field
    Query query = parser.Parse(categoryId); //get the query
    return query;
}
misteraidan