use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class TestRealTimeGet method testStressGetRealtime.
/***
@Test
public void testGetRealtime() throws Exception {
SolrQueryRequest sr1 = req("q","foo");
IndexReader r1 = sr1.getCore().getRealtimeReader();
assertU(adoc("id","1"));
IndexReader r2 = sr1.getCore().getRealtimeReader();
assertNotSame(r1, r2);
int refcount = r2.getRefCount();
// make sure a new reader wasn't opened
IndexReader r3 = sr1.getCore().getRealtimeReader();
assertSame(r2, r3);
assertEquals(refcount+1, r3.getRefCount());
assertU(commit());
// this is not critical, but currently a commit does not refresh the reader
// if nothing has changed
IndexReader r4 = sr1.getCore().getRealtimeReader();
assertEquals(refcount+2, r4.getRefCount());
r1.decRef();
r2.decRef();
r3.decRef();
r4.decRef();
sr1.close();
}
***/
@Test
public void testStressGetRealtime() throws Exception {
clearIndex();
assertU(commit());
// req().getCore().getUpdateHandler().getIndexWriterProvider().getIndexWriter(req().getCore()).setInfoStream(System.out);
final int commitPercent = 5 + random().nextInt(20);
// what percent of the commits are soft
final int softCommitPercent = 30 + random().nextInt(75);
final int deletePercent = 4 + random().nextInt(25);
final int deleteByQueryPercent = 1 + random().nextInt(5);
// percent change that an update uses optimistic locking
final int optimisticPercent = 1 + random().nextInt(50);
// percent change that a version specified will be correct
final int optimisticCorrectPercent = 25 + random().nextInt(70);
// percent of time that a get will be filtered... we normally don't want too high.
final int filteredGetPercent = random().nextInt(random().nextInt(20) + 1);
final int ndocs = 5 + (random().nextBoolean() ? random().nextInt(25) : random().nextInt(200));
int nWriteThreads = 5 + random().nextInt(25);
// number of committers at a time...
final int maxConcurrentCommits = nWriteThreads;
// query variables
final int percentRealtimeQuery = 60;
// number of query operations to perform in total
final AtomicLong operations = new AtomicLong(50000);
int nReadThreads = 5 + random().nextInt(25);
verbose("commitPercent=", commitPercent);
verbose("softCommitPercent=", softCommitPercent);
verbose("deletePercent=", deletePercent);
verbose("deleteByQueryPercent=", deleteByQueryPercent);
verbose("ndocs=", ndocs);
verbose("nWriteThreads=", nWriteThreads);
verbose("nReadThreads=", nReadThreads);
verbose("percentRealtimeQuery=", percentRealtimeQuery);
verbose("maxConcurrentCommits=", maxConcurrentCommits);
verbose("operations=", operations);
initModel(ndocs);
final AtomicInteger numCommitting = new AtomicInteger();
List<Thread> threads = new ArrayList<>();
for (int i = 0; i < nWriteThreads; i++) {
Thread thread = new Thread("WRITER" + i) {
Random rand = new Random(random().nextInt());
@Override
public void run() {
try {
while (operations.get() > 0) {
int oper = rand.nextInt(100);
if (oper < commitPercent) {
if (numCommitting.incrementAndGet() <= maxConcurrentCommits) {
Map<Integer, DocInfo> newCommittedModel;
long version;
synchronized (TestRealTimeGet.this) {
// take a snapshot
newCommittedModel = new HashMap<>(model);
version = snapshotCount++;
verbose("took snapshot version=", version);
}
if (rand.nextInt(100) < softCommitPercent) {
verbose("softCommit start");
assertU(TestHarness.commit("softCommit", "true"));
verbose("softCommit end");
} else {
verbose("hardCommit start");
assertU(commit());
verbose("hardCommit end");
}
synchronized (TestRealTimeGet.this) {
// install this model snapshot only if it's newer than the current one
if (version >= committedModelClock) {
if (VERBOSE) {
verbose("installing new committedModel version=" + committedModelClock);
}
committedModel = newCommittedModel;
committedModelClock = version;
}
}
}
numCommitting.decrementAndGet();
continue;
}
int id = rand.nextInt(ndocs);
Object sync = syncArr[id];
// set the lastId before we actually change it sometimes to try and
// uncover more race conditions between writing and reading
boolean before = rand.nextBoolean();
if (before) {
lastId = id;
}
// Even with versions, we can't remove the sync because increasing versions does not mean increasing vals.
synchronized (sync) {
DocInfo info = model.get(id);
long val = info.val;
long nextVal = Math.abs(val) + 1;
if (oper < commitPercent + deletePercent) {
boolean opt = rand.nextInt() < optimisticPercent;
boolean correct = opt ? rand.nextInt() < optimisticCorrectPercent : false;
long badVersion = correct ? 0 : badVersion(rand, info.version);
if (VERBOSE) {
if (!opt) {
verbose("deleting id", id, "val=", nextVal);
} else {
verbose("deleting id", id, "val=", nextVal, "existing_version=", info.version, (correct ? "" : (" bad_version=" + badVersion)));
}
}
// assertU("<delete><id>" + id + "</id></delete>");
Long version = null;
if (opt) {
if (correct) {
version = deleteAndGetVersion(Integer.toString(id), params("_version_", Long.toString(info.version)));
} else {
try {
version = deleteAndGetVersion(Integer.toString(id), params("_version_", Long.toString(badVersion)));
fail();
} catch (SolrException se) {
assertEquals(409, se.code());
}
}
} else {
version = deleteAndGetVersion(Integer.toString(id), null);
}
if (version != null) {
model.put(id, new DocInfo(version, -nextVal));
}
if (VERBOSE) {
verbose("deleting id", id, "val=", nextVal, "DONE");
}
} else if (oper < commitPercent + deletePercent + deleteByQueryPercent) {
if (VERBOSE) {
verbose("deleteByQuery id ", id, "val=", nextVal);
}
assertU("<delete><query>id:" + id + "</query></delete>");
model.put(id, new DocInfo(-1L, -nextVal));
if (VERBOSE) {
verbose("deleteByQuery id", id, "val=", nextVal, "DONE");
}
} else {
boolean opt = rand.nextInt() < optimisticPercent;
boolean correct = opt ? rand.nextInt() < optimisticCorrectPercent : false;
long badVersion = correct ? 0 : badVersion(rand, info.version);
if (VERBOSE) {
if (!opt) {
verbose("adding id", id, "val=", nextVal);
} else {
verbose("adding id", id, "val=", nextVal, "existing_version=", info.version, (correct ? "" : (" bad_version=" + badVersion)));
}
}
Long version = null;
SolrInputDocument sd = sdoc("id", Integer.toString(id), FIELD, Long.toString(nextVal));
if (opt) {
if (correct) {
version = addAndGetVersion(sd, params("_version_", Long.toString(info.version)));
} else {
try {
version = addAndGetVersion(sd, params("_version_", Long.toString(badVersion)));
fail();
} catch (SolrException se) {
assertEquals(409, se.code());
}
}
} else {
version = addAndGetVersion(sd, null);
}
if (version != null) {
model.put(id, new DocInfo(version, nextVal));
}
if (VERBOSE) {
verbose("adding id", id, "val=", nextVal, "DONE");
}
}
}
if (!before) {
lastId = id;
}
}
} catch (Throwable e) {
operations.set(-1L);
throw new RuntimeException(e);
}
}
};
threads.add(thread);
}
for (int i = 0; i < nReadThreads; i++) {
Thread thread = new Thread("READER" + i) {
Random rand = new Random(random().nextInt());
@Override
public void run() {
try {
while (operations.decrementAndGet() >= 0) {
// bias toward a recently changed doc
int id = rand.nextInt(100) < 25 ? lastId : rand.nextInt(ndocs);
// when indexing, we update the index, then the model
// so when querying, we should first check the model, and then the index
boolean realTime = rand.nextInt(100) < percentRealtimeQuery;
DocInfo info;
if (realTime) {
info = model.get(id);
} else {
synchronized (TestRealTimeGet.this) {
info = committedModel.get(id);
}
}
if (VERBOSE) {
verbose("querying id", id);
}
boolean filteredOut = false;
SolrQueryRequest sreq;
if (realTime) {
ModifiableSolrParams p = params("wt", "json", "qt", "/get", "ids", Integer.toString(id));
if (rand.nextInt(100) < filteredGetPercent) {
int idToFilter = rand.nextBoolean() ? id : rand.nextInt(ndocs);
filteredOut = idToFilter != id;
p.add("fq", "id:" + idToFilter);
}
sreq = req(p);
} else {
sreq = req("wt", "json", "q", "id:" + Integer.toString(id), "omitHeader", "true");
}
String response = h.query(sreq);
Map rsp = (Map) ObjectBuilder.fromJSON(response);
List doclist = (List) (((Map) rsp.get("response")).get("docs"));
if (doclist.size() == 0) {
// there's no info we can get back with a delete, so not much we can check without further synchronization
// This is also correct when filteredOut==true
} else {
assertEquals(1, doclist.size());
long foundVal = (Long) (((Map) doclist.get(0)).get(FIELD));
long foundVer = (Long) (((Map) doclist.get(0)).get("_version_"));
if (filteredOut || foundVal < Math.abs(info.val) || (foundVer == info.version && foundVal != info.val)) {
// if the version matches, the val must
verbose("ERROR, id=", id, "found=", response, "model", info);
assertTrue(false);
}
}
}
} catch (Throwable e) {
operations.set(-1L);
throw new RuntimeException(e);
}
}
};
threads.add(thread);
}
for (Thread thread : threads) {
thread.start();
}
for (Thread thread : threads) {
thread.join();
}
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class TestRecovery method testBuffering.
@Test
public void testBuffering() throws Exception {
DirectUpdateHandler2.commitOnClose = false;
final Semaphore logReplay = new Semaphore(0);
final Semaphore logReplayFinish = new Semaphore(0);
UpdateLog.testing_logReplayHook = () -> {
try {
assertTrue(logReplay.tryAcquire(timeout, TimeUnit.SECONDS));
} catch (Exception e) {
throw new RuntimeException(e);
}
};
UpdateLog.testing_logReplayFinishHook = logReplayFinish::release;
SolrQueryRequest req = req();
UpdateHandler uhandler = req.getCore().getUpdateHandler();
UpdateLog ulog = uhandler.getUpdateLog();
try {
clearIndex();
assertU(commit());
Map<String, Metric> metrics = getMetrics();
assertEquals(UpdateLog.State.ACTIVE, ulog.getState());
ulog.bufferUpdates();
assertEquals(UpdateLog.State.BUFFERING, ulog.getState());
Future<UpdateLog.RecoveryInfo> rinfoFuture = ulog.applyBufferedUpdates();
assertTrue(rinfoFuture == null);
assertEquals(UpdateLog.State.ACTIVE, ulog.getState());
ulog.bufferUpdates();
assertEquals(UpdateLog.State.BUFFERING, ulog.getState());
Gauge<Integer> state = (Gauge<Integer>) metrics.get("TLOG.state");
assertEquals(UpdateLog.State.BUFFERING.ordinal(), state.getValue().intValue());
Gauge<Integer> bufferedOps = (Gauge<Integer>) metrics.get("TLOG.buffered.ops");
int initialOps = bufferedOps.getValue();
Meter applyingBuffered = (Meter) metrics.get("TLOG.applyingBuffered.ops");
long initialApplyingOps = applyingBuffered.getCount();
String v3 = getNextVersion();
String v940_del = "-" + getNextVersion();
String v950_del = "-" + getNextVersion();
String v1010 = getNextVersion();
String v1015 = getNextVersion();
String v1017_del = "-" + getNextVersion();
String v1020 = getNextVersion();
String v1030 = getNextVersion();
String v1040 = getNextVersion();
String v1050 = getNextVersion();
String v1060 = getNextVersion();
String v1070 = getNextVersion();
String v1080 = getNextVersion();
String v2010_del = "-" + getNextVersion();
String v2060_del = "-" + getNextVersion();
String v3000_del = "-" + getNextVersion();
String versionListFirstCheck = String.join(",", v2010_del, v1030, v1020, v1017_del, v1015, v1010);
String versionListSecondCheck = String.join(",", v3000_del, v1080, v1050, v1060, v940_del, v1040, v3, v2010_del, v1030, v1020, v1017_del, v1015, v1010);
// simulate updates from a leader
updateJ(jsonAdd(sdoc("id", "B1", "_version_", v1010)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
updateJ(jsonAdd(sdoc("id", "B11", "_version_", v1015)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
updateJ(jsonDelQ("id:B1 id:B11 id:B2 id:B3"), params(DISTRIB_UPDATE_PARAM, FROM_LEADER, "_version_", v1017_del));
updateJ(jsonAdd(sdoc("id", "B2", "_version_", v1020)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
updateJ(jsonAdd(sdoc("id", "B3", "_version_", v1030)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
deleteAndGetVersion("B1", params(DISTRIB_UPDATE_PARAM, FROM_LEADER, "_version_", v2010_del));
assertJQ(req("qt", "/get", "getVersions", "6"), "=={'versions':[" + versionListFirstCheck + "]}");
assertU(commit());
assertJQ(req("qt", "/get", "getVersions", "6"), "=={'versions':[" + versionListFirstCheck + "]}");
// updates should be buffered, so we should not see any results yet.
assertJQ(req("q", "*:*"), "/response/numFound==0");
// real-time get should also not show anything (this could change in the future,
// but it's currently used for validating version numbers too, so it would
// be bad for updates to be visible if we're just buffering.
assertJQ(req("qt", "/get", "id", "B3"), "=={'doc':null}");
assertEquals(6, bufferedOps.getValue().intValue() - initialOps);
rinfoFuture = ulog.applyBufferedUpdates();
assertTrue(rinfoFuture != null);
assertEquals(UpdateLog.State.APPLYING_BUFFERED, ulog.getState());
logReplay.release(1000);
UpdateLog.RecoveryInfo rinfo = rinfoFuture.get();
assertEquals(UpdateLog.State.ACTIVE, ulog.getState());
assertEquals(6L, applyingBuffered.getCount() - initialApplyingOps);
assertJQ(req("qt", "/get", "getVersions", "6"), "=={'versions':[" + versionListFirstCheck + "]}");
assertJQ(req("q", "*:*"), "/response/numFound==2");
// move back to recovering
ulog.bufferUpdates();
assertEquals(UpdateLog.State.BUFFERING, ulog.getState());
Long ver = getVer(req("qt", "/get", "id", "B3"));
assertEquals(Long.valueOf(v1030), ver);
// add a reordered doc that shouldn't overwrite one in the index
updateJ(jsonAdd(sdoc("id", "B3", "_version_", v3)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
// reorder two buffered updates
updateJ(jsonAdd(sdoc("id", "B4", "_version_", v1040)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
// this update should not take affect
deleteAndGetVersion("B4", params(DISTRIB_UPDATE_PARAM, FROM_LEADER, "_version_", v940_del));
updateJ(jsonAdd(sdoc("id", "B6", "_version_", v1060)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
updateJ(jsonAdd(sdoc("id", "B5", "_version_", v1050)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
updateJ(jsonAdd(sdoc("id", "B8", "_version_", v1080)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
// test that delete by query is at least buffered along with everything else so it will delete the
// currently buffered id:8 (even if it doesn't currently support versioning)
updateJ("{\"delete\": { \"query\":\"id:B2 OR id:B8\" }}", params(DISTRIB_UPDATE_PARAM, FROM_LEADER, "_version_", v3000_del));
assertJQ(req("qt", "/get", "getVersions", "13"), // the "3" appears because versions aren't checked while buffering
"=={'versions':[" + versionListSecondCheck + "]}");
logReplay.drainPermits();
rinfoFuture = ulog.applyBufferedUpdates();
assertTrue(rinfoFuture != null);
assertEquals(UpdateLog.State.APPLYING_BUFFERED, ulog.getState());
// apply a single update
logReplay.release(1);
// now add another update
updateJ(jsonAdd(sdoc("id", "B7", "_version_", v1070)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
// a reordered update that should be dropped
deleteAndGetVersion("B5", params(DISTRIB_UPDATE_PARAM, FROM_LEADER, "_version_", v950_del));
deleteAndGetVersion("B6", params(DISTRIB_UPDATE_PARAM, FROM_LEADER, "_version_", v2060_del));
logReplay.release(1000);
UpdateLog.RecoveryInfo recInfo = rinfoFuture.get();
assertJQ(req("q", "*:*", "sort", "id asc", "fl", "id,_version_"), "/response/docs==[" + "{'id':'B3','_version_':" + v1030 + "}" + ",{'id':'B4','_version_':" + v1040 + "}" + ",{'id':'B5','_version_':" + v1050 + "}" + ",{'id':'B7','_version_':" + v1070 + "}" + "]");
assertEquals(1, recInfo.deleteByQuery);
// leave each test method in a good state
assertEquals(UpdateLog.State.ACTIVE, ulog.getState());
assertEquals(0, bufferedOps.getValue().intValue());
} finally {
DirectUpdateHandler2.commitOnClose = true;
UpdateLog.testing_logReplayHook = null;
UpdateLog.testing_logReplayFinishHook = null;
req().close();
}
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class TestRecovery method testBufferedMultipleCalls.
@Test
public void testBufferedMultipleCalls() throws Exception {
DirectUpdateHandler2.commitOnClose = false;
final Semaphore logReplay = new Semaphore(0);
final Semaphore logReplayFinish = new Semaphore(0);
UpdateLog.testing_logReplayHook = () -> {
try {
assertTrue(logReplay.tryAcquire(timeout, TimeUnit.SECONDS));
} catch (Exception e) {
throw new RuntimeException(e);
}
};
UpdateLog.testing_logReplayFinishHook = () -> logReplayFinish.release();
SolrQueryRequest req = req();
UpdateHandler uhandler = req.getCore().getUpdateHandler();
UpdateLog ulog = uhandler.getUpdateLog();
Future<UpdateLog.RecoveryInfo> rinfoFuture;
try {
String v101 = getNextVersion();
String v102 = getNextVersion();
String v103 = getNextVersion();
String v104 = getNextVersion();
String v105 = getNextVersion();
String v200 = getNextVersion();
String v201 = getNextVersion();
String v203 = getNextVersion();
String v204 = getNextVersion();
String v205 = getNextVersion();
String v206 = getNextVersion();
clearIndex();
assertU(commit());
assertEquals(UpdateLog.State.ACTIVE, ulog.getState());
ulog.bufferUpdates();
assertEquals(UpdateLog.State.BUFFERING, ulog.getState());
// simulate updates from a leader
updateJ(jsonAdd(sdoc("id", "c1", "_version_", v101)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
updateJ(jsonAdd(sdoc("id", "c2", "_version_", v102)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
updateJ(jsonAdd(sdoc("id", "c3", "_version_", v103)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
// call bufferUpdates again (this currently happens when recovery fails)... we should get a new starting point
ulog.bufferUpdates();
assertEquals(UpdateLog.State.BUFFERING, ulog.getState());
updateJ(jsonAdd(sdoc("id", "c4", "_version_", v104)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
updateJ(jsonAdd(sdoc("id", "c5", "_version_", v105)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
logReplay.release(1000);
rinfoFuture = ulog.applyBufferedUpdates();
UpdateLog.RecoveryInfo rinfo = rinfoFuture.get();
assertEquals(2, rinfo.adds);
assertJQ(req("qt", "/get", "getVersions", "2"), "=={'versions':[" + v105 + "," + v104 + "]}");
// this time add some docs first before buffering starts (so tlog won't be at pos 0)
updateJ(jsonAdd(sdoc("id", "c100", "_version_", v200)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
updateJ(jsonAdd(sdoc("id", "c101", "_version_", v201)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
ulog.bufferUpdates();
updateJ(jsonAdd(sdoc("id", "c103", "_version_", v203)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
updateJ(jsonAdd(sdoc("id", "c104", "_version_", v204)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
// call bufferUpdates again (this currently happens when recovery fails)... we should get a new starting point
ulog.bufferUpdates();
updateJ(jsonAdd(sdoc("id", "c105", "_version_", v205)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
updateJ(jsonAdd(sdoc("id", "c106", "_version_", v206)), params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
rinfoFuture = ulog.applyBufferedUpdates();
rinfo = rinfoFuture.get();
assertEquals(2, rinfo.adds);
assertJQ(req("q", "*:*", "sort", "_version_ asc", "fl", "id,_version_"), "/response/docs==[" + "{'id':'c4','_version_':" + v104 + "}" + ",{'id':'c5','_version_':" + v105 + "}" + ",{'id':'c100','_version_':" + v200 + "}" + ",{'id':'c101','_version_':" + v201 + "}" + ",{'id':'c105','_version_':" + v205 + "}" + ",{'id':'c106','_version_':" + v206 + "}" + "" + "]");
// The updates that were buffered (but never applied) still appear in recent versions!
// This is good for some uses, but may not be good for others.
assertJQ(req("qt", "/get", "getVersions", "11"), "=={'versions':[" + String.join(",", v206, v205, v204, v203, v201, v200, v105, v104, v103, v102, v101) + "]}");
// leave each test method in a good state
assertEquals(UpdateLog.State.ACTIVE, ulog.getState());
} finally {
DirectUpdateHandler2.commitOnClose = true;
UpdateLog.testing_logReplayHook = null;
UpdateLog.testing_logReplayFinishHook = null;
req().close();
}
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class TestFiltering method testRandomFiltering.
@Test
public void testRandomFiltering() throws Exception {
int indexIter = 5 * RANDOM_MULTIPLIER;
int queryIter = 250 * RANDOM_MULTIPLIER;
Model model = new Model();
for (int iiter = 0; iiter < indexIter; iiter++) {
model.indexSize = random().nextInt(40 * RANDOM_MULTIPLIER) + 1;
clearIndex();
for (int i = 0; i < model.indexSize; i++) {
String val = Integer.toString(i);
SolrInputDocument doc = sdoc("id", val, f, val, f_s, f_s(i));
updateJ(jsonAdd(doc), null);
if (random().nextInt(100) < 20) {
// duplicate doc 20% of the time (makes deletions)
updateJ(jsonAdd(doc), null);
}
if (random().nextInt(100) < 10) {
// commit 10% of the time (forces a new segment)
assertU(commit());
}
}
assertU(commit());
// sanity check
assertJQ(req("q", "*:*"), "/response/numFound==" + model.indexSize);
int totalMatches = 0;
int nonZeros = 0;
for (int qiter = 0; qiter < queryIter; qiter++) {
model.clear();
List<String> params = new ArrayList<>();
params.add("q");
params.add(makeRandomQuery(model, true, false));
int nFilters = random().nextInt(5);
for (int i = 0; i < nFilters; i++) {
params.add("fq");
params.add(makeRandomQuery(model, false, false));
}
boolean facet = random().nextBoolean();
if (facet) {
// basic facet.query tests getDocListAndSet
params.add("facet");
params.add("true");
params.add("facet.query");
params.add("*:*");
params.add("facet.query");
params.add("{!key=multiSelect ex=t}*:*");
String facetQuery = makeRandomQuery(model, false, true);
if (facetQuery.startsWith("{!")) {
facetQuery = "{!key=facetQuery " + facetQuery.substring(2);
} else {
facetQuery = "{!key=facetQuery}" + facetQuery;
}
params.add("facet.query");
params.add(facetQuery);
}
if (random().nextInt(100) < 10) {
params.add("group");
params.add("true");
params.add("group.main");
params.add("true");
params.add("group.field");
params.add("id");
if (random().nextBoolean()) {
params.add("group.cache.percent");
params.add("100");
}
}
SolrQueryRequest sreq = req(params.toArray(new String[params.size()]));
long expected = model.answer.cardinality();
long expectedMultiSelect = model.multiSelect.cardinality();
long expectedFacetQuery = model.facetQuery.cardinality();
totalMatches += expected;
if (expected > 0) {
nonZeros++;
}
if (iiter == -1 && qiter == -1) {
// set breakpoint here to debug a specific issue
System.out.println("request=" + params);
}
try {
assertJQ(sreq, "/response/numFound==" + expected, facet ? "/facet_counts/facet_queries/*:*/==" + expected : null, facet ? "/facet_counts/facet_queries/multiSelect/==" + expectedMultiSelect : null, facet ? "/facet_counts/facet_queries/facetQuery/==" + expectedFacetQuery : null);
} catch (Exception e) {
// show the indexIter and queryIter for easier debugging
SolrException.log(log, e);
String s = "FAILURE: indexSize=" + model.indexSize + " iiter=" + iiter + " qiter=" + qiter + " request=" + params;
log.error(s);
fail(s);
}
}
// After making substantial changes to this test, make sure that we still get a
// decent number of queries that match some documents
// System.out.println("totalMatches=" + totalMatches + " nonZeroQueries="+nonZeros);
}
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class TestExtendedDismaxParser method testSowFalseWithBoost.
public void testSowFalseWithBoost() throws Exception {
try (SolrQueryRequest req = req("sow", "false", "qf", "subject title")) {
QParser qParser = QParser.getParser("one two", "edismax", req);
Query q = qParser.getQuery();
assertEquals("+((title:one | subject:on) (title:two | subject:two))", q.toString());
}
try (SolrQueryRequest req = req("sow", "false", "qf", "subject title^5")) {
QParser qParser = QParser.getParser("one two", "edismax", req);
Query q = qParser.getQuery();
assertEquals("+(((title:one)^5.0 | subject:on) ((title:two)^5.0 | subject:two))", q.toString());
}
try (SolrQueryRequest req = req("sow", "false", "qf", "subject^3 title")) {
QParser qParser = QParser.getParser("one two", "edismax", req);
Query q = qParser.getQuery();
assertEquals("+((title:one | (subject:on)^3.0) (title:two | (subject:two)^3.0))", q.toString());
}
try (SolrQueryRequest req = req("sow", "false", "qf", "subject^10 title^20")) {
QParser qParser = QParser.getParser("one two", "edismax", req);
Query q = qParser.getQuery();
assertEquals("+(((title:one)^20.0 | (subject:on)^10.0) ((title:two)^20.0 | (subject:two)^10.0))", q.toString());
}
}
Aggregations