lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Friedman <pfried...@macromedia.com>
Subject Keyword search with punctuation?
Date Wed, 07 Nov 2001 22:44:59 GMT
I am unable to find the expected documents when I execute a query on a
keyword whose value contains punctuation.
 
Here is the test case:
 
import org.apache.lucene.queryParser.*; 
import org.apache.lucene.search.*; 
import org.apache.lucene.index.*; 
import org.apache.lucene.analysis.*; 
import org.apache.lucene.analysis.standard.*;
import org.apache.lucene.document.*; 
 
public class KeywordTest { 
 
    public static void main(String args[]) throws Exception {
 
        Analyzer analyzer = new StandardAnalyzer(); 
        IndexWriter writer = new IndexWriter("index", analyzer, true); 
 
        Document d3 = new Document();
        d3.add(Field.Keyword("id","person/john"));
        d3.add(Field.Text("macrinstfulltext","male married"));
        writer.addDocument(d3);
 
        Document d4 = new Document();
        d4.add(Field.Keyword("id","person/wendy"));
        d4.add(Field.Text("macrinstfulltext","female Single"));
        writer.addDocument(d4);

        Document d5 = new Document();
        d5.add(Field.Keyword("id","person123"));
        d5.add(Field.Text("macrinstfulltext","female Single"));
        writer.addDocument(d5);
        
        writer.close();
 
        IndexReader reader = IndexReader.open("index");
        Searcher searcher = new IndexSearcher(reader);
 
        search(searcher, analyzer, "id:person/john");
// this query doesn't find anything
        search(searcher, analyzer, "id:person/wendy");
// this query doesn't find anything
        search(searcher, analyzer, "id:person123");
// this query works
        search(searcher, analyzer, "id:person/john id:person/wendy");   //
this query doesn't find anything
      }
 
      private static void search(Searcher searcher, Analyzer analyzer,
                                 String queryString) throws Exception {
        Query query = QueryParser.parse(queryString, "macrfulltext",
analyzer);
        Hits hits = searcher.search(query);
        System.out.println(query.toString("macrfulltext") + ": " +
hits.length() + " hits");
        for (int i = 0; i < hits.length(); i++) {
          System.out.println(" " + hits.doc(i).get("id"));
        }
      }
}
 
 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message