lucene bypass parser for search?
I dont think its ne开发者_JS百科eded but i was curious
instead of generating a query string and searching lucene with it (ex "tag: abc 123 id:(2 or 99 or 123)") could i build a struct/class and pass it in?
using lucene.net
Do you mean using directly the query API?
If yes take a look at BooleanQuery
: http://lucene.apache.org/java/2_9_3/api/core/index.html
If you look in the Lucene.Net.Search
namespace you will find a lot of query classes, and then you use the BooleanQuery class to combine them
BooleanQuery mainQuery = new BooleanQuery();
// add terms to the query
mainQuery.Add(new TermQuery(new Term("tag", "abc")), BooleanClause.Occur.MUST);
mainQuery.Add(new TermQuery(new Term("tag", "123")), BooleanClause.Occur.MUST);
// for the parentheses, do a sub BooleanQuery
BooleanQuery idQuery = new BooleanQuery();
idQuery.Add(new TermQuery(new Term("id", "2")), BooleanClause.Occur.SHOULD);
idQuery.Add(new TermQuery(new Term("id", "99")), BooleanClause.Occur.SHOULD);
idQuery.Add(new TermQuery(new Term("id", "123")), BooleanClause.Occur.SHOULD);
// append subquery to the main
mainQuery.Add(idQuery, BooleanClause.Occur.MUST);
Then pass the mainQuery
object to one of the Searcher
's method that takes a query in parameter.
精彩评论