use of org.apache.solr.search.SolrIndexSearcher in project lucene-solr by apache.
the class TestSimpleTextCodec method test.
public void test() throws Exception {
SolrConfig config = h.getCore().getSolrConfig();
String codecFactory = config.get("codecFactory/@class");
assertEquals("Unexpected solrconfig codec factory", "solr.SimpleTextCodecFactory", codecFactory);
assertEquals("Unexpected core codec", "SimpleText", h.getCore().getCodec().getName());
RefCounted<IndexWriter> writerRef = h.getCore().getSolrCoreState().getIndexWriter(h.getCore());
try {
IndexWriter writer = writerRef.get();
assertEquals("Unexpected codec in IndexWriter config", "SimpleText", writer.getConfig().getCodec().getName());
} finally {
writerRef.decref();
}
assertU(add(doc("id", "1", "text", "textual content goes here")));
assertU(commit());
RefCounted<SolrIndexSearcher> searcherRef = h.getCore().getSearcher();
try {
SolrIndexSearcher searcher = searcherRef.get();
SegmentInfos infos = SegmentInfos.readLatestCommit(searcher.getIndexReader().directory());
SegmentInfo info = infos.info(infos.size() - 1).info;
assertEquals("Unexpected segment codec", "SimpleText", info.getCodec().getName());
} finally {
searcherRef.decref();
}
assertQ(req("q", "id:1"), "*[count(//doc)=1]");
}
use of org.apache.solr.search.SolrIndexSearcher in project lucene-solr by apache.
the class TestFaceting method testMultiThreadedFacets.
@Test
public void testMultiThreadedFacets() throws Exception {
add50ocs();
String[] methodParam = random().nextBoolean() ? new String[] {} : new String[] { "facet.method", "uif" };
assertQ("check no threading, threads == 0", req(methodParam, "q", "id:*", "indent", "true", "fl", "id", "rows", "1", "facet", "true", "facet.field", "f0_ws", "facet.field", "f1_ws", "facet.field", "f2_ws", "facet.field", "f3_ws", "facet.field", "f4_ws", "facet.field", "f5_ws", "facet.field", "f6_ws", "facet.field", "f7_ws", "facet.field", "f8_ws", "facet.field", "f9_ws", "facet.threads", "0", "facet.limit", "-1"), "*[count(//lst[@name='facet_fields']/lst)=10]", "*[count(//lst[@name='facet_fields']/lst/int)=20]", "//lst[@name='f0_ws']/int[@name='zero_1'][.='25']", "//lst[@name='f0_ws']/int[@name='zero_2'][.='25']", "//lst[@name='f1_ws']/int[@name='one_1'][.='33']", "//lst[@name='f1_ws']/int[@name='one_3'][.='17']", "//lst[@name='f2_ws']/int[@name='two_1'][.='37']", "//lst[@name='f2_ws']/int[@name='two_4'][.='13']", "//lst[@name='f3_ws']/int[@name='three_1'][.='40']", "//lst[@name='f3_ws']/int[@name='three_5'][.='10']", "//lst[@name='f4_ws']/int[@name='four_1'][.='41']", "//lst[@name='f4_ws']/int[@name='four_6'][.='9']", "//lst[@name='f5_ws']/int[@name='five_1'][.='42']", "//lst[@name='f5_ws']/int[@name='five_7'][.='8']", "//lst[@name='f6_ws']/int[@name='six_1'][.='43']", "//lst[@name='f6_ws']/int[@name='six_8'][.='7']", "//lst[@name='f7_ws']/int[@name='seven_1'][.='44']", "//lst[@name='f7_ws']/int[@name='seven_9'][.='6']", "//lst[@name='f8_ws']/int[@name='eight_1'][.='45']", "//lst[@name='f8_ws']/int[@name='eight_10'][.='5']", "//lst[@name='f9_ws']/int[@name='nine_1'][.='45']", "//lst[@name='f9_ws']/int[@name='nine_11'][.='5']");
RefCounted<SolrIndexSearcher> currentSearcherRef = h.getCore().getSearcher();
try {
SolrIndexSearcher currentSearcher = currentSearcherRef.get();
SortedSetDocValues ui0 = DocValues.getSortedSet(currentSearcher.getSlowAtomicReader(), "f0_ws");
SortedSetDocValues ui1 = DocValues.getSortedSet(currentSearcher.getSlowAtomicReader(), "f1_ws");
SortedSetDocValues ui2 = DocValues.getSortedSet(currentSearcher.getSlowAtomicReader(), "f2_ws");
SortedSetDocValues ui3 = DocValues.getSortedSet(currentSearcher.getSlowAtomicReader(), "f3_ws");
SortedSetDocValues ui4 = DocValues.getSortedSet(currentSearcher.getSlowAtomicReader(), "f4_ws");
SortedSetDocValues ui5 = DocValues.getSortedSet(currentSearcher.getSlowAtomicReader(), "f5_ws");
SortedSetDocValues ui6 = DocValues.getSortedSet(currentSearcher.getSlowAtomicReader(), "f6_ws");
SortedSetDocValues ui7 = DocValues.getSortedSet(currentSearcher.getSlowAtomicReader(), "f7_ws");
SortedSetDocValues ui8 = DocValues.getSortedSet(currentSearcher.getSlowAtomicReader(), "f8_ws");
SortedSetDocValues ui9 = DocValues.getSortedSet(currentSearcher.getSlowAtomicReader(), "f9_ws");
assertQ("check threading, more threads than fields", req(methodParam, "q", "id:*", "indent", "true", "fl", "id", "rows", "1", "facet", "true", "facet.field", "f0_ws", "facet.field", "f1_ws", "facet.field", "f2_ws", "facet.field", "f3_ws", "facet.field", "f4_ws", "facet.field", "f5_ws", "facet.field", "f6_ws", "facet.field", "f7_ws", "facet.field", "f8_ws", "facet.field", "f9_ws", "facet.threads", "1000", "facet.limit", "-1"), "*[count(//lst[@name='facet_fields']/lst)=10]", "*[count(//lst[@name='facet_fields']/lst/int)=20]", "//lst[@name='f0_ws']/int[@name='zero_1'][.='25']", "//lst[@name='f0_ws']/int[@name='zero_2'][.='25']", "//lst[@name='f1_ws']/int[@name='one_1'][.='33']", "//lst[@name='f1_ws']/int[@name='one_3'][.='17']", "//lst[@name='f2_ws']/int[@name='two_1'][.='37']", "//lst[@name='f2_ws']/int[@name='two_4'][.='13']", "//lst[@name='f3_ws']/int[@name='three_1'][.='40']", "//lst[@name='f3_ws']/int[@name='three_5'][.='10']", "//lst[@name='f4_ws']/int[@name='four_1'][.='41']", "//lst[@name='f4_ws']/int[@name='four_6'][.='9']", "//lst[@name='f5_ws']/int[@name='five_1'][.='42']", "//lst[@name='f5_ws']/int[@name='five_7'][.='8']", "//lst[@name='f6_ws']/int[@name='six_1'][.='43']", "//lst[@name='f6_ws']/int[@name='six_8'][.='7']", "//lst[@name='f7_ws']/int[@name='seven_1'][.='44']", "//lst[@name='f7_ws']/int[@name='seven_9'][.='6']", "//lst[@name='f8_ws']/int[@name='eight_1'][.='45']", "//lst[@name='f8_ws']/int[@name='eight_10'][.='5']", "//lst[@name='f9_ws']/int[@name='nine_1'][.='45']", "//lst[@name='f9_ws']/int[@name='nine_11'][.='5']");
assertQ("check threading, fewer threads than fields", req(methodParam, "q", "id:*", "indent", "true", "fl", "id", "rows", "1", "facet", "true", "facet.field", "f0_ws", "facet.field", "f1_ws", "facet.field", "f2_ws", "facet.field", "f3_ws", "facet.field", "f4_ws", "facet.field", "f5_ws", "facet.field", "f6_ws", "facet.field", "f7_ws", "facet.field", "f8_ws", "facet.field", "f9_ws", "facet.threads", "3", "facet.limit", "-1"), "*[count(//lst[@name='facet_fields']/lst)=10]", "*[count(//lst[@name='facet_fields']/lst/int)=20]", "//lst[@name='f0_ws']/int[@name='zero_1'][.='25']", "//lst[@name='f0_ws']/int[@name='zero_2'][.='25']", "//lst[@name='f1_ws']/int[@name='one_1'][.='33']", "//lst[@name='f1_ws']/int[@name='one_3'][.='17']", "//lst[@name='f2_ws']/int[@name='two_1'][.='37']", "//lst[@name='f2_ws']/int[@name='two_4'][.='13']", "//lst[@name='f3_ws']/int[@name='three_1'][.='40']", "//lst[@name='f3_ws']/int[@name='three_5'][.='10']", "//lst[@name='f4_ws']/int[@name='four_1'][.='41']", "//lst[@name='f4_ws']/int[@name='four_6'][.='9']", "//lst[@name='f5_ws']/int[@name='five_1'][.='42']", "//lst[@name='f5_ws']/int[@name='five_7'][.='8']", "//lst[@name='f6_ws']/int[@name='six_1'][.='43']", "//lst[@name='f6_ws']/int[@name='six_8'][.='7']", "//lst[@name='f7_ws']/int[@name='seven_1'][.='44']", "//lst[@name='f7_ws']/int[@name='seven_9'][.='6']", "//lst[@name='f8_ws']/int[@name='eight_1'][.='45']", "//lst[@name='f8_ws']/int[@name='eight_10'][.='5']", "//lst[@name='f9_ws']/int[@name='nine_1'][.='45']", "//lst[@name='f9_ws']/int[@name='nine_11'][.='5']");
// After this all, the uninverted fields should be exactly the same as they were the first time, even if we
// blast a whole bunch of identical fields at the facet code.
// The way fetching the uninverted field is written, all this is really testing is if the cache is working.
// It's NOT testing whether the pending/sleep is actually functioning, I had to do that by hand since I don't
// see how to make sure that uninverting the field multiple times actually happens to hit the wait state.
assertQ("check threading, more threads than fields", req(methodParam, "q", "id:*", "indent", "true", "fl", "id", "rows", "1", "facet", "true", "facet.field", "f0_ws", "facet.field", "f0_ws", "facet.field", "f0_ws", "facet.field", "f0_ws", "facet.field", "f0_ws", "facet.field", "f1_ws", "facet.field", "f1_ws", "facet.field", "f1_ws", "facet.field", "f1_ws", "facet.field", "f1_ws", "facet.field", "f2_ws", "facet.field", "f2_ws", "facet.field", "f2_ws", "facet.field", "f2_ws", "facet.field", "f2_ws", "facet.field", "f3_ws", "facet.field", "f3_ws", "facet.field", "f3_ws", "facet.field", "f3_ws", "facet.field", "f3_ws", "facet.field", "f4_ws", "facet.field", "f4_ws", "facet.field", "f4_ws", "facet.field", "f4_ws", "facet.field", "f4_ws", "facet.field", "f5_ws", "facet.field", "f5_ws", "facet.field", "f5_ws", "facet.field", "f5_ws", "facet.field", "f5_ws", "facet.field", "f6_ws", "facet.field", "f6_ws", "facet.field", "f6_ws", "facet.field", "f6_ws", "facet.field", "f6_ws", "facet.field", "f7_ws", "facet.field", "f7_ws", "facet.field", "f7_ws", "facet.field", "f7_ws", "facet.field", "f7_ws", "facet.field", "f8_ws", "facet.field", "f8_ws", "facet.field", "f8_ws", "facet.field", "f8_ws", "facet.field", "f8_ws", "facet.field", "f9_ws", "facet.field", "f9_ws", "facet.field", "f9_ws", "facet.field", "f9_ws", "facet.field", "f9_ws", "facet.threads", "1000", "facet.limit", "-1"), "*[count(//lst[@name='facet_fields']/lst)=10]", "*[count(//lst[@name='facet_fields']/lst/int)=20]");
} finally {
currentSearcherRef.decref();
}
}
use of org.apache.solr.search.SolrIndexSearcher in project lucene-solr by apache.
the class BaseSimilarityTestCase method getSimilarity.
/** returns the similarity in use for the field */
protected Similarity getSimilarity(String field) {
SolrCore core = h.getCore();
RefCounted<SolrIndexSearcher> searcher = core.getSearcher();
Similarity sim = searcher.get().getSimilarity(true);
searcher.decref();
while (sim instanceof PerFieldSimilarityWrapper) {
sim = ((PerFieldSimilarityWrapper) sim).get(field);
}
return sim;
}
use of org.apache.solr.search.SolrIndexSearcher in project lucene-solr by apache.
the class TestPointFields method doTestFieldNotIndexed.
private void doTestFieldNotIndexed(String field, String[] values) throws IOException {
assert values.length == 10;
// test preconditions
SchemaField sf = h.getCore().getLatestSchema().getField(field);
assertFalse("Field should be indexed=false", sf.indexed());
assertFalse("Field should be docValues=false", sf.hasDocValues());
for (int i = 0; i < 10; i++) {
assertU(adoc("id", String.valueOf(i), field, values[i]));
}
assertU(commit());
assertQ(req("q", "*:*"), "//*[@numFound='10']");
assertQ("Can't search on index=false docValues=false field", req("q", field + ":[* TO *]"), "//*[@numFound='0']");
IndexReader ir;
RefCounted<SolrIndexSearcher> ref = null;
try {
ref = h.getCore().getSearcher();
ir = ref.get().getIndexReader();
assertEquals("Field " + field + " should have no point values", 0, PointValues.size(ir, field));
} finally {
ref.decref();
}
}
use of org.apache.solr.search.SolrIndexSearcher in project lucene-solr by apache.
the class OverseerElectionContext method runLeaderProcess.
/*
* weAreReplacement: has someone else been the leader already?
*/
@Override
void runLeaderProcess(boolean weAreReplacement, int pauseBeforeStart) throws KeeperException, InterruptedException, IOException {
String coreName = leaderProps.getStr(ZkStateReader.CORE_NAME_PROP);
ActionThrottle lt;
try (SolrCore core = cc.getCore(coreName)) {
if (core == null) {
if (cc.isShutDown()) {
return;
} else {
throw new SolrException(ErrorCode.SERVER_ERROR, "SolrCore not found:" + coreName + " in " + cc.getLoadedCoreNames());
}
}
MDCLoggingContext.setCore(core);
lt = core.getUpdateHandler().getSolrCoreState().getLeaderThrottle();
}
try {
lt.minimumWaitBetweenActions();
lt.markAttemptingAction();
int leaderVoteWait = cc.getZkController().getLeaderVoteWait();
log.debug("Running the leader process for shard={} and weAreReplacement={} and leaderVoteWait={}", shardId, weAreReplacement, leaderVoteWait);
// clear the leader in clusterstate
ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION, OverseerAction.LEADER.toLower(), ZkStateReader.SHARD_ID_PROP, shardId, ZkStateReader.COLLECTION_PROP, collection);
Overseer.getStateUpdateQueue(zkClient).offer(Utils.toJSON(m));
boolean allReplicasInLine = false;
if (!weAreReplacement) {
allReplicasInLine = waitForReplicasToComeUp(leaderVoteWait);
} else {
allReplicasInLine = areAllReplicasParticipating();
}
if (isClosed) {
// re-register the cores and handle a new leadership election.
return;
}
Replica.Type replicaType;
try (SolrCore core = cc.getCore(coreName)) {
if (core == null) {
if (!zkController.getCoreContainer().isShutDown()) {
cancelElection();
throw new SolrException(ErrorCode.SERVER_ERROR, "SolrCore not found:" + coreName + " in " + cc.getLoadedCoreNames());
} else {
return;
}
}
replicaType = core.getCoreDescriptor().getCloudDescriptor().getReplicaType();
// should I be leader?
if (weAreReplacement && !shouldIBeLeader(leaderProps, core, weAreReplacement)) {
rejoinLeaderElection(core);
return;
}
log.info("I may be the new leader - try and sync");
// we are going to attempt to be the leader
// first cancel any current recovery
core.getUpdateHandler().getSolrCoreState().cancelRecovery();
if (weAreReplacement) {
// wait a moment for any floating updates to finish
try {
Thread.sleep(2500);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, e);
}
}
PeerSync.PeerSyncResult result = null;
boolean success = false;
try {
result = syncStrategy.sync(zkController, core, leaderProps, weAreReplacement);
success = result.isSuccess();
} catch (Exception e) {
SolrException.log(log, "Exception while trying to sync", e);
result = PeerSync.PeerSyncResult.failure();
}
UpdateLog ulog = core.getUpdateHandler().getUpdateLog();
if (!success) {
boolean hasRecentUpdates = false;
if (ulog != null) {
// TODO: we could optimize this if necessary
try (UpdateLog.RecentUpdates recentUpdates = ulog.getRecentUpdates()) {
hasRecentUpdates = !recentUpdates.getVersions(1).isEmpty();
}
}
if (!hasRecentUpdates) {
// before, so become leader anyway if no one else has any versions either
if (result.getOtherHasVersions().orElse(false)) {
log.info("We failed sync, but we have no versions - we can't sync in that case. But others have some versions, so we should not become leader");
success = false;
} else {
log.info("We failed sync, but we have no versions - we can't sync in that case - we were active before, so become leader anyway");
success = true;
}
}
}
// solrcloud_debug
if (log.isDebugEnabled()) {
try {
RefCounted<SolrIndexSearcher> searchHolder = core.getNewestSearcher(false);
SolrIndexSearcher searcher = searchHolder.get();
try {
log.debug(core.getCoreContainer().getZkController().getNodeName() + " synched " + searcher.search(new MatchAllDocsQuery(), 1).totalHits);
} finally {
searchHolder.decref();
}
} catch (Exception e) {
log.error("Error in solrcloud_debug block", e);
}
}
if (!success) {
rejoinLeaderElection(core);
return;
}
}
boolean isLeader = true;
if (!isClosed) {
try {
// we must check LIR before registering as leader
checkLIR(coreName, allReplicasInLine);
if (replicaType == Replica.Type.TLOG) {
// stop replicate from old leader
zkController.stopReplicationFromLeader(coreName);
if (weAreReplacement) {
try (SolrCore core = cc.getCore(coreName)) {
Future<UpdateLog.RecoveryInfo> future = core.getUpdateHandler().getUpdateLog().recoverFromCurrentLog();
if (future != null) {
log.info("Replaying tlog before become new leader");
future.get();
} else {
log.info("New leader does not have old tlog to replay");
}
}
}
}
super.runLeaderProcess(weAreReplacement, 0);
try (SolrCore core = cc.getCore(coreName)) {
if (core != null) {
core.getCoreDescriptor().getCloudDescriptor().setLeader(true);
publishActiveIfRegisteredAndNotActive(core);
} else {
return;
}
}
log.info("I am the new leader: " + ZkCoreNodeProps.getCoreUrl(leaderProps) + " " + shardId);
// we made it as leader - send any recovery requests we need to
syncStrategy.requestRecoveries();
} catch (Exception e) {
isLeader = false;
SolrException.log(log, "There was a problem trying to register as the leader", e);
try (SolrCore core = cc.getCore(coreName)) {
if (core == null) {
log.debug("SolrCore not found:" + coreName + " in " + cc.getLoadedCoreNames());
return;
}
core.getCoreDescriptor().getCloudDescriptor().setLeader(false);
// we could not publish ourselves as leader - try and rejoin election
rejoinLeaderElection(core);
}
}
if (isLeader) {
// check for any replicas in my shard that were set to down by the previous leader
try {
startLeaderInitiatedRecoveryOnReplicas(coreName);
} catch (Exception exc) {
// don't want leader election to fail because of
// an error trying to tell others to recover
}
}
} else {
cancelElection();
}
} finally {
MDCLoggingContext.clear();
}
}
Aggregations