我正在使用Lucene 4.3在我的项目中编写全文搜索功能 当我添加数据时,一切正常,但是当查询时,只有当查询中至少有一个单词与索引中某个字段的值中至少有一个单词匹配时才会获得点击。
例如,如果我添加
private static StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_43);
public static void addCustomerDoc(Map<String, String[]> parameters, String path, long customerId) throws IOException {
File file = new File(path + "/index/");
FSDirectory indexDir = FSDirectory.open(file);
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_43, analyzer);
IndexWriter writer = new IndexWriter(indexDir, config);
Document doc = new Document();
doc.add(new TextField("email", parameters.get("email")[0].toString(), Field.Store.YES));
doc.add(new TextField("username", parameters.get("username")[0].toString(), Field.Store.YES));
doc.add(new TextField("phone", parameters.get("phone")[0].toString(), Field.Store.YES));
doc.add(new StringField("customerId", "" + customerId, Field.Store.YES));
addDoc(writer, doc);
writer.close();
}
private static void addDoc(IndexWriter writer, Document doc) throws IOException {
writer.addDocument(doc);
writer.commit();
}
添加像
这样的用户如果我搜索foo,fooba或foobarx,即使我输入f或超过foobar这个词,我也不会得到结果吗?