模糊搜索

zhjt_88 2008-07-07
如题,比如我索引的文字有两个document 1:爱的敬意 2:爱的致意 如果我想输入 爱的敬意 两条Document都能搜到,应该怎么做呢
fys124974704 2008-07-07
	public static void main(String[] args) throws CorruptIndexException, LockObtainFailedException, IOException {
		RAMDirectory ram = new RAMDirectory();
		IndexWriter writer = new IndexWriter(ram,new SimpleAnalyzer(),true);
		Document doc1 = new Document();
		doc1.add(new Field("content","爱的敬意",Field.Store.YES,Field.Index.TOKENIZED));
		Document doc2 = new Document();
		doc2.add(new Field("content","爱的致意",Field.Store.YES,Field.Index.TOKENIZED));
		writer.addDocument(doc1);
		writer.addDocument(doc2);
		writer.flush();
		writer.close();
		IndexSearcher searcher = new IndexSearcher(ram);
		Term term = new Term("content","爱的敬意");
		FuzzyQuery fuzzy = null;
		fuzzy = new FuzzyQuery(term);
		Hits hits =	searcher.search(fuzzy);
		System.out.println(hits.length());
	}
fys124974704 2008-07-07
在做搜索的过程中要注意分词的方式
Global site tag (gtag.js) - Google Analytics