lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kaog <>
Subject TermRangeQuery work not
Date Mon, 21 Dec 2015 23:19:10 GMT
Hi i am kevin from Chile and i am new whit Lucene, 

I have 5 documents. Each document has a field date but i would search on
range date whit TermRangeQuery . Total structure is 
looking like this: 

public static void main(String[] args) throws IOException, ParseException {

    StandardAnalyzer analyzer = new StandardAnalyzer();

    Directory index = new RAMDirectory();

    IndexWriterConfig config = new IndexWriterConfig(analyzer);

    IndexWriter w = new IndexWriter(index, config);
    addDoc(w, "Lucene in Action", "1999-08-12");
    addDoc(w, "Lucene for Dummies", "1998-08-12");
    addDoc(w, "Lucene for chile", "2011-08-12");
    addDoc(w, "Managing Gigabytes", "1995-08-12");
    addDoc(w, "The Art of Computer Science", "2001-08-12");

    BytesRef lowerDate = new BytesRef("2015-08-13");
    BytesRef upperDate = new BytesRef("1998-08-12");

    TermRangeQuery query =  new TermRangeQuery("isbn", lowerDate, upperDate,
true, true);

   // 3. search
    IndexReader reader =;
    IndexSearcher searcher = new IndexSearcher(reader);

   ScoreDoc[] hits =, 100).scoreDocs;

   for(int i=0;i<hits.length;++i) {
      int docId = hits[i].doc;
      Document d = searcher.doc(docId);
      System.out.println((i + 1) + ". " + d.get("date") + "\t" +


  private static void addDoc(IndexWriter w, String title, String date)
throws IOException {
    Document doc = new Document();
    doc.add(new TextField("title", title, Field.Store.YES));

    doc.add(new StringField("date", isbn, Field.Store.YES));
why can i have not result

the result for hits.length() is null

could anyone help me please.. and sorry for my English

View this message in context:
Sent from the Lucene - Java Users mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message