lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ian Lea <ian....@blackwell.co.uk>
Subject Re: partial search
Date Tue, 06 Nov 2001 21:51:49 GMT
> How could I make a search with something like "tes*" for test, testing, ...?
> 
> Currently, I use a StandardAnalyzer for indexing and searching (with query
> parser), and it doesn't work.
> Do I need to use another analyser ?

I don't think so.  The short program below works for me with lucene-1.2-rc2.


--
Ian.
ian.lea@blackwell.co.uk


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 Test { 

    public static void main(String args[]) throws Exception { 
	Analyzer analyzer = new StandardAnalyzer(); 
	IndexWriter writer = new IndexWriter("test", analyzer, true); 
	Document d;
	d = new Document();
	d.add(Field.Text("word", "test"));
	writer.addDocument(d);
	d = new Document();
	d.add(Field.Text("word", "testing"));
	writer.addDocument(d);
	writer.close();
	IndexReader reader = IndexReader.open("test");
	Searcher searcher = new IndexSearcher(reader);
	String s = "test*";
	if (args.length > 0) { s = args[0]; }
	Query query = QueryParser.parse(s, "word", analyzer);
	Hits hits = searcher.search(query);
	for (int i = 0; i < hits.length(); i++) {
	    System.out.println(hits.doc(i).get("word"));
	}
    }
}

--
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