You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Greg Huber <gr...@gmail.com> on 2015/08/24 11:02:27 UTC
AnalyzingInfixSuggester Lucene 5.3.0
Hello,
I am extending AnalyzingInfixSuggester for use with my suggester where I
change the query to be a AND rather than an OR in the finishQuery(..)
method.
ie
/**
* Subclass can override this to tweak the Query before searching.
*/
protected Query finishQuery(Builder in, boolean allTermsRequired) {
// Update contexts to be ANDs (MUST) rather than ORs (SHOULD)
for (BooleanClause booleanClause : in.build().clauses()) {
// Change the contexts to be MUST (will be the only
BooleanQuery and others will be TermQuery)
if (booleanClause.getQuery() instanceof BooleanQuery) {
BooleanQuery bq = (BooleanQuery) booleanClause.getQuery();
for (BooleanClause bc : bq) {
bc.setOccur(BooleanClause.Occur.MUST);
}
// We are done
break;
}
}
return in.build();
}
It says that BooleanClause.setOccur(..) is depreciated and will be *immutable
in 6.0*, how would I then be able to do this?
http://lucene.apache.org/core/5_3_0/core/org/apache/lucene/search/BooleanClause.html
Cheers Greg
Re: AnalyzingInfixSuggester Lucene 5.3.0
Posted by Arcadius Ahouansou <ar...@menelic.com>.
Hello Greg.
Not a direct answer to your question...
If all you are changing is the default OR into AND, there may be other
alternative like:
- a jira ticket to allow to choose the operator,
- have you looked at the more flexible option where you can pass to
lookup() your own custom built BooleanQuery for filtering? This was
introduced in LUCENE-6464
https://github.com/apache/lucene-solr/blob/5767764a2b621fce76c0b0529ddde550fdc00307/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java#L493
Thanks.
Arcadius.
On 24 August 2015 at 10:02, Greg Huber <gr...@gmail.com> wrote:
> Hello,
>
> I am extending AnalyzingInfixSuggester for use with my suggester where I
> change the query to be a AND rather than an OR in the finishQuery(..)
> method.
>
> ie
>
> /**
> * Subclass can override this to tweak the Query before searching.
> */
> protected Query finishQuery(Builder in, boolean allTermsRequired) {
>
> // Update contexts to be ANDs (MUST) rather than ORs (SHOULD)
> for (BooleanClause booleanClause : in.build().clauses()) {
> // Change the contexts to be MUST (will be the only
> BooleanQuery and others will be TermQuery)
> if (booleanClause.getQuery() instanceof BooleanQuery) {
> BooleanQuery bq = (BooleanQuery) booleanClause.getQuery();
> for (BooleanClause bc : bq) {
> bc.setOccur(BooleanClause.Occur.MUST);
> }
> // We are done
> break;
> }
> }
>
> return in.build();
> }
>
> It says that BooleanClause.setOccur(..) is depreciated and will be
> *immutable
> in 6.0*, how would I then be able to do this?
>
>
> http://lucene.apache.org/core/5_3_0/core/org/apache/lucene/search/BooleanClause.html
>
> Cheers Greg
>
--
Arcadius Ahouansou
Menelic Ltd | Information is Power
M: 07908761999
W: www.menelic.com
---