lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Kazekin <Michael.Kaze...@mediainsight.info>
Subject Re: Null scorer constructed by TermQuery
Date Tue, 31 Jan 2012 08:29:52 GMT
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


Mime
View raw message