Search in sources :

Example 1 with LocalSolrQueryRequest

use of org.apache.solr.request.LocalSolrQueryRequest in project Solbase by Photobucket.

the class SolbaseQuerySenderListener method newSearcher.

@Override
public void newSearcher(SolrIndexSearcher newSearcher, SolrIndexSearcher currentSearcher) {
    // don't warm up this core. only warm up shard cores
    if (!core.getName().equals("") && core.getName().indexOf("~") > 0) {
        final SolrIndexSearcher searcher = newSearcher;
        log.info("QuerySenderListener sending requests to " + core.getName());
        for (NamedList nlst : (List<NamedList>) args.get("queries")) {
            try {
                SolrQueryResponse rsp = new SolrQueryResponse();
                LocalSolrQueryRequest req = new LocalSolrQueryRequest(core, nlst) {

                    @Override
                    public SolrIndexSearcher getSearcher() {
                        return searcher;
                    }

                    @Override
                    public void close() {
                    }
                };
                req.getContext().put("solbase-index", core.getName());
                req.getContext().put("webapp", "/solbase");
                req.getContext().put("path", "/select");
                core.execute(core.getRequestHandler(req.getParams().get(core.getName())), req, rsp);
                req.close();
            } catch (Exception e) {
            // do nothing... we want to continue with the other
            // requests.
            // the failure should have already been logged.
            }
        }
        log.info("QuerySenderListener done.");
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.request.SolrQueryResponse) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) DocList(org.apache.solr.search.DocList) NamedList(org.apache.solr.common.util.NamedList) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher)

Example 2 with LocalSolrQueryRequest

use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.

the class TestApiFramework method invoke.

private SolrQueryResponse invoke(PluginBag<SolrRequestHandler> reqHandlers, String path, String fullPath, SolrRequest.METHOD method, CoreContainer mockCC) {
    HashMap<String, String> parts = new HashMap<>();
    boolean containerHandlerLookup = mockCC.getRequestHandlers() == reqHandlers;
    path = path == null ? fullPath : path;
    Api api = null;
    if (containerHandlerLookup) {
        api = V2HttpCall.getApiInfo(reqHandlers, path, "GET", fullPath, parts);
    } else {
        api = V2HttpCall.getApiInfo(mockCC.getRequestHandlers(), fullPath, "GET", fullPath, parts);
        if (api == null)
            api = new CompositeApi(null);
        if (api instanceof CompositeApi) {
            CompositeApi compositeApi = (CompositeApi) api;
            api = V2HttpCall.getApiInfo(reqHandlers, path, "GET", fullPath, parts);
            compositeApi.add(api);
            api = compositeApi;
        }
    }
    SolrQueryResponse rsp = new SolrQueryResponse();
    LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, new MapSolrParams(new HashMap<>())) {

        @Override
        public List<CommandOperation> getCommands(boolean validateInput) {
            return Collections.emptyList();
        }
    };
    api.call(req, rsp);
    return rsp;
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) CommandOperation(org.apache.solr.common.util.CommandOperation) CompositeApi(org.apache.solr.api.V2HttpCall.CompositeApi) CompositeApi(org.apache.solr.api.V2HttpCall.CompositeApi) Api(org.apache.solr.api.Api)

Example 3 with LocalSolrQueryRequest

use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.

the class SolrIndexSplitterTest method testSplitByRouteKey.

