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();
}
}
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();
}
}
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_"));
}
}
}
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);
}
}
}
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());
}
Aggregations