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 AlexElba <ra...@yahoo.com> on 2010/01/13 18:51:05 UTC

RangeFilter

Hello,

I am currently using lucene 2.4 and have document with 3 fields

id  
name 
rank

and have query and filter when I am trying to use rang filter on rank I am
not getting any result back

RangeFilter rangeFilter = new RangeFilter("rank", "3", "10", true, true);

I have documents which are in this interval 


Any suggestion what am I doing wrong?

Regards




-- 
View this message in context: http://old.nabble.com/RangeFilter-tp27148785p27148785.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.


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


Re: RangeFilter

Posted by Ian Lea <ia...@gmail.com>.
Indexing code looks OK at a glance.  What does the search code look
like?  Should be easy enough to pass a disk based Directory to your
write method to get an index you can look at/play with in Luke.


--
Ian.


On Thu, Jan 14, 2010 at 6:54 PM, AlexElba <ra...@yahoo.com> wrote:
>
> Did you completely re-index?
> Yes I did
>
> Here is method which creates index
>
>
>
> public void write(List<Object[]> data, Directory directory, Analyzer
> analyzer) {
>            IndexWriter  indexWriter = new IndexWriter(directory, analyzer,
>                MaxFieldLength.LIMITED);
>
>        try {
>            for (Object[] obj: data) {
>                try {
>                                        Document document = new Document();
>                                        Field field = new Field("id", obj[0]....
>                                        document.add(field);
>                                        Field rank = new Field("rank", NumberTools
>                    .longToString(Long.valueOf(obj[3])), Store.NO,
> Index.ANALYZED_NO_NORMS);
>                                        document.add(rank);
>                                        indexWriter.addDocument(document);
>                } catch (CorruptIndexException e) {
>
>                } catch (IOException e) {
>
>                }
>            }
>        } finally {
>            try {
>                indexWriter.commit();
>            } catch (CorruptIndexException e) {
>
>            } catch (IOException e) {
>              }
>        }
>    }
>
>
> Yeap I am using luke but this app is ram base index...
>
>
>
> Steven A Rowe wrote:
>>
>> Hi AlexElba,
>>
>> Did you completely re-index?
>>
>> If you did, then there is some other problem - can you share (more of)
>> your code?
>>
>> Do you know about Luke?  It's an essential tool for Lucene index
>> debugging:
>>
>>    http://www.getopt.org/luke/
>>
>> Steve
>>
>> On 01/13/2010 at 8:34 PM, AlexElba wrote:
>>>
>>> Hello,
>>>
>>> I change filter to follow
>>>   RangeFilter rangeFilter = new RangeFilter(
>>>                        "rank", NumberTools
>>>                                 .longToString(rating), NumberTools
>>>                                 .longToString(10), true, true);
>>>
>>> and change index to store rank the same way... But still not seeing :(
>>> any results
>>>
>>>
>>> AlexElba wrote:
>>> >
>>> > Hello,
>>> >
>>> > I am currently using lucene 2.4 and have document with 3 fields
>>> >
>>> > id
>>> > name
>>> > rank
>>> >
>>> > and have query and filter when I am trying to use rang filter on rank I
>>> > am not getting any result back
>>> >
>>> > RangeFilter rangeFilter = new RangeFilter("rank", "3", "10", true,
>>> > true);
>>> >
>>> > I have documents which are in this interval
>>> >
>>> >
>>> > Any suggestion what am I doing wrong?
>>> >
>>> > Regards
>>> >
>>> >
>>> >
>>> >
>>> >
>>>
>>> -- View this message in context: http://old.nabble.com/RangeFilter-
>>> tp27148785p27155102.html Sent from the Lucene - Java Users mailing list
>>> archive at Nabble.com.
>>>
>>>
>>> --------------------------------------------------------------------- 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
>>
>>
>>
>
> --
> View this message in context: http://old.nabble.com/RangeFilter-tp27148785p27166330.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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


RE: RangeFilter

Posted by AlexElba <ra...@yahoo.com>.
Did you completely re-index?
Yes I did 

Here is method which creates index



public void write(List<Object[]> data, Directory directory, Analyzer
analyzer) {
            IndexWriter  indexWriter = new IndexWriter(directory, analyzer,
                MaxFieldLength.LIMITED);
		
        try {
            for (Object[] obj: data) {
                try {
					Document document = new Document();
					Field field = new Field("id", obj[0]....
					document.add(field);		
					Field rank = new Field("rank", NumberTools
                    .longToString(Long.valueOf(obj[3])), Store.NO,
Index.ANALYZED_NO_NORMS);
					document.add(rank);
					indexWriter.addDocument(document);
                } catch (CorruptIndexException e) {
                    
                } catch (IOException e) {
                    
                }
            }
        } finally {
            try {
                indexWriter.commit();
            } catch (CorruptIndexException e) {
  
            } catch (IOException e) {
              }
        }
    }


Yeap I am using luke but this app is ram base index...



Steven A Rowe wrote:
> 
> Hi AlexElba,
> 
> Did you completely re-index?
> 
> If you did, then there is some other problem - can you share (more of)
> your code?
> 
> Do you know about Luke?  It's an essential tool for Lucene index
> debugging:
> 
>    http://www.getopt.org/luke/
> 
> Steve
> 
> On 01/13/2010 at 8:34 PM, AlexElba wrote:
>> 
>> Hello,
>> 
>> I change filter to follow
>>   RangeFilter rangeFilter = new RangeFilter(
>>                        "rank", NumberTools
>>                                 .longToString(rating), NumberTools
>>                                 .longToString(10), true, true);
>> 
>> and change index to store rank the same way... But still not seeing :(
>> any results
>> 
>> 
>> AlexElba wrote:
>> > 
>> > Hello,
>> > 
>> > I am currently using lucene 2.4 and have document with 3 fields
>> > 
>> > id
>> > name
>> > rank
>> > 
>> > and have query and filter when I am trying to use rang filter on rank I
>> > am not getting any result back
>> > 
>> > RangeFilter rangeFilter = new RangeFilter("rank", "3", "10", true,
>> > true);
>> > 
>> > I have documents which are in this interval
>> > 
>> > 
>> > Any suggestion what am I doing wrong?
>> > 
>> > Regards
>> > 
>> > 
>> > 
>> > 
>> > 
>> 
>> -- View this message in context: http://old.nabble.com/RangeFilter-
>> tp27148785p27155102.html Sent from the Lucene - Java Users mailing list
>> archive at Nabble.com.
>> 
>> 
>> --------------------------------------------------------------------- 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
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/RangeFilter-tp27148785p27166330.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.


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


RE: RangeFilter

Posted by Steven A Rowe <sa...@syr.edu>.
Hi AlexElba,

Did you completely re-index?

If you did, then there is some other problem - can you share (more of) your code?

Do you know about Luke?  It's an essential tool for Lucene index debugging:

   http://www.getopt.org/luke/

Steve

On 01/13/2010 at 8:34 PM, AlexElba wrote:
> 
> Hello,
> 
> I change filter to follow
>   RangeFilter rangeFilter = new RangeFilter(
>                        "rank", NumberTools
>                                 .longToString(rating), NumberTools
>                                 .longToString(10), true, true);
> 
> and change index to store rank the same way... But still not seeing :(
> any results
> 
> 
> AlexElba wrote:
> > 
> > Hello,
> > 
> > I am currently using lucene 2.4 and have document with 3 fields
> > 
> > id
> > name
> > rank
> > 
> > and have query and filter when I am trying to use rang filter on rank I
> > am not getting any result back
> > 
> > RangeFilter rangeFilter = new RangeFilter("rank", "3", "10", true,
> > true);
> > 
> > I have documents which are in this interval
> > 
> > 
> > Any suggestion what am I doing wrong?
> > 
> > Regards
> > 
> > 
> > 
> > 
> > 
> 
> -- View this message in context: http://old.nabble.com/RangeFilter-
> tp27148785p27155102.html Sent from the Lucene - Java Users mailing list
> archive at Nabble.com.
> 
> 
> --------------------------------------------------------------------- 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


Re: RangeFilter

Posted by AlexElba <ra...@yahoo.com>.
Hello,

I change filter to follow
  RangeFilter rangeFilter = new RangeFilter(
                       "rank", NumberTools
                                .longToString(rating), NumberTools
                                .longToString(10), true, true);

and change index to store rank the same way... But still not seeing :( any
results 


AlexElba wrote:
> 
> Hello,
> 
> I am currently using lucene 2.4 and have document with 3 fields
> 
> id  
> name 
> rank
> 
> and have query and filter when I am trying to use rang filter on rank I am
> not getting any result back
> 
> RangeFilter rangeFilter = new RangeFilter("rank", "3", "10", true, true);
> 
> I have documents which are in this interval 
> 
> 
> Any suggestion what am I doing wrong?
> 
> Regards
> 
> 
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/RangeFilter-tp27148785p27155102.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.


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


Re: RangeFilter

Posted by AlexElba <ra...@yahoo.com>.
Thanks Steve.

Mike for now I can not upgrade... 
-- 
View this message in context: http://old.nabble.com/RangeFilter-tp27148785p27151315.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.


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


Re: RangeFilter

Posted by Michael McCandless <lu...@mikemccandless.com>.
Actually, as of Lucene 2.9 (if you can upgrade), you should use
NumericField to index numerics and NumericRangeQuery to do range
search/filter -- it all just works -- no more padding.

Mike

On Wed, Jan 13, 2010 at 1:17 PM, Steven A Rowe <sa...@syr.edu> wrote:
> Hi AlexElba,
>
> The problem is that Lucene only knows how to handle character strings, not numbers.  Lexicographically, "3" > "10", so you get the expected results (nothing).
>
> The standard thing to do is transform your numbers into strings that sort as you want them to.  E.g., you can left-pad the "rank" field values with zeroes: "03", "04", ..., "10", and then create a RangeFilter over "03" .. "10".  You will of course need to left-zero-pad to at least the maximum character length of the largest rank.
>
> Facilities to handle this problem are available in NumberTools:
>
> <http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/document/NumberTools.html>
>
> (Note that NumberTools converts longs to base-36 fixed-length padded strings.)
>
> More info here:
>
>   <http://wiki.apache.org/lucene-java/SearchNumericalFields>
>
> Steve
>
> On 01/13/2010 at 12:51 PM, AlexElba wrote:
>>
>> Hello,
>>
>> I am currently using lucene 2.4 and have document with 3 fields
>>
>> id
>> name
>> rank
>>
>> and have query and filter when I am trying to use rang filter on rank I
>> am not getting any result back
>>
>> RangeFilter rangeFilter = new RangeFilter("rank", "3", "10", true, true);
>>
>> I have documents which are in this interval
>>
>>
>> Any suggestion what am I doing wrong?
>>
>> Regards
>
> ---------------------------------------------------------------------
> 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


RE: RangeFilter

Posted by Steven A Rowe <sa...@syr.edu>.
Hi AlexElba,

The problem is that Lucene only knows how to handle character strings, not numbers.  Lexicographically, "3" > "10", so you get the expected results (nothing).

The standard thing to do is transform your numbers into strings that sort as you want them to.  E.g., you can left-pad the "rank" field values with zeroes: "03", "04", ..., "10", and then create a RangeFilter over "03" .. "10".  You will of course need to left-zero-pad to at least the maximum character length of the largest rank.

Facilities to handle this problem are available in NumberTools:

<http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/document/NumberTools.html>

(Note that NumberTools converts longs to base-36 fixed-length padded strings.)

More info here:

   <http://wiki.apache.org/lucene-java/SearchNumericalFields>

Steve

On 01/13/2010 at 12:51 PM, AlexElba wrote:
> 
> Hello,
> 
> I am currently using lucene 2.4 and have document with 3 fields
> 
> id
> name
> rank
> 
> and have query and filter when I am trying to use rang filter on rank I
> am not getting any result back
> 
> RangeFilter rangeFilter = new RangeFilter("rank", "3", "10", true, true);
> 
> I have documents which are in this interval
> 
> 
> Any suggestion what am I doing wrong?
> 
> Regards

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