Hello,

I'm trying to do a numerical search for a property in Lucene using RangeFilter.Less
without using both RangeQuery and test cases.

Here's the code that I expect would return one hit :
(adapted from Youngho)

import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.document.*;
import org.apache.lucene.index.*;
import org.apache.lucene.search.*;
import org.apache.lucene.store.*;
import java.io.IOException;
import java.io.Serializable;
import java.util.*;

public class doesRFLwork
   {
   private static Directory ramdir;
   public static void main(String[] args)
      {
      try
         {
         setdocs();
         runfilterquery();
         }
      catch(Exception e)
         {
         System.out.println(e);
         }
      } // main

   protected static void setdocs() throws Exception
      {
      ramdir=new RAMDirectory();
      adddocs();
      }

   public static void runfilterquery() throws Exception
      {
      IndexSearcher searcher=new IndexSearcher(ramdir);
Filter filter=RangeFilter.Less("num",NumberTools.longToString(10L));

      Term term=new Term("id","property");
      Query query=new TermQuery(term);

      FilteredQuery fq = new FilteredQuery(query,filter);

      Hits hits = searcher.search(fq);
System.out.println("property found,less than 10: " +hits.length());
      }

   private static void adddocs() throws IOException
      {
IndexWriter writer=new IndexWriter(ramdir,new SimpleAnalyzer(), true);
      Document doc=new Document();
doc.add( new Field("id","property",Field.Store.YES,Field.Index.TOKENIZED) ); doc.add( new Field("num",NumberTools.longToString(5L),Field.Store.YES,Field.Index.TOK ENIZED) );

      writer.addDocument(doc);
      writer.optimize();
      writer.close();
      }
   }

Since five is less than ten, why doesn't it work?

Thanks.

Peter W.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to