Search in sources :

Example 1 with SearchSolr

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

the class SolrEndToEndTest method getSearchRunner.

protected SearchSolr getSearchRunner(SearchSolr.Args args) throws Exception {
    SearchSolr runner = new SearchSolr(args);
    Field f = runner.getClass().getDeclaredField("client");
    f.setAccessible(true);
    // close the old client
    ((SolrClient) f.get(runner)).close();
    f.set(runner, client);
    return runner;
}
Also used : Field(java.lang.reflect.Field) SearchSolr(io.anserini.search.SearchSolr) SolrClient(org.apache.solr.client.solrj.SolrClient)

Example 2 with SearchSolr

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

the class SolrEndToEndTest method testIndexAndSearch.

@Test
public void testIndexAndSearch() throws Exception {
    String schemaAdjustmentFile = getSchemaAdjustmentFile();
    if (schemaAdjustmentFile != null) {
        // update schema, much like curl -X POST -H 'Content-type:application/json' --data-binary SCHEMA_NAME.json http://localhost:8983/solr/COLLECTION_NAME/schema
        String schemaJson = Files.readString(getFile(schemaAdjustmentFile).toPath());
        DirectJsonQueryRequest schemaRequest = new DirectJsonQueryRequest(schemaJson, params(CommonParams.QT, "/schema"));
        QueryResponse response = schemaRequest.process(client, getCollectionName());
        assertEquals(0, response.getStatus());
    }
    IndexArgs indexArgs = getIndexArgs();
    IndexCollection indexRunner = getIndexRunner(indexArgs);
    indexRunner.run();
    SearchSolr.Args searchArgs = getSearchArgs();
    SearchSolr searchRunner = getSearchRunner(searchArgs);
    searchRunner.runTopics();
    BufferedReader br = new BufferedReader(new FileReader(searchArgs.output));
    String[] ref = getRefRankingResult();
    String s;
    int cnt = 0;
    while ((s = br.readLine()) != null) {
        assertEquals(ref[cnt], s);
        cnt++;
    }
    assertEquals(cnt, ref.length);
    FileUtils.deleteQuietly(new File(searchArgs.output));
}
Also used : SearchSolr(io.anserini.search.SearchSolr) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) IndexArgs(io.anserini.index.IndexArgs) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) DirectJsonQueryRequest(org.apache.solr.client.solrj.request.json.DirectJsonQueryRequest) File(java.io.File) IndexCollection(io.anserini.index.IndexCollection) Test(org.junit.Test)

Aggregations

SearchSolr (io.anserini.search.SearchSolr)2 IndexArgs (io.anserini.index.IndexArgs)1 IndexCollection (io.anserini.index.IndexCollection)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 Field (java.lang.reflect.Field)1 SolrClient (org.apache.solr.client.solrj.SolrClient)1 DirectJsonQueryRequest (org.apache.solr.client.solrj.request.json.DirectJsonQueryRequest)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1 Test (org.junit.Test)1