lucene3.0.3 | get correct document in case of multiple Boolean query in search criteria
I am using query like
criteria = (sql OR sqlserver OR "sql server") AND java AND delphi .
In this case when i am using default parser as code mention below:
QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, field, analyzer);
Query query = parser.parse(criteria);
I am getting same number of document when i am using QueryParser.OR_OPERATOR in code below:
QueryPar开发者_运维技巧ser parser = new QueryParser(Version.LUCENE_CURRENT, field, analyzer);
parser.setDefaultOperator(QueryParser.OR_OPERATOR);
Query query = parser.parse(criteria);
which is not correct. please! suggest me feasible solution.
how could get correct document in case of multiple Boolean query in search criteria?
If your query specifies the operator as you did in:
criteria = (sql OR sqlserver OR "sql server") AND java AND delphi
then setting the default operator has no effect. If you had instead specified your query as follows:
criteria = (sql sqlserver "sql server") java delphi
then setting the default operator to OR would cause the query to be interpreted as:
criteria = (sql OR sqlserver OR "sql server") OR java OR delphi
By the way, the default operator for QueryParser is OR - see Lucene QueryParser javadoc
From your code, your query searches all Documents in the index where field contains the terms "java" and "delphi", and one or more of {sql, sqlserver, "sql server"}. There's nothing syntactically or conceptually wrong with what you've presented, so I suspect that the issue is with how the field has been indexed. I would recommend picking up Luke and using it to analyze your index.
精彩评论