Search in sources :

Example 66 with SolrQueryRequest

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

the class QueryEqualityTest method testQuerySwitch.

public void testQuerySwitch() throws Exception {
    SolrQueryRequest req = req("myXXX", "XXX", "myField", "foo_s", "myQ", "{!prefix f=$myField}asdf");
    try {
        assertQueryEquals("switch", req, "{!switch case.foo=XXX case.bar=zzz case.yak=qqq}foo", "{!switch case.foo=qqq case.bar=XXX case.yak=zzz} bar ", "{!switch case.foo=qqq case.bar=XXX case.yak=zzz v='  bar '}", "{!switch default=XXX case.foo=qqq case.bar=zzz}asdf", "{!switch default=$myXXX case.foo=qqq case.bar=zzz}asdf", "{!switch case=XXX case.bar=zzz case.yak=qqq v=''}", "{!switch case.bar=zzz case=XXX case.yak=qqq v=''}", "{!switch case=XXX case.bar=zzz case.yak=qqq}", "{!switch case=XXX case.bar=zzz case.yak=qqq}   ", "{!switch case=$myXXX case.bar=zzz case.yak=qqq}   ");
        assertQueryEquals("switch", req, "{!switch case.foo=$myQ case.bar=zzz case.yak=qqq}foo", "{!query v=$myQ}");
    } finally {
        req.close();
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest)

Example 67 with SolrQueryRequest

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

the class QueryEqualityTest method testQueryFunc.

public void testQueryFunc() throws Exception {
    // more involved tests of specific functions in other methods
    SolrQueryRequest req = req("myVar", "5", "myField", "foo_i", "myInner", "product(4,foo_i)");
    try {
        assertQueryEquals("func", req, "{!func}sum(4,5)", "{!func}sum(4,$myVar)", "sum(4,5)");
        assertQueryEquals("func", req, "{!func}sum(1,2,3,4,5)", "{!func}sum(1,2,3,4,$myVar)", "sum(1,2,3,4,5)");
        assertQueryEquals("func", req, "{!func}sum(4,$myInner)", "{!func}sum(4,product(4,foo_i))", "{!func}sum(4,product(4,$myField))", "{!func}sum(4,product(4,field(foo_i)))");
    } finally {
        req.close();
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest)

Example 68 with SolrQueryRequest

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

the class CursorMarkTest method testInvalidUsage.

public void testInvalidUsage() {
    final SolrQueryRequest req = req();
    final IndexSchema schema = req.getSchema();
    try {
        final SortSpec ss = SortSpecParsing.parseSortSpec("str desc, score desc", req);
        final CursorMark totem = new CursorMark(schema, ss);
        fail("no failure from sort that doesn't include uniqueKey field");
    } catch (SolrException e) {
        assertEquals(ErrorCode.BAD_REQUEST.code, e.code());
        assertTrue(0 < e.getMessage().indexOf("uniqueKey"));
    }
    for (final String dir : Arrays.asList("asc", "desc")) {
        try {
            final SortSpec ss = SortSpecParsing.parseSortSpec("score " + dir, req);
            final CursorMark totem = new CursorMark(schema, ss);
            fail("no failure from score only sort: " + dir);
        } catch (SolrException e) {
            assertEquals(ErrorCode.BAD_REQUEST.code, e.code());
            assertTrue(0 < e.getMessage().indexOf("uniqueKey"));
        }
        try {
            final SortSpec ss = SortSpecParsing.parseSortSpec("_docid_ " + dir + ", id desc", req);
            final CursorMark totem = new CursorMark(schema, ss);
            fail("no failure from sort that includes _docid_: " + dir);
        } catch (SolrException e) {
            assertEquals(ErrorCode.BAD_REQUEST.code, e.code());
            assertTrue(0 < e.getMessage().indexOf("_docid_"));
        }
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) IndexSchema(org.apache.solr.schema.IndexSchema) SolrException(org.apache.solr.common.SolrException)

Example 69 with SolrQueryRequest

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

the class QueryParsingTest method testQParserEmptyInput.

/**
   * Test that the main QParserPlugins people are likely to use
   * as defaults fail with a consistent exception when the query string 
   * is either empty or null.
   * @see <a href="https://issues.apache.org/jira/browse/SOLR-435">SOLR-435</a>
   * @see <a href="https://issues.apache.org/jira/browse/SOLR-2001">SOLR-2001</a>
   */
public void testQParserEmptyInput() throws Exception {
    SolrQueryRequest req = req("df", "text");
    final String[] parsersTested = new String[] { OldLuceneQParserPlugin.NAME, LuceneQParserPlugin.NAME, DisMaxQParserPlugin.NAME, ExtendedDismaxQParserPlugin.NAME };
    for (String defType : parsersTested) {
        for (String qstr : new String[] { null, "" }) {
            QParser parser = null;
            try {
                parser = QParser.getParser(qstr, defType, req);
            } catch (Exception e) {
                throw new RuntimeException("getParser excep using defType=" + defType + " with qstr=" + qstr, e);
            }
            Query q = parser.parse();
            assertNull("expected no query", q);
        }
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) Query(org.apache.lucene.search.Query)

Example 70 with SolrQueryRequest

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

the class QueryParsingTest method testLiteralFunction.

public void testLiteralFunction() throws Exception {
    final String NAME = FunctionQParserPlugin.NAME;
    SolrQueryRequest req = req("variable", "foobar");
    assertNotNull(QParser.getParser("literal('a value')", NAME, req).getQuery());
    assertNotNull(QParser.getParser("literal('a value')", NAME, req).getQuery());
    assertNotNull(QParser.getParser("literal(\"a value\")", NAME, req).getQuery());
    assertNotNull(QParser.getParser("literal($variable)", NAME, req).getQuery());
    assertNotNull(QParser.getParser("strdist(\"a value\",literal('a value'),edit)", NAME, req).getQuery());
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest)

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