use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class TestExtendedDismaxParser method testAutoGeneratePhraseQueries.
public void testAutoGeneratePhraseQueries() throws Exception {
ModifiableSolrParams noSowParams = new ModifiableSolrParams();
noSowParams.add("df", "text");
ModifiableSolrParams sowFalseParams = new ModifiableSolrParams();
sowFalseParams.add("sow", "false");
sowFalseParams.add("df", "text");
ModifiableSolrParams sowTrueParams = new ModifiableSolrParams();
sowTrueParams.add("sow", "true");
sowTrueParams.add("df", "text");
for (SolrParams params : Arrays.asList(noSowParams, sowFalseParams)) {
try (SolrQueryRequest req = req(params)) {
// "text" has autoGeneratePhraseQueries="true"
QParser qParser = QParser.getParser("text:grackle", "edismax", req);
Query q = qParser.getQuery();
assertEquals("+(text:\"crow blackbird\" text:grackl)", q.toString());
}
}
try (SolrQueryRequest req = req(sowTrueParams)) {
QParser qParser = QParser.getParser("text:grackle", "edismax", req);
Query q = qParser.getQuery();
assertEquals("+spanOr([spanNear([text:crow, text:blackbird], 0, true), text:grackl])", q.toString());
}
for (SolrParams params : Arrays.asList(noSowParams, sowTrueParams, sowFalseParams)) {
try (SolrQueryRequest req = req(params)) {
// "text_sw" doesn't specify autoGeneratePhraseQueries => default false
QParser qParser = QParser.getParser("text_sw:grackle", "edismax", req);
Query q = qParser.getQuery();
assertEquals("+((+text_sw:crow +text_sw:blackbird) text_sw:grackl)", q.toString());
}
}
Stream.of(noSowParams, sowTrueParams, sowFalseParams).forEach(p -> p.add("qf", "text text_sw"));
for (SolrParams params : Arrays.asList(noSowParams, sowFalseParams)) {
try (SolrQueryRequest req = req(params)) {
QParser qParser = QParser.getParser("grackle", "edismax", req);
Query q = qParser.getQuery();
assertEquals("+((text:\"crow blackbird\" text:grackl)" + " | ((+text_sw:crow +text_sw:blackbird) text_sw:grackl))", q.toString());
qParser = QParser.getParser("grackle wi fi", "edismax", req);
q = qParser.getQuery();
assertEquals("+(((text:\"crow blackbird\" text:grackl) text:wifi)" + " | (((+text_sw:crow +text_sw:blackbird) text_sw:grackl) text_sw:wifi))", q.toString());
}
}
try (SolrQueryRequest req = req(sowTrueParams)) {
QParser qParser = QParser.getParser("grackle", "edismax", req);
Query q = qParser.getQuery();
assertEquals("+(spanOr([spanNear([text:crow, text:blackbird], 0, true), text:grackl])" + " | ((+text_sw:crow +text_sw:blackbird) text_sw:grackl))", q.toString());
qParser = QParser.getParser("grackle wi fi", "edismax", req);
q = qParser.getQuery();
assertEquals("+((spanOr([spanNear([text:crow, text:blackbird], 0, true), text:grackl])" + " | ((+text_sw:crow +text_sw:blackbird) text_sw:grackl)) (text:wi | text_sw:wi) (text:fi | text_sw:fi))", q.toString());
}
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class TestFiltering method testLiveDocsSharing.
@Test
public void testLiveDocsSharing() throws Exception {
clearIndex();
for (int i = 0; i < 20; i++) {
for (int repeat = 0; repeat < (i % 5 == 0 ? 2 : 1); repeat++) {
assertU(adoc("id", Integer.toString(i), "foo_s", "foo", "val_i", Integer.toString(i), "val_s", Character.toString((char) ('A' + i))));
}
}
assertU(commit());
String[] queries = { "foo_s:foo", "foo_s:f*", "*:*", "id:[* TO *]", "id:[0 TO 99]", "val_i:[0 TO 20]", "val_s:[A TO z]" };
SolrQueryRequest req = req();
try {
SolrIndexSearcher searcher = req.getSearcher();
DocSet live = null;
for (String qstr : queries) {
Query q = QParser.getParser(qstr, null, req).getQuery();
// System.out.println("getting set for " + q);
DocSet set = searcher.getDocSet(q);
if (live == null) {
live = searcher.getLiveDocs();
}
assertTrue(set == live);
QueryCommand cmd = new QueryCommand();
cmd.setQuery(QParser.getParser(qstr, null, req).getQuery());
cmd.setLen(random().nextInt(30));
cmd.setNeedDocSet(true);
QueryResult res = new QueryResult();
searcher.search(res, cmd);
set = res.getDocSet();
assertTrue(set == live);
cmd.setQuery(QParser.getParser(qstr + " OR id:0", null, req).getQuery());
cmd.setFilterList(QParser.getParser(qstr + " OR id:1", null, req).getQuery());
res = new QueryResult();
searcher.search(res, cmd);
set = res.getDocSet();
assertTrue(set == live);
}
} finally {
req.close();
}
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class TestRealTimeGet method testGetRealtime.
@Test
public void testGetRealtime() throws Exception {
clearIndex();
assertU(commit());
assertU(adoc("id", "1", "a_f", "-1.5", "a_fd", "-1.5", "a_fdS", "-1.5", "a_fs", "1.0", "a_fs", "2.5", "a_fds", "1.0", "a_fds", "2.5", "a_fdsS", "1.0", "a_fdsS", "2.5", "a_d", "-1.2E99", "a_dd", "-1.2E99", "a_ddS", "-1.2E99", "a_ds", "1.0", "a_ds", "2.5", "a_dds", "1.0", "a_dds", "2.5", "a_ddsS", "1.0", "a_ddsS", "2.5", "a_i", "-1", "a_id", "-1", "a_idS", "-1", "a_is", "1", "a_is", "2", "a_ids", "1", "a_ids", "2", "a_idsS", "1", "a_idsS", "2", "a_l", "-9999999999", "a_ld", "-9999999999", "a_ldS", "-9999999999", "a_ls", "1", "a_ls", "9999999999", "a_lds", "1", "a_lds", "9999999999", "a_ldsS", "1", "a_ldsS", "9999999999"));
assertJQ(req("q", "id:1"), "/response/numFound==0");
assertJQ(req("qt", "/get", "id", "1", "fl", "id, a_f,a_fd,a_fdS a_fs,a_fds,a_fdsS, a_d,a_dd,a_ddS, a_ds,a_dds,a_ddsS, a_i,a_id,a_idS a_is,a_ids,a_idsS, a_l,a_ld,a_ldS a_ls,a_lds,a_ldsS"), "=={'doc':{'id':'1'" + ", a_f:-1.5, a_fd:-1.5, a_fdS:-1.5, a_fs:[1.0,2.5], a_fds:[1.0,2.5],a_fdsS:[1.0,2.5]" + ", a_d:-1.2E99, a_dd:-1.2E99, a_ddS:-1.2E99, a_ds:[1.0,2.5],a_dds:[1.0,2.5],a_ddsS:[1.0,2.5]" + ", a_i:-1, a_id:-1, a_idS:-1, a_is:[1,2],a_ids:[1,2],a_idsS:[1,2]" + ", a_l:-9999999999, a_ld:-9999999999, a_ldS:-9999999999, a_ls:[1,9999999999],a_lds:[1,9999999999],a_ldsS:[1,9999999999]" + " }}");
assertJQ(req("qt", "/get", "ids", "1", "fl", "id"), "=={" + " 'response':{'numFound':1,'start':0,'docs':[" + " {" + " 'id':'1'}]" + " }}}");
assertU(commit());
assertJQ(req("q", "id:1"), "/response/numFound==1");
// a cut-n-paste of the first big query, but this time it will be retrieved from the index rather than the transaction log
assertJQ(req("qt", "/get", "id", "1", "fl", "id, a_f,a_fd,a_fdS a_fs,a_fds,a_fdsS, a_d,a_dd,a_ddS, a_ds,a_dds,a_ddsS, a_i,a_id,a_idS a_is,a_ids,a_idsS, a_l,a_ld,a_ldS a_ls,a_lds,a_ldsS"), "=={'doc':{'id':'1'" + ", a_f:-1.5, a_fd:-1.5, a_fdS:-1.5, a_fs:[1.0,2.5], a_fds:[1.0,2.5],a_fdsS:[1.0,2.5]" + ", a_d:-1.2E99, a_dd:-1.2E99, a_ddS:-1.2E99, a_ds:[1.0,2.5],a_dds:[1.0,2.5],a_ddsS:[1.0,2.5]" + ", a_i:-1, a_id:-1, a_idS:-1, a_is:[1,2],a_ids:[1,2],a_idsS:[1,2]" + ", a_l:-9999999999, a_ld:-9999999999, a_ldS:-9999999999, a_ls:[1,9999999999],a_lds:[1,9999999999],a_ldsS:[1,9999999999]" + " }}");
assertJQ(req("qt", "/get", "id", "1", "fl", "id"), "=={'doc':{'id':'1'}}");
assertJQ(req("qt", "/get", "ids", "1", "fl", "id"), "=={" + " 'response':{'numFound':1,'start':0,'docs':[" + " {" + " 'id':'1'}]" + " }}}");
assertU(delI("1"));
assertJQ(req("q", "id:1"), "/response/numFound==1");
assertJQ(req("qt", "/get", "id", "1"), "=={'doc':null}");
assertJQ(req("qt", "/get", "ids", "1"), "=={'response':{'numFound':0,'start':0,'docs':[]}}");
assertU(adoc("id", "10"));
assertU(adoc("id", "11"));
assertJQ(req("qt", "/get", "id", "10", "fl", "id"), "=={'doc':{'id':'10'}}");
assertU(delQ("id:10 foo_s:abcdef"));
assertJQ(req("qt", "/get", "id", "10"), "=={'doc':null}");
assertJQ(req("qt", "/get", "id", "11", "fl", "id"), "=={'doc':{'id':'11'}}");
// multivalued field
assertU(adoc("id", "12", "val_ls", "1", "val_ls", "2"));
assertJQ(req("q", "id:12"), "/response/numFound==0");
assertJQ(req("qt", "/get", "id", "12", "fl", "id,val_ls"), "=={'doc':{'id':'12', 'val_ls':[1,2]}}");
assertU(commit());
assertJQ(req("qt", "/get", "id", "12", "fl", "id,val_ls"), "=={'doc':{'id':'12', 'val_ls':[1,2]}}");
assertJQ(req("q", "id:12"), "/response/numFound==1");
SolrQueryRequest req = req();
RefCounted<SolrIndexSearcher> realtimeHolder = req.getCore().getRealtimeSearcher();
//
// filters
//
assertU(adoc("id", "12"));
assertU(adoc("id", "13"));
// this should not need to open another realtime searcher
assertJQ(req("qt", "/get", "id", "11", "fl", "id", "fq", "id:11"), "=={doc:{id:'11'}}");
// assert that the same realtime searcher is still in effect (i.e. that we didn't
// open a new searcher when we didn't have to).
RefCounted<SolrIndexSearcher> realtimeHolder2 = req.getCore().getRealtimeSearcher();
// Autocommit could possibly cause this to fail?
assertEquals(realtimeHolder.get(), realtimeHolder2.get());
realtimeHolder2.decref();
// filter most likely different segment
assertJQ(req("qt", "/get", "id", "12", "fl", "id", "fq", "id:11"), "=={doc:null}");
// filter most likely same different segment
assertJQ(req("qt", "/get", "id", "12", "fl", "id", "fq", "id:13"), "=={doc:null}");
assertJQ(req("qt", "/get", "id", "12", "fl", "id", "fq", "id:12"), "=={doc:{id:'12'}}");
assertU(adoc("id", "14"));
assertU(adoc("id", "15"));
// id list, with some in index and some not, first id from index. Also test mutiple fq params.
assertJQ(req("qt", "/get", "ids", "12,14,13,15", "fl", "id", "fq", "id:[10 TO 14]", "fq", "id:[13 TO 19]"), "/response/docs==[{id:'14'},{id:'13'}]");
assertU(adoc("id", "16"));
assertU(adoc("id", "17"));
// id list, with some in index and some not, first id from tlog
assertJQ(req("qt", "/get", "ids", "17,16,15,14", "fl", "id", "fq", "id:[15 TO 16]"), "/response/docs==[{id:'16'},{id:'15'}]");
// more complex filter
assertJQ(req("qt", "/get", "ids", "17,16,15,14", "fl", "id", "fq", "{!frange l=15 u=16}id"), "/response/docs==[{id:'16'},{id:'15'}]");
realtimeHolder.decref();
req.close();
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class DirectUpdateHandlerTest method testAddRollback.
@Test
public void testAddRollback() throws Exception {
// re-init the core
deleteCore();
initCore("solrconfig.xml", "schema12.xml");
assertU(adoc("id", "A"));
// commit "A"
SolrCore core = h.getCore();
UpdateHandler updater = core.getUpdateHandler();
assertTrue(updater instanceof DirectUpdateHandler2);
DirectUpdateHandler2 duh2 = (DirectUpdateHandler2) updater;
SolrQueryRequest ureq = req();
CommitUpdateCommand cmtCmd = new CommitUpdateCommand(ureq, false);
cmtCmd.waitSearcher = true;
assertEquals(1, duh2.addCommands.longValue());
assertEquals(1, duh2.addCommandsCumulative.getCount());
assertEquals(0, duh2.commitCommands.getCount());
updater.commit(cmtCmd);
assertEquals(0, duh2.addCommands.longValue());
assertEquals(1, duh2.addCommandsCumulative.getCount());
assertEquals(1, duh2.commitCommands.getCount());
ureq.close();
assertU(adoc("id", "B"));
// rollback "B"
ureq = req();
RollbackUpdateCommand rbkCmd = new RollbackUpdateCommand(ureq);
assertEquals(1, duh2.addCommands.longValue());
assertEquals(2, duh2.addCommandsCumulative.getCount());
assertEquals(0, duh2.rollbackCommands.getCount());
updater.rollback(rbkCmd);
assertEquals(0, duh2.addCommands.longValue());
assertEquals(1, duh2.addCommandsCumulative.getCount());
assertEquals(1, duh2.rollbackCommands.getCount());
ureq.close();
// search - "B" should not be found.
Map<String, String> args = new HashMap<>();
args.put(CommonParams.Q, "id:A OR id:B");
args.put("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("\"B\" should not be found.", req, "//*[@numFound='1']", "//result/doc[1]/str[@name='id'][.='A']");
// Add a doc after the rollback to make sure we can continue to add/delete documents
// after a rollback as normal
assertU(adoc("id", "ZZZ"));
assertU(commit());
assertQ("\"ZZZ\" must be found.", req("q", "id:ZZZ"), "//*[@numFound='1']", "//result/doc[1]/str[@name='id'][.='ZZZ']");
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class JsonLoaderTest method testSimpleFormat.
public void testSimpleFormat() throws Exception {
String str = "[{'id':'1'},{'id':'2'}]".replace('\'', '"');
SolrQueryRequest req = req("commitWithin", "100", "overwrite", "false");
SolrQueryResponse rsp = new SolrQueryResponse();
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
JsonLoader loader = new JsonLoader();
loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
assertEquals(2, p.addCommands.size());
AddUpdateCommand add = p.addCommands.get(0);
SolrInputDocument d = add.solrDoc;
SolrInputField f = d.getField("id");
assertEquals("1", f.getValue());
assertEquals(add.commitWithin, 100);
assertEquals(add.overwrite, false);
add = p.addCommands.get(1);
d = add.solrDoc;
f = d.getField("id");
assertEquals("2", f.getValue());
assertEquals(add.commitWithin, 100);
assertEquals(add.overwrite, false);
req.close();
}
Aggregations