lucene 多域搜索

http://blog.sina.com.cn/s/blog_60452f7d0100lv5g.html


lucene 多字段多域搜索

(2010-10-19 15:29:38)
标签:

杂谈

分类: 搜索引擎
诶 
  先来个浅显能用的,有两种方法:

1.使用 MultiFieldQueryParser:
BooleanClause.Occur[] clauses = {
                    BooleanClause.Occur.SHOULD,
                    BooleanClause.Occur.SHOULD
                };
        Query query = MultiFieldQueryParser.parse(Version.LUCENE_30, queries, fields, clauses, new StandardAnalyzer(Version.LUCENE_30));

2.使用 BooleanQuery 动态 add query 对象:
BooleanQuery booleanQuery = new BooleanQuery();
   
        QueryParser parser1 = new QueryParser(Version.LUCENE_30, "chapter_name", new StandardAnalyzer(Version.LUCENE_30));
        Query titleQuery = parser1.parse("家");
        booleanQuery.add(titleQuery, BooleanClause.Occur.SHOULD);
   
        QueryParser parser2 = new QueryParser(Version.LUCENE_30, "content", new StandardAnalyzer(Version.LUCENE_30));
        Query contentQuery = parser2.parse("家");
        booleanQuery.add(contentQuery, BooleanClause.Occur.SHOULD);

学习劲头蜗牛爬哇,不过有爬总比趴着好啊


原文地址:https://www.cnblogs.com/lexus/p/2145283.html