@Test
public void testSplitByRouteKey() throws Exception {
    File indexDir = createTempDir().toFile();
    CompositeIdRouter r1 = new CompositeIdRouter();
    String splitKey = "sea-line!";
    String key2 = "soul-raising!";
    // murmur2 has a collision on the above two keys
    assertEquals(r1.keyHashRange(splitKey), r1.keyHashRange(key2));
    for (int i = 0; i < 10; i++) {
        assertU(adoc("id", splitKey + i));
        assertU(adoc("id", key2 + i));
    }
    assertU(commit());
    assertJQ(req("q", "*:*"), "/response/numFound==20");
    DocRouter.Range splitKeyRange = r1.keyHashRange(splitKey);
    LocalSolrQueryRequest request = null;
    Directory directory = null;
    try {
        request = lrf.makeRequest("q", "dummy");
        SplitIndexCommand command = new SplitIndexCommand(request, Lists.newArrayList(indexDir.getAbsolutePath()), null, Lists.newArrayList(splitKeyRange), new CompositeIdRouter(), null, splitKey);
        new SolrIndexSplitter(command).split();
        directory = h.getCore().getDirectoryFactory().get(indexDir.getAbsolutePath(), DirectoryFactory.DirContext.DEFAULT, h.getCore().getSolrConfig().indexConfig.lockType);
        DirectoryReader reader = DirectoryReader.open(directory);
        assertEquals("split index has wrong number of documents", 10, reader.numDocs());
        reader.close();
        h.getCore().getDirectoryFactory().release(directory);
        directory = null;
    } finally {
        if (request != null) {
            request.close();
        }
        if (directory != null) {
            h.getCore().getDirectoryFactory().release(directory);
        }
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) CompositeIdRouter(org.apache.solr.common.cloud.CompositeIdRouter) DirectoryReader(org.apache.lucene.index.DirectoryReader) DocRouter(org.apache.solr.common.cloud.DocRouter) File(java.io.File) Directory(org.apache.lucene.store.Directory) Test(org.junit.Test)

Example 4 with LocalSolrQueryRequest

use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.

the class SolrIndexSplitterTest method testSplitDeletes.

// SOLR-5144
public void testSplitDeletes() throws Exception {
    LocalSolrQueryRequest request = null;
    try {
        // add two docs
        String id1 = "dorothy";
        assertU(adoc("id", id1));
        String id2 = "kansas";
        assertU(adoc("id", id2));
        assertU(commit());
        assertJQ(req("q", "*:*"), "/response/numFound==2");
        // delete id2
        assertU(delI(id2));
        assertU(commit());
        // find minHash/maxHash hash ranges
        List<DocRouter.Range> ranges = getRanges(id1, id2);
        request = lrf.makeRequest("q", "dummy");
        SplitIndexCommand command = new SplitIndexCommand(request, Lists.newArrayList(indexDir1.getAbsolutePath(), indexDir2.getAbsolutePath()), null, ranges, new PlainIdRouter(), null, null);
        new SolrIndexSplitter(command).split();
        Directory directory = h.getCore().getDirectoryFactory().get(indexDir1.getAbsolutePath(), DirectoryFactory.DirContext.DEFAULT, h.getCore().getSolrConfig().indexConfig.lockType);
        DirectoryReader reader = DirectoryReader.open(directory);
        assertEquals("id:dorothy should be present in split index1", 1, reader.docFreq(new Term("id", "dorothy")));
        assertEquals("id:kansas should not be present in split index1", 0, reader.docFreq(new Term("id", "kansas")));
        assertEquals("split index1 should have only one document", 1, reader.numDocs());
        reader.close();
        h.getCore().getDirectoryFactory().release(directory);
        directory = h.getCore().getDirectoryFactory().get(indexDir2.getAbsolutePath(), DirectoryFactory.DirContext.DEFAULT, h.getCore().getSolrConfig().indexConfig.lockType);
        reader = DirectoryReader.open(directory);
        // should be empty
        assertEquals(0, reader.numDocs());
        reader.close();
        h.getCore().getDirectoryFactory().release(directory);
    } finally {
        // decrefs the searcher
        if (request != null)
            request.close();
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) DirectoryReader(org.apache.lucene.index.DirectoryReader) PlainIdRouter(org.apache.solr.common.cloud.PlainIdRouter) Term(org.apache.lucene.index.Term) Directory(org.apache.lucene.store.Directory)

Example 5 with LocalSolrQueryRequest

use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.

the class SolrIndexSplitterTest method testSplitByCores.

@Test
public void testSplitByCores() throws Exception {
    // add two docs
    String id1 = "dorothy";
    assertU(adoc("id", id1));
    String id2 = "kansas";
    assertU(adoc("id", id2));
    assertU(commit());
    assertJQ(req("q", "*:*"), "/response/numFound==2");
    List<DocRouter.Range> ranges = getRanges(id1, id2);
    SolrCore core1 = null, core2 = null;
    try {
        core1 = h.getCoreContainer().create("split1", ImmutableMap.of("dataDir", indexDir1.getAbsolutePath(), "configSet", "minimal"));
        core2 = h.getCoreContainer().create("split2", ImmutableMap.of("dataDir", indexDir2.getAbsolutePath(), "configSet", "minimal"));
        LocalSolrQueryRequest request = null;
        try {
            request = lrf.makeRequest("q", "dummy");
            SplitIndexCommand command = new SplitIndexCommand(request, null, Lists.newArrayList(core1, core2), ranges, new PlainIdRouter(), null, null);
            new SolrIndexSplitter(command).split();
        } finally {
            if (request != null)
                request.close();
        }
        EmbeddedSolrServer server1 = new EmbeddedSolrServer(h.getCoreContainer(), "split1");
        EmbeddedSolrServer server2 = new EmbeddedSolrServer(h.getCoreContainer(), "split2");
        server1.commit(true, true);
        server2.commit(true, true);
        assertEquals("id:dorothy should be present in split index1", 1, server1.query(new SolrQuery("id:dorothy")).getResults().getNumFound());
        assertEquals("id:kansas should not be present in split index1", 0, server1.query(new SolrQuery("id:kansas")).getResults().getNumFound());
        assertEquals("id:dorothy should not be present in split index2", 0, server2.query(new SolrQuery("id:dorothy")).getResults().getNumFound());
        assertEquals("id:kansas should be present in split index2", 1, server2.query(new SolrQuery("id:kansas")).getResults().getNumFound());
    } finally {
        h.getCoreContainer().unload("split2");
        h.getCoreContainer().unload("split1");
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) PlainIdRouter(org.apache.solr.common.cloud.PlainIdRouter) EmbeddedSolrServer(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Aggregations

LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)107 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)61 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)49 SolrCore (org.apache.solr.core.SolrCore)47 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)41 Test (org.junit.Test)41 HashMap (java.util.HashMap)32 NamedList (org.apache.solr.common.util.NamedList)26 ArrayList (java.util.ArrayList)23 MapSolrParams (org.apache.solr.common.params.MapSolrParams)21 SolrException (org.apache.solr.common.SolrException)18 List (java.util.List)15 LinkedHashMap (java.util.LinkedHashMap)11 SolrParams (org.apache.solr.common.params.SolrParams)10 SearchComponent (org.apache.solr.handler.component.SearchComponent)10 SolrRequestHandler (org.apache.solr.request.SolrRequestHandler)10 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)10 Map (java.util.Map)9 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)9 IOException (java.io.IOException)8