Search in sources :

Example 91 with SolrQueryRequest

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

the class TestNestedDocsSort method testCachehits.

public void testCachehits() {
    final SolrQueryRequest req = req();
    try {
        final SolrCache cache = req.getSearcher().getCache("perSegFilter");
        assertNotNull(cache);
        final Map<String, Object> state = cache.getMetricsSnapshot();
        String lookupsKey = null;
        for (String key : state.keySet()) {
            if (key.endsWith(".lookups")) {
                lookupsKey = key;
                break;
            }
        }
        Number before = (Number) state.get(lookupsKey);
        parse("childfield(name_s1,$q) asc");
        Number after = (Number) cache.getMetricsSnapshot().get(lookupsKey);
        assertEquals("parsing bjq lookups parent filter," + "parsing sort spec lookups parent and child filters, " + "hopefully for the purpose", 3, after.intValue() - before.intValue());
    } finally {
        req.close();
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrCache(org.apache.solr.search.SolrCache)

Example 92 with SolrQueryRequest

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

the class TestNestedDocsSort method parse.

private SortField parse(String a) {
    final SolrQueryRequest req = req("q", "{!parent which=type_s1:parent}whatever_s1:foo", "q2", "{!parent which=type_s1:parent}nomater_s1:what", "notbjq", "foo_s1:bar");
    try {
        final SortSpec spec = SortSpecParsing.parseSortSpec(a, req);
        assertNull(spec.getSchemaFields().get(0));
        final Sort sort = spec.getSort();
        final SortField field = sort.getSort()[0];
        assertNotNull(field);
        return field;
    } finally {
        req.close();
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) Sort(org.apache.lucene.search.Sort) SortField(org.apache.lucene.search.SortField) SortSpec(org.apache.solr.search.SortSpec)

Example 93 with SolrQueryRequest

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

the class TestScoreJoinQPNoScore method testNotEquals.

public void testNotEquals() throws SyntaxError, IOException {
    try (SolrQueryRequest req = req("*:*")) {
        Query x = QParser.getParser("{!join from=dept_id_s to=dept_ss score=none}text_t:develop", req).getQuery();
        Query y = QParser.getParser("{!join from=dept_ss to=dept_ss score=none}text_t:develop", req).getQuery();
        assertFalse("diff from fields produce equal queries", x.equals(y));
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) Query(org.apache.lucene.search.Query)

Example 94 with SolrQueryRequest

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

the class TestScoreJoinQPNoScore method testJoinQueryType.

public void testJoinQueryType() throws SyntaxError, IOException {
    SolrQueryRequest req = null;
    try {
        final String score = whateverScore();
        req = req("{!join from=dept_id_s to=dept_ss" + score + "}text_t:develop");
        SolrQueryResponse rsp = new SolrQueryResponse();
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
        {
            final Query query = QParser.getParser(req.getParams().get("q"), req).getQuery();
            final Query rewrittenQuery = query.rewrite(req.getSearcher().getIndexReader());
            assertEquals(rewrittenQuery + " is expected to be from Solr", ScoreJoinQParserPlugin.class.getPackage().getName(), rewrittenQuery.getClass().getPackage().getName());
        }
        {
            final Query query = QParser.getParser("{!join from=dept_id_s to=dept_ss}text_t:develop", req).getQuery();
            final Query rewrittenQuery = query.rewrite(req.getSearcher().getIndexReader());
            assertEquals(rewrittenQuery + " is expected to be from Solr", JoinQParserPlugin.class.getPackage().getName(), rewrittenQuery.getClass().getPackage().getName());
        }
    } finally {
        if (req != null) {
            req.close();
        }
        SolrRequestInfo.clearRequestInfo();
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) Query(org.apache.lucene.search.Query) JoinQParserPlugin(org.apache.solr.search.JoinQParserPlugin) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo)

Example 95 with SolrQueryRequest

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

the class TestHdfsUpdateLog method testFSThreadSafety.

@Test
public void testFSThreadSafety() throws Exception {
    final SolrQueryRequest req = req();
    final UpdateHandler uhandler = req.getCore().getUpdateHandler();
    ((DirectUpdateHandler2) uhandler).getCommitTracker().setTimeUpperBound(100);
    ((DirectUpdateHandler2) uhandler).getCommitTracker().setOpenSearcher(false);
    final UpdateLog ulog = uhandler.getUpdateLog();
    clearIndex();
    assertU(commit());
    // we hammer on init in a background thread to make
    // sure we don't run into any filesystem already closed
    // problems (SOLR-7113)
    Thread thread = new Thread() {

        public void run() {
            int cnt = 0;
            while (true) {
                ulog.init(uhandler, req.getCore());
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
                if (cnt++ > 50) {
                    break;
                }
            }
        }
    };
    Thread thread2 = new Thread() {

        public void run() {
            int cnt = 0;
            while (true) {
                assertU(adoc("id", Integer.toString(cnt)));
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                }
                if (cnt++ > 500) {
                    break;
                }
            }
        }
    };
    thread.start();
    thread2.start();
    thread.join();
    thread2.join();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) Test(org.junit.Test)

Aggregations

SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)362 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)148 Test (org.junit.Test)143 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)129 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)106 SolrCore (org.apache.solr.core.SolrCore)58 ArrayList (java.util.ArrayList)49 NamedList (org.apache.solr.common.util.NamedList)48 SolrInputDocument (org.apache.solr.common.SolrInputDocument)45 HashMap (java.util.HashMap)43 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)37 SolrParams (org.apache.solr.common.params.SolrParams)36 SolrException (org.apache.solr.common.SolrException)34 IOException (java.io.IOException)24 Query (org.apache.lucene.search.Query)24 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)24 List (java.util.List)23 MapSolrParams (org.apache.solr.common.params.MapSolrParams)23 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)23 Map (java.util.Map)22