0

我有一些文档的索引,包含单词计算机的 593 个文档和包含单词science的 51 个文档和包含单词computer OR science的 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 份文件 :(

4

0 回答 0