apache / apache/lucene

ComplexPhraseQuery.rewrite throws "Unknown query type:org.apache.lucene.search.SynonymQuery" when nested BooleanQuery contains a SynonymQuery [LUCENE-8495]

Open
#9,541 1 comment 0 reactions 0 assignees View on GitHub
affects-version:7.4 affects-version:8.0 legacy-jira-priority:Major module:core/queryparser type:bug
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

When using nested queries in ComplexPhrases, and a part of the query is a SynonymQuery, an exception is thrown from  addComplexPhraseClause:

`throw new IllegalArgumentException("Unknown query type:"`
` + childQuery.getClass().getName());`

Examples (dogs and tv are synonyms):

`"(cats OR dogs) cigar"`

"platform\* (video\* OR tv)"\~10

The bug is similar in nature to #9352, in that SynonymQuery support was added to ComplexPhraseQueryParser (in LUCENE-7695), but was not expanded to nested queries.

The fix is similar to the one in #9352, namely to add the same logic in addComplexPhraseClause as in rewrite.

See attached patch.

---
Migrated from [LUCENE-8495](https://issues.apache.org/jira/browse/LUCENE-8495) by Bjarke Mortensen, updated May 05 2021
Attachments: [0001-Added-support-for-nested-synonym-queries-in-ComplexP.patch](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-8495/0001-Added-support-for-nested-synonym-queries-in-ComplexP.patch)

Contributor guide

Open the contributing guide

Research direction

Start in ComplexPhraseQueryParser, comparing addComplexPhraseClause with rewrite, as described in the issue and attached patch. Reproduce the nested SynonymQuery examples and verify that ComplexPhrase queries containing nested synonyms no longer throw the unknown-query-type exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.