Lucene.Net Search List

I use Sitecore and have a multi-sheeted field that I would like to use to search Lucene. The problem is that the field is a list of actual values ​​separated by the handset, and there can be between 0 and an infinite (theoretically, in fact, perhaps only a thousand or two possibilities) number of elements in this list. I could not successfully use the wildcard query, and I cannot imagine how to split this field into several fields, because the list has an unknown number of elements.

+3
source share
1 answer

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(); //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;
}
+5
source

Source: https://habr.com/ru/post/1725890/


All Articles