[
https://issues.apache.org/jira/browse/LUCENE-5766?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Adrien Grand closed LUCENE-5766.
--------------------------------
Resolution: Cannot Reproduce
I don't understand why not cloning is an issue and I could not reproduce the
issue:
{code}
private static BooleanQuery should(Query q) {
BooleanQuery bq = new BooleanQuery();
bq.add(q, Occur.SHOULD);
return bq;
}
public static void main(String[] args) throws Exception {
try (Directory dir = new RAMDirectory();
IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(new
WhitespaceAnalyzer()))) {
Document doc = new Document();
doc.add(new TextField("title", "at", Store.NO));
w.addDocument(doc);
w.commit();
try (DirectoryReader reader = DirectoryReader.open(dir)) {
FuzzyQuery fuzzyQuery = new FuzzyQuery(new Term("title", "at"), 1);
Query query = fuzzyQuery;
query = should(query);
query.setBoost(2);
query = should(query);
query = should(query);
query.setBoost(4.5f);
System.out.println(query);
Query rewritten = query.rewrite(reader);
System.out.println(rewritten);
}
}
}
{code}
which prints
{code}
((((title:at~1)^2.0)))^4.5
(title:at)^9.0
{code}
Closing it for now, please reopen if you can still reproduce and share what
query parser you are using.
> bug in rewrite function of boolean query
> ----------------------------------------
>
> Key: LUCENE-5766
> URL: https://issues.apache.org/jira/browse/LUCENE-5766
> Project: Lucene - Core
> Issue Type: Bug
> Reporter: Wang Han
>
> when optimize boolean query. When the only query sub clause has a boost with
> 1.0, it should be cloned too.
> if (minNrShouldMatch == 0 && clauses.size() == 1) { //
> optimize 1-clause queries
> BooleanClause c = clauses.get(0);
> if (!c.isProhibited()) { // just return clause
> Query query = c.getQuery().rewrite(reader); // rewrite first
> if (getBoost() != 1.0f) { // incorporate boost
> if (query == c.getQuery()) { // if rewrite was
> no-op
> query = query.clone(); // then clone before boost
> }
> // Since the BooleanQuery only has 1 clause, the BooleanQuery will
> be
> // written out. Therefore the rewritten Query's boost must
> incorporate both
> // the clause's boost, and the boost of the BooleanQuery itself
> query.setBoost(getBoost() * query.getBoost());
> }
> return query;
> }
> }
> when boolean query nested in a disjunction query, rewrite function return the
> original term query without clone and may cause bad boost value in upper
> queries. Delete the if statement and always do
> if (query == c.getQuery()) { // if rewrite was no-op
> query = query.clone(); // then clone before boost
> }
> can fix this bug.
> sample query may cause this bug: ((+((title:at)~1^2.0)))^4.5 after rewrite
> the query will be changed to ((+((title:at)~1^9.0)))^4.5 and Query.clone()
> won't work for this problem because your lazy clone strategy.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]