lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ian Lea <ian....@gmail.com>
Subject Re: how to create a range query with string parameters
Date Tue, 17 May 2011 15:42:24 GMT
It's likely to have something to do with analyzers.  That is the
usually the first thing to come to mind if queries hold upper or mixed
case terms.  Maybe Luke is using an analyzer that matches the one you
used when you indexed your documents.

You can use Luke to see what is being stored in the index.   See also
http://wiki.apache.org/lucene-java/LuceneFAQ#Why_am_I_getting_no_hits_.2BAC8_incorrect_hits.3F


Something that looks OK here but might bite you in the future is if
your article fields aren't always in the same format and of the same
length.  The comparison is a simple string based one and if you had,
say, l123-1, l1-123, l19999-999 the range matching might not give you
what you expected.

--
Ian.


On Tue, May 17, 2011 at 3:41 PM, G.Long <jdevgl@gmail.com> wrote:
> Hi Uwe :)
>
> Thank you for your answer ! Now I have another problem. Here is the code I
> use to query the index :
>
> ScoreDoc[] hits = null;
>        TopFieldCollector collector = TopFieldCollector.create(new
> Sort(SortField.FIELD_DOC), 200000, true, false, false, false);
>        Directory directory = FSDirectory.open(new File("/home/user/index"));
>
>        IndexSearcher isearcher = new IndexSearcher(directory);
>        Query tQueryCode = new TermQuery(new Term(FIELD_CODE, "CCOM"));
>        Query tQueryCodeRef = new TermQuery(new Term(FIELD_CODE_REF,
> "CCOM"));
>        Query rQuery = new TermRangeQuery(FIELD_ARTICLE, "l110-1", "l146-4",
> true, true);
>
>        BooleanQuery bQuery = new BooleanQuery();
>        bQuery.add(tQueryCode, Occur.MUST);
>        bQuery.add(tQueryCodeRef, Occur.MUST);
>        bQuery.add(rQuery, Occur.MUST);
>
>        System.out.println(bQuery.toString());
>
>        isearcher.search(bQuery, collector);
>        hits = collector.topDocs().scoreDocs;
>
>        System.out.println(hits.length);
>
> The query is : +code:CCOM +codeRef:CCOM +article:[l110-1 TO l146-4]
>
> The hits[] is equal to Zero although there should be hits. I'm using a
> program called lukeall 3.1 which provide
> a GUI to query a lucene index. When I copy the query into this program and
> run it, it return a lot of results =o
>
> So I guess I'm missing something. I thought about a missing analyzer but I'm
> not sure...
>
> Regards,
> Gary
>
> Le 17/05/2011 14:02, Uwe Schindler a écrit :
>>
>> Hi,
>>
>> Query q = new TermRangeQuery(...)
>>
>> Uwe
>>
>> -----
>> Uwe Schindler
>> H.-H.-Meier-Allee 63, D-28213 Bremen
>> http://www.thetaphi.de
>> eMail: uwe@thetaphi.de
>
>
> ---------------------------------------------------------------------
> 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