lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uwe Schindler" <...@thetaphi.de>
Subject RE: Null scorer constructed by TermQuery
Date Tue, 31 Jan 2012 08:50:30 GMT
Hi,

As this was originally a Solr index, are you sure, that the term is exactly
in *that* spelling (including case) in the index? You should open the index
with the Luke desktop tool and inspect the term index! Solr uses an analyzer
when indexing or searching, so depending on the Solr config, it might be
that the term is "normalized" or changed in any other way inside the index.
TermQuery does not analyze, it looks up the raw term.

Btw: SegmentReader.open(...) is wrong, must be IndexReader.open(), it just
works because SR is a subclass and you can call static methods in
subclasses.

Uwe

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de

> -----Original Message-----
> From: Michael Kazekin [mailto:Michael.Kazekin@mediainsight.info]
> Sent: Tuesday, January 31, 2012 9:30 AM
> To: java-user@lucene.apache.org
> Subject: Re: Null scorer constructed by TermQuery
> 
> Uwe, thank you very much for such verbose answer!
> 
> I tried the code you mentioned ( searcher.createNormalizedWeight(query) ),
> but it doesn't work on Lucene 3.5 for me either :(
> 
> My Solr server returns the document correctly on specified term (field and
> value), field is indexed and stored.
> 
> I'm really stuck on it, because the API code seems to be simple and has to
> behave as expected, index exists, solr returns correct results.
> 
> May be you have some thoughts on it, because my knowledge of "inner
Lucene"
> is not very good.
> 
> My code is:
> 
>          File file = new File(luceneDir);
> 
>          Preconditions.checkArgument(file.isDirectory(), "Lucene
> directory: " + file.getAbsolutePath() + " does not exist or is not a
directory");
> 
>          Directory directory = FSDirectory.open(file); //index exists,
> 
>          IndexReader reader = SegmentReader.open(directory, true);
> 
>          IndexSearcher searcher = new IndexSearcher(reader);
> 
>          TermQuery termQuery = new TermQuery(new Term("lang", "en"));
> 
> 
>          Weight weight = searcher.createNormalizedWeight(termQuery);
> 
>          Scorer scorer = weight.scorer(reader, true, false);
> 
>          System.out.println("scorer = " + scorer); //outputs "scorer =
null"
> 
> 
> 
> On 01/27/2012 08:46 PM, Uwe Schindler wrote:
> > One addition:
> >
> > In general, your way how to get a scorer from a query is not supported
> > (and does not work correct for all queries), the right way is *not* to
> > use
> > query.createWeight(searcher) but instead
> > searcher.createNormalizedWeight(query).
> >
> > But that has nothing to do with the null scorer, which is a valid
> > return value if the term does not exist and no docs can ever match.
> >
> >> You are creating a TermScorer on a composite (non atomic IndexReader
> >> like SegmentReader). That's still supported in 3.x, but no longer
> >> allowed in
> > 4.0.
> >> The backwards layer in 3.x had a bug before Lucene 3.5, so
> >> theoretically
> > your
> >> code should work on 3.5:
> >> https://issues.apache.org/jira/browse/LUCENE-3442
> >>
> >> But still: null is a valid return value for scorer()!!! It may return
> > null, if no
> >> document can  match this query. Means the term does not exist at all.
> >>
> >> Uwe
> >>
> >> -----
> >> Uwe Schindler
> >> H.-H.-Meier-Allee 63, D-28213 Bremen
> >> http://www.thetaphi.de
> >> eMail: uwe@thetaphi.de
> >>
> >>
> >>> -----Original Message-----
> >>> From: Michael Kazekin [mailto:Michael.Kazekin@mediainsight.info]
> >>> Sent: Friday, January 27, 2012 4:39 PM
> >>> To: java-user@lucene.apache.org
> >>> Subject: Null scorer constructed by TermQuery
> >>>
> >>> Hi!
> >>>
> >>> I have a Solr-constructed index, which I read with this code:
> >>>
> >>> Directory directory = FSDirectory.open(file); IndexReader reader =
> >>> IndexReader.open(directory, true); IndexSearcher searcher = new
> >>> IndexSearcher(reader);
> >>>
> >>> I try to get a Scorer with this TermQuery ("lang" field is indexed
> >>> and
> >> stored and
> >>> all data is available)
> >>>
> >>> TermQuery atomQuery = new TermQuery(new Term("lang", "ru"));
> >>>
> >>> Weight weight = atomQuery.createWeight(searcher); Scorer scorer =
> >>> weight.scorer(reader, true, false);
> >>>
> >>>
> >>>
> >>> after this scorer is null.
> >>>
> >>>
> >>>
> >>> Does anyone know, what could be the problem here?
> >>>
> >>> I tried it with Solr. 3.4 and with Solr 3.5, results are the same.
> >>>
> >>> --------------------------------------------------------------------
> >>> - To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> >>> For additional commands, e-mail: java-user-help@lucene.apache.org
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> >> For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> >
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message