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 kaog <kv...@gmail.com> on 2015/12/22 00:19:10 UTC

TermRangeQuery work not

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");
    w.close();

    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 = DirectoryReader.open(index);
    IndexSearcher searcher = new IndexSearcher(reader);

   ScoreDoc[] hits = searcher.search(query, 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" +
d.get("title"));

  reader.close();
  }

  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));
    w.addDocument(doc);
  }
why can i have not result

the result for hits.length() is null

could anyone help me please.. and sorry for my English
thankĀ”




--
View this message in context: http://lucene.472066.n3.nabble.com/TermRangeQuery-work-not-tp4246519.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: TermRangeQuery work not

Posted by Michael Wilkowski <mw...@silenteight.com>.
You mixed lowerDate with upperDate.

MW
Sent from Mi phone
On 25 Dec 2015 16:41, "kaog" <kv...@gmail.com> wrote:

> hi
> I did the change of variable "ISBN, it was a mistake I did when I wrote in
> the post. unfortunately still it does not work TermRangeQuery. :(
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/TermRangeQuery-work-not-tp4246519p4247358.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: TermRangeQuery work not

Posted by kaog <kv...@gmail.com>.
hi
I did the change of variable "ISBN, it was a mistake I did when I wrote in
the post. unfortunately still it does not work TermRangeQuery. :(



--
View this message in context: http://lucene.472066.n3.nabble.com/TermRangeQuery-work-not-tp4246519p4247358.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: TermRangeQuery work not

Posted by Uwe Schindler <uw...@thetaphi.de>.
Hi,

Your addDoc method indexes wrong contents for the date field. It uses some field named ISBN.

Uwe

Am 22. Dezember 2015 00:19:10 MEZ, schrieb kaog <kv...@gmail.com>:
>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");
>    w.close();
>
>    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 = DirectoryReader.open(index);
>    IndexSearcher searcher = new IndexSearcher(reader);
>
>   ScoreDoc[] hits = searcher.search(query, 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" +
>d.get("title"));
>
>  reader.close();
>  }
>
>  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));
>    w.addDocument(doc);
>  }
>why can i have not result
>
>the result for hits.length() is null
>
>could anyone help me please.. and sorry for my English
>thankĀ”
>
>
>
>
>--
>View this message in context:
>http://lucene.472066.n3.nabble.com/TermRangeQuery-work-not-tp4246519.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

--
Uwe Schindler
H.-H.-Meier-Allee 63, 28213 Bremen
http://www.thetaphi.de