Search in sources :

Example 1 with SearchArgs

use of io.anserini.search.SearchArgs in project Anserini by castorini.

the class EndToEndTest method createDefaultSearchArgs.

protected SearchArgs createDefaultSearchArgs() {
    SearchArgs searchArgs = new SearchArgs();
    // required
    searchArgs.index = this.indexPath;
    searchArgs.output = this.searchOutputPrefix + this.topicReader;
    searchArgs.topicReader = this.topicReader;
    searchArgs.topics = new String[] { this.topicFile };
    searchArgs.bm25 = true;
    // optional
    searchArgs.topicfield = "title";
    searchArgs.searchtweets = false;
    searchArgs.hits = 1000;
    searchArgs.keepstop = false;
    return searchArgs;
}
Also used : SearchArgs(io.anserini.search.SearchArgs)

Example 2 with SearchArgs

use of io.anserini.search.SearchArgs in project Anserini by castorini.

the class EndToEndTest method testSearching.

@Test
public void testSearching() {
    // Subclasses will override this method and provide the ground truth.
    setSearchGroundTruth();
    try {
        for (Map.Entry<String, SearchArgs> entry : testQueries.entrySet()) {
            SearchCollection searcher = new SearchCollection(entry.getValue());
            searcher.runTopics();
            Map<String, List<String>> actualQuery = searcher.getQueries();
            searcher.close();
            // check query tokens
            if (!queryTokens.isEmpty()) {
                assertEquals(queryTokens, actualQuery);
            }
            checkRankingResults(entry.getKey(), entry.getValue().output);
            // Remember to cleanup run files.
            cleanup.add(new File(entry.getValue().output));
        }
    } catch (Exception e) {
        System.out.println("Test Searching failed: ");
        e.printStackTrace();
        fail();
    }
}
Also used : SearchArgs(io.anserini.search.SearchArgs) SearchCollection(io.anserini.search.SearchCollection) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) NotStoredException(io.anserini.index.NotStoredException) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with SearchArgs

use of io.anserini.search.SearchArgs in project Anserini by castorini.

the class JsonVectorEndToEndTest method setSearchGroundTruth.

@Override
protected void setSearchGroundTruth() {
    topicReader = "TsvInt";
    topicFile = "src/test/resources/sample_topics/json_vector_topics.tsv";
    SearchArgs searchArg = createDefaultSearchArgs().impact();
    searchArg.pretokenized = true;
    testQueries.put("impact", searchArg);
    queryTokens.put("1", new ArrayList<>());
    queryTokens.get("1").add("f35");
    queryTokens.put("2", new ArrayList<>());
    queryTokens.get("2").add("f3");
    queryTokens.put("3", new ArrayList<>());
    queryTokens.get("3").add("f4");
    referenceRunOutput.put("impact", new String[] { "1 Q0 doc2 1 8.000000 Anserini", "2 Q0 doc1 1 1.000000 Anserini", "3 Q0 doc1 1 4.000000 Anserini", "3 Q0 doc2 2 3.000000 Anserini" });
}
Also used : SearchArgs(io.anserini.search.SearchArgs)

Example 4 with SearchArgs

use of io.anserini.search.SearchArgs in project Anserini by castorini.

the class PretokenizedIndexEndToEndTest method setSearchGroundTruth.

@Override
protected void setSearchGroundTruth() {
    topicReader = "TsvInt";
    topicFile = "src/test/resources/sample_topics/json_topics.tsv";
    SearchArgs searchArg = createDefaultSearchArgs().bm25();
    searchArg.pretokenized = true;
    testQueries.put("bm25", searchArg);
    queryTokens.put("1", new ArrayList<>());
    queryTokens.get("1").add("##ing");
    queryTokens.get("1").add("##vert");
    referenceRunOutput.put("bm25", new String[] { "1 Q0 2000001 1 0.922400 Anserini" });
}
Also used : SearchArgs(io.anserini.search.SearchArgs)

Example 5 with SearchArgs

use of io.anserini.search.SearchArgs in project Anserini by castorini.

the class TrecEndToEndPassageTest method setSearchGroundTruth.

@Override
protected void setSearchGroundTruth() {
    topicReader = "Trec";
    topicFile = "src/test/resources/sample_topics/Trec";
    SearchArgs args;
    args = createDefaultSearchArgs().bm25();
    args.selectMaxPassage = true;
    testQueries.put("bm25v1", args);
    referenceRunOutput.put("bm25v1", new String[] { "1 Q0 TREC_DOC_1 1 0.343200 Anserini", "1 Q0 WSJ_1 2 0.068700 Anserini" });
    args = createDefaultSearchArgs().bm25();
    args.selectMaxPassage = true;
    args.selectMaxPassage_hits = 1;
    testQueries.put("bm25v2", args);
    referenceRunOutput.put("bm25v2", new String[] { "1 Q0 TREC_DOC_1 1 0.343200 Anserini" });
    args = createDefaultSearchArgs().qld();
    args.selectMaxPassage = true;
    testQueries.put("qld", args);
    referenceRunOutput.put("qld", new String[] { "1 Q0 TREC_DOC_1 1 0.002500 Anserini", "1 Q0 WSJ_1 2 0.000000 Anserini" });
    args = createDefaultSearchArgs().qljm();
    args.selectMaxPassage = true;
    testQueries.put("qljm", args);
    referenceRunOutput.put("qljm", new String[] { "1 Q0 TREC_DOC_1 1 4.872300 Anserini", "1 Q0 WSJ_1 2 1.658200 Anserini" });
    args = createDefaultSearchArgs().inl2();
    args.selectMaxPassage = true;
    testQueries.put("inl2", args);
    referenceRunOutput.put("inl2", new String[] { "1 Q0 TREC_DOC_1 1 0.133200 Anserini", "1 Q0 WSJ_1 2 0.021100 Anserini" });
    args = createDefaultSearchArgs().spl();
    args.selectMaxPassage = true;
    testQueries.put("spl", args);
    referenceRunOutput.put("spl", new String[] { "1 Q0 TREC_DOC_1 1 0.446100 Anserini", "1 Q0 WSJ_1 2 0.115900 Anserini" });
    args = createDefaultSearchArgs().f2exp();
    args.selectMaxPassage = true;
    testQueries.put("f2exp", args);
    referenceRunOutput.put("f2exp", new String[] { "1 Q0 TREC_DOC_1 1 1.434700 Anserini", "1 Q0 WSJ_1 2 0.536200 Anserini" });
    args = createDefaultSearchArgs().f2log();
    args.selectMaxPassage = true;
    testQueries.put("f2log", args);
    referenceRunOutput.put("f2log", new String[] { "1 Q0 TREC_DOC_1 1 0.548500 Anserini", "1 Q0 WSJ_1 2 0.139500 Anserini" });
}
Also used : SearchArgs(io.anserini.search.SearchArgs)

Aggregations

SearchArgs (io.anserini.search.SearchArgs)10 IndexReader (org.apache.lucene.index.IndexReader)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)2 Directory (org.apache.lucene.store.Directory)2 FSDirectory (org.apache.lucene.store.FSDirectory)2 NotStoredException (io.anserini.index.NotStoredException)1 RerankerContext (io.anserini.rerank.RerankerContext)1 SearchCollection (io.anserini.search.SearchCollection)1 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MultiTerms (org.apache.lucene.index.MultiTerms)1 Term (org.apache.lucene.index.Term)1 Terms (org.apache.lucene.index.Terms)1 TermsEnum (org.apache.lucene.index.TermsEnum)1