lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cecil, Paula New" <c...@fuse.net>
Subject Attribute Search Bug
Date Thu, 29 Nov 2001 05:28:10 GMT
This program illustrates what may be a bug.  It creates an index, a document
with two fields.  The second field is the problem.  I use the Field
constructor to make a field that is not stored, is indexed, not tokenized
(there is no factory method for this combination).

The program then queries on the second field and no hits are returned.

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;

import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.document.*;
import org.apache.lucene.search.*;
import org.apache.lucene.queryParser.QueryParser;

public class Bug1 {
  public static void main(String[] args) throws Exception {
    String indexPath = "./bugdex";
    String fieldName = "catno";
    String fieldValue= "AB12-42 2X";
    IndexWriter writer;

    // An index is created by opening an IndexWriter with the
    // create argument set to true.
    writer = new IndexWriter(indexPath, null, true);
    writer.close();

    // now index a document
    try {
      writer = new IndexWriter(indexPath, new SimpleAnalyzer(), false);

      Document doc = new Document();
      // add id as unindexed - can't search, but it is stored
      doc.add(Field.UnIndexed("id", "12345"));
      doc.add(new Field(fieldName,fieldValue,false,true,false));
      writer.addDocument(doc);
      writer.close();

    } catch (Exception e) {
        e.printStackTrace();
    }

    // now make a query and search for document
    Searcher searcher = new IndexSearcher(indexPath);
    Query query = QueryParser.parse(fieldValue, fieldName,
                              new SimpleAnalyzer());
    Hits hits = searcher.search(query);
    for (int i=0; i<hits.length(); i++) {
      System.out.println(
        "id "+hits.doc(i).get("id") + "; Score: " + hits.score(i));
    }
    System.out.println("\nNumber of hits: "+ hits.length());
  }
}



----- Original Message -----
From: Doug Cutting <DCutting@grandcentral.com>
To: 'Lucene Users List' <lucene-user@jakarta.apache.org>
Sent: Monday, November 26, 2001 2:42 PM
Subject: RE: Attribute Search


> > From: New, Cecil (GEAE) [mailto:cecil.new@ae.ge.com]
> >
> > this is exactly what I was doing.  Store=false, index=true,
> > and token=false.
> >
> > It appeared to work ok, but searches *never* returned any hits.
> >
> > That's why I suspect it is a bug.
>
> If you think this is a bug, please submit a test case, as a simple class
> whose 'main()' method illustrates the problem.
>
> Doug
>
> --
> To unsubscribe, e-mail:
<mailto:lucene-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:lucene-user-help@jakarta.apache.org>
>



--
To unsubscribe, e-mail:   <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>


Mime
View raw message