Search in sources :

Example 56 with SolrIndexSearcher

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]");
}
Also used : SegmentInfos(org.apache.lucene.index.SegmentInfos) IndexWriter(org.apache.lucene.index.IndexWriter) SegmentInfo(org.apache.lucene.index.SegmentInfo) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher)

Example 57 with SolrIndexSearcher

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();
    }
}
Also used : SortedSetDocValues(org.apache.lucene.index.SortedSetDocValues) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) Test(org.junit.Test)

Example 58 with SolrIndexSearcher

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;
}
Also used : Similarity(org.apache.lucene.search.similarities.Similarity) SolrCore(org.apache.solr.core.SolrCore) PerFieldSimilarityWrapper(org.apache.lucene.search.similarities.PerFieldSimilarityWrapper) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher)

Example 59 with SolrIndexSearcher

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();
    }
}
Also used : IndexReader(org.apache.lucene.index.IndexReader) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) LongPoint(org.apache.lucene.document.LongPoint) DoublePoint(org.apache.lucene.document.DoublePoint) IntPoint(org.apache.lucene.document.IntPoint) FloatPoint(org.apache.lucene.document.FloatPoint)

Example 60 with SolrIndexSearcher

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();
    }
}
Also used : SolrCore(org.apache.solr.core.SolrCore) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) PeerSync(org.apache.solr.update.PeerSync) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) Replica(org.apache.solr.common.cloud.Replica) SolrException(org.apache.solr.common.SolrException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) UpdateLog(org.apache.solr.update.UpdateLog) SolrException(org.apache.solr.common.SolrException)

Aggregations

SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)97 SolrException (org.apache.solr.common.SolrException)29 NamedList (org.apache.solr.common.util.NamedList)29 SolrCore (org.apache.solr.core.SolrCore)28 IOException (java.io.IOException)23 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)20 SolrParams (org.apache.solr.common.params.SolrParams)19 SchemaField (org.apache.solr.schema.SchemaField)18 IndexReader (org.apache.lucene.index.IndexReader)13 DocList (org.apache.solr.search.DocList)13 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)12 Map (java.util.Map)11 Document (org.apache.lucene.document.Document)11 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)11 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)11 IndexSchema (org.apache.solr.schema.IndexSchema)11 LeafReader (org.apache.lucene.index.LeafReader)10 Query (org.apache.lucene.search.Query)10 HashMap (java.util.HashMap)9