lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Lucene-java Wiki] Update of "SearchNumericalFields" by Peter W
Date Sun, 24 Jun 2007 03:29:05 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Lucene-java Wiki" for change notification.

The following page has been changed by Peter W:
http://wiki.apache.org/lucene-java/SearchNumericalFields

------------------------------------------------------------------------------
  
  == Use a Custom RangeFilter ==
  
- If you have a size field indexed using NumberTools build a custom RangeFilter to include
a subset such as 1-1500.
+ If you have a size field indexed using NumberTools build a chained RangeFilter to include
a subset such as 1-1500.
- 
+ {{{
  FilteredQuery fq=new FilteredQuery(query,cstm_range("size",1L,1500L)); 
  
  private static Filter cstm_range(String sfld,long lmin,long lmax) 
     { 
-    Filter lessthn_f=RangeFilter.Less(sfld,NumberTools.longToString(lmax)); 
+    Filter lessthn_f=RangeFilter.Less(sfld,NumberTools.longToString(lmax));
-    Filter morethn_f=RangeFilter.More(sfld,NumberTools.longToString(lmin)); 
+    Filter morethn_f=RangeFilter.More(sfld,NumberTools.longToString(lmin));
     Filter[] fa=new Filter[]{lessthn_f,morethn_f}; 
  
     Filter rf=new ChainedFilter(fa,ChainedFilter.AND); 
     return rf; 
     } 
- 
+ }}}
  == Consider Using a Filter ==
  
   Building a Query that for a number (or a range of numbers) is just like building a Query
for a word -- it involves scoring based on the frequency of that word (or number) in the index
which isn't usually what people want.  So you may want to consider "Filtering" using the RangeFilter
class instead.  It can be a lot more efficient then using the RangeQuery class because it
can skip all of the score related issues.

Mime
View raw message