Lucene BooleanQuery OR输出不是想要的

时间:2018-05-26 22:27:19

标签: java lucene booleanquery

我有一个包含一些文档的索引,包含计算机一词的593个文档和包含科学一词的51个文档以及包含单词的596个文档>计算机或科学,我想在这里输出那些596文档是我的代码:

public class Main
{
    public static void main(String args[]) throws IOException, ParseException{

        String[] champ ={"W", "A"};
       BooleanQuery q = new BooleanQuery();

              BooleanQuery qIntermediaire;
        qIntermediaire = new BooleanQuery();
        for(int i=0;i<champ.length;i++){
           qIntermediaire.add(new BooleanClause(new FuzzyQuery(new Term(champ[i], "computer"), 0), BooleanClause.Occur.SHOULD));
       }
       q.add(new BooleanClause(qIntermediaire, BooleanClause.Occur.MUST));
       qIntermediaire = new BooleanQuery();
       for(int i=0;i<champ.length;i++){
           qIntermediaire.add(new BooleanClause(new FuzzyQuery(new Term(champ[i], "science"), 0), BooleanClause.Occur.SHOULD));
       }
       q.add(new BooleanClause(qIntermediaire, BooleanClause.Occur.SHOULD));


         Path indexPath = Paths.get("MonIndex");
        Directory directory = FSDirectory.open(indexPath);
        DirectoryReader reader = DirectoryReader.open(directory);
        IndexSearcher iSearcher = new IndexSearcher(reader);

        TopDocs topdocs = iSearcher.search(q, 10000);
        ScoreDoc[] resultsList = topdocs.scoreDocs;

             System.out.println(resultsList.length);


    }

}

由于某些原因,这给了我461份文件:(

0 个答案:

没有答案