Java apachelucene中的多属性查询
下面的程序满足查询,其中title同时包含lucene和action。如果我想搜索一个元组,其中isbn考虑isbn不是唯一的是1234,标题包含Lucene和dummies。lucene是否为此提供了设施Java apachelucene中的多属性查询,java,apache,lucene,Java,Apache,Lucene,下面的程序满足查询,其中title同时包含lucene和action。如果我想搜索一个元组,其中isbn考虑isbn不是唯一的是1234,标题包含Lucene和dummies。lucene是否为此提供了设施 StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_40); Directory index = new RAMDirectory(); IndexWriterConfig config = new Index
StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_40);
Directory index = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_40, analyzer);
IndexWriter w = new IndexWriter(index, config);
addDoc(w, "Lucene in Action", "193398817");
addDoc(w, "Lucene for Dummies", "55320055Z");
addDoc(w, "Managing Gigabytes", "55063554A");
addDoc(w, "The Art of Computer Science", "9900333X");
w.close();
private static void addDoc(IndexWriter w, String title, String isbn) throws IOException {
Document doc = new Document();
doc.add(new TextField("title", title, Field.Store.YES));
doc.add(new StringField("isbn", isbn, Field.Store.YES));
w.addDocument(doc);
}
String querystr = args.length > 0 ? args[0] : "lucene AND action";
Query q = new QueryParser(Version.LUCENE_40, "title", analyzer).parse(querystr);
在我看来,QueryParser类只用于查询标题字段,因此,为了使查询同时以title和isbn字段为目标,您必须使用multifiedqueryparser类和title:lucene和dummies以及isbn:1234等查询,或者只构建BooleanQuery,这就是您手工从多个TermQuery对象得到的结果 我希望这有帮助