Search in sources :

Example 31 with SolrIndexSearcher

use of org.apache.solr.search.SolrIndexSearcher in project lucene-solr by apache.

the class AutoCommitTest method waitForNewSearcher.

boolean waitForNewSearcher(int timeoutMs) {
    TimeOut timeout = new TimeOut(timeoutMs, TimeUnit.MILLISECONDS);
    while (!timeout.hasTimedOut()) {
        if (triggered) {
            // check if the new searcher has been registered yet
            RefCounted<SolrIndexSearcher> registeredSearcherH = newSearcher.getCore().getSearcher();
            SolrIndexSearcher registeredSearcher = registeredSearcherH.get();
            registeredSearcherH.decref();
            if (registeredSearcher == newSearcher)
                return true;
        // log.info("TEST: waiting for searcher " + newSearcher + " to be registered.  current=" + registeredSearcher);
        }
        try {
            Thread.sleep(250);
        } catch (InterruptedException e) {
        }
    }
    return false;
}
Also used : TimeOut(org.apache.solr.util.TimeOut) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher)

Example 32 with SolrIndexSearcher

use of org.apache.solr.search.SolrIndexSearcher in project lucene-solr by apache.

the class AddBlockUpdateTest method testOverwrite.

@Test
public void testOverwrite() throws IOException {
    assertU(add(nest(doc("id", "X", parent, "X"), doc(child, "a", "id", "66"), doc(child, "b", "id", "66"))));
    assertU(add(nest(doc("id", "Y", parent, "Y"), doc(child, "a", "id", "66"), doc(child, "b", "id", "66"))));
    String overwritten = random().nextBoolean() ? "X" : "Y";
    String dubbed = overwritten == "X" ? "Y" : "X";
    assertU(add(nest(doc("id", overwritten, parent, overwritten), doc(child, "c", "id", "66"), doc(child, "d", "id", "66")), "overwrite", "true"));
    assertU(add(nest(doc("id", dubbed, parent, dubbed), doc(child, "c", "id", "66"), doc(child, "d", "id", "66")), "overwrite", "false"));
    assertU(commit());
    assertQ(req(parent + ":" + overwritten, "//*[@numFound='1']"));
    assertQ(req(parent + ":" + dubbed, "//*[@numFound='2']"));
    final SolrIndexSearcher searcher = getSearcher();
    assertSingleParentOf(searcher, one("ab"), dubbed);
    final TopDocs docs = searcher.search(join(one("cd")), 10);
    assertEquals(2, docs.totalHits);
    final String pAct = searcher.doc(docs.scoreDocs[0].doc).get(parent) + searcher.doc(docs.scoreDocs[1].doc).get(parent);
    assertTrue(pAct.contains(dubbed) && pAct.contains(overwritten) && pAct.length() == 2);
    assertQ(req("id:66", "//*[@numFound='6']"));
    assertQ(req(child + ":(a b)", "//*[@numFound='2']"));
    assertQ(req(child + ":(c d)", "//*[@numFound='4']"));
}
Also used : TopDocs(org.apache.lucene.search.TopDocs) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) Test(org.junit.Test)

Example 33 with SolrIndexSearcher

use of org.apache.solr.search.SolrIndexSearcher in project lucene-solr by apache.

the class AddBlockUpdateTest method testSolrJXML.

@SuppressWarnings("serial")
@Test
public void testSolrJXML() throws IOException {
    UpdateRequest req = new UpdateRequest();
    List<SolrInputDocument> docs = new ArrayList<>();
    SolrInputDocument document1 = new SolrInputDocument() {

        {
            final String id = id();
            addField("id", id);
            addField("parent_s", "X");
            ArrayList<SolrInputDocument> ch1 = new ArrayList<>(Arrays.asList(new SolrInputDocument() {

                {
                    addField("id", id());
                    addField("child_s", "y");
                }
            }, new SolrInputDocument() {

                {
                    addField("id", id());
                    addField("child_s", "z");
                }
            }));
            Collections.shuffle(ch1, random());
            addChildDocuments(ch1);
        }
    };
    SolrInputDocument document2 = new SolrInputDocument() {

        {
            final String id = id();
            addField("id", id);
            addField("parent_s", "A");
            addChildDocument(new SolrInputDocument() {

                {
                    addField("id", id());
                    addField("child_s", "b");
                }
            });
            addChildDocument(new SolrInputDocument() {

                {
                    addField("id", id());
                    addField("child_s", "c");
                }
            });
        }
    };
    docs.add(document1);
    docs.add(document2);
    Collections.shuffle(docs, random());
    req.add(docs);
    RequestWriter requestWriter = new RequestWriter();
    OutputStream os = new ByteArrayOutputStream();
    requestWriter.write(req, os);
    assertBlockU(os.toString());
    assertU(commit());
    final SolrIndexSearcher searcher = getSearcher();
    assertSingleParentOf(searcher, one("yz"), "X");
    assertSingleParentOf(searcher, one("bc"), "A");
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) OutputStream(java.io.OutputStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) ArrayList(java.util.ArrayList) RequestWriter(org.apache.solr.client.solrj.request.RequestWriter) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) Test(org.junit.Test)

Example 34 with SolrIndexSearcher

use of org.apache.solr.search.SolrIndexSearcher in project lucene-solr by apache.

the class TestPointFields method doTestInternals.

private void doTestInternals(String field, String[] values) throws IOException {
    assertTrue(h.getCore().getLatestSchema().getField(field).getType() instanceof PointField);
    for (int i = 0; i < 10; i++) {
        assertU(adoc("id", String.valueOf(i), field, values[i]));
    }
    assertU(commit());
    IndexReader ir;
    RefCounted<SolrIndexSearcher> ref = null;
    SchemaField sf = h.getCore().getLatestSchema().getField(field);
    boolean ignoredField = !(sf.indexed() || sf.stored() || sf.hasDocValues());
    try {
        ref = h.getCore().getSearcher();
        SolrIndexSearcher searcher = ref.get();
        ir = searcher.getIndexReader();
        // our own SlowCompositeReader to check DocValues on disk w/o the UninvertingReader added by SolrIndexSearcher
        final LeafReader leafReaderForCheckingDVs = SlowCompositeReaderWrapper.wrap(searcher.getRawReader());
        if (sf.indexed()) {
            assertEquals("Field " + field + " should have point values", 10, PointValues.size(ir, field));
        } else {
            assertEquals("Field " + field + " should have no point values", 0, PointValues.size(ir, field));
        }
        if (ignoredField) {
            assertTrue("Field " + field + " should not have docValues", DocValues.getSortedNumeric(leafReaderForCheckingDVs, field).nextDoc() == DocIdSetIterator.NO_MORE_DOCS);
            assertTrue("Field " + field + " should not have docValues", DocValues.getNumeric(leafReaderForCheckingDVs, field).nextDoc() == DocIdSetIterator.NO_MORE_DOCS);
            assertTrue("Field " + field + " should not have docValues", DocValues.getSorted(leafReaderForCheckingDVs, field).nextDoc() == DocIdSetIterator.NO_MORE_DOCS);
            assertTrue("Field " + field + " should not have docValues", DocValues.getBinary(leafReaderForCheckingDVs, field).nextDoc() == DocIdSetIterator.NO_MORE_DOCS);
        } else {
            if (sf.hasDocValues()) {
                if (sf.multiValued()) {
                    assertFalse("Field " + field + " should have docValues", DocValues.getSortedNumeric(leafReaderForCheckingDVs, field).nextDoc() == DocIdSetIterator.NO_MORE_DOCS);
                } else {
                    assertFalse("Field " + field + " should have docValues", DocValues.getNumeric(leafReaderForCheckingDVs, field).nextDoc() == DocIdSetIterator.NO_MORE_DOCS);
                }
            } else {
                expectThrows(IllegalStateException.class, () -> DocValues.getSortedNumeric(leafReaderForCheckingDVs, field));
                expectThrows(IllegalStateException.class, () -> DocValues.getNumeric(leafReaderForCheckingDVs, field));
            }
            expectThrows(IllegalStateException.class, () -> DocValues.getSorted(leafReaderForCheckingDVs, field));
            expectThrows(IllegalStateException.class, () -> DocValues.getBinary(leafReaderForCheckingDVs, field));
        }
        for (LeafReaderContext leave : ir.leaves()) {
            LeafReader reader = leave.reader();
            for (int i = 0; i < reader.numDocs(); i++) {
                Document doc = reader.document(i);
                if (sf.stored()) {
                    assertNotNull("Field " + field + " not found. Doc: " + doc, doc.get(field));
                } else {
                    assertNull(doc.get(field));
                }
            }
        }
    } finally {
        ref.decref();
    }
    clearIndex();
    assertU(commit());
}
Also used : LeafReader(org.apache.lucene.index.LeafReader) IndexReader(org.apache.lucene.index.IndexReader) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) Document(org.apache.lucene.document.Document) SolrInputDocument(org.apache.solr.common.SolrInputDocument) 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 35 with SolrIndexSearcher

use of org.apache.solr.search.SolrIndexSearcher in project lucene-solr by apache.

the class DirectSolrSpellCheckerTest method test.

@Test
public void test() throws Exception {
    DirectSolrSpellChecker checker = new DirectSolrSpellChecker();
    NamedList spellchecker = new NamedList();
    spellchecker.add("classname", DirectSolrSpellChecker.class.getName());
    spellchecker.add(SolrSpellChecker.FIELD, "teststop");
    // we will try "fob"
    spellchecker.add(DirectSolrSpellChecker.MINQUERYLENGTH, 2);
    SolrCore core = h.getCore();
    checker.init(spellchecker, core);
    RefCounted<SolrIndexSearcher> searcher = core.getSearcher();
    Collection<Token> tokens = queryConverter.convert("fob");
    SpellingOptions spellOpts = new SpellingOptions(tokens, searcher.get().getIndexReader());
    SpellingResult result = checker.getSuggestions(spellOpts);
    assertTrue("result is null and it shouldn't be", result != null);
    Map<String, Integer> suggestions = result.get(tokens.iterator().next());
    Map.Entry<String, Integer> entry = suggestions.entrySet().iterator().next();
    assertTrue(entry.getKey() + " is not equal to " + "foo", entry.getKey().equals("foo") == true);
    assertFalse(entry.getValue() + " equals: " + SpellingResult.NO_FREQUENCY_INFO, entry.getValue() == SpellingResult.NO_FREQUENCY_INFO);
    spellOpts.tokens = queryConverter.convert("super");
    result = checker.getSuggestions(spellOpts);
    assertTrue("result is null and it shouldn't be", result != null);
    suggestions = result.get(tokens.iterator().next());
    assertTrue("suggestions is not null and it should be", suggestions == null);
    searcher.decref();
}
Also used : NamedList(org.apache.solr.common.util.NamedList) SolrCore(org.apache.solr.core.SolrCore) Token(org.apache.lucene.analysis.Token) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) Map(java.util.Map) Test(org.junit.Test)

Aggregations

SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)125 SolrCore (org.apache.solr.core.SolrCore)33 NamedList (org.apache.solr.common.util.NamedList)32 SolrException (org.apache.solr.common.SolrException)31 IOException (java.io.IOException)29 ArrayList (java.util.ArrayList)24 SolrParams (org.apache.solr.common.params.SolrParams)22 SchemaField (org.apache.solr.schema.SchemaField)22 Test (org.junit.Test)22 Document (org.apache.lucene.document.Document)21 SolrInputDocument (org.apache.solr.common.SolrInputDocument)17 Term (org.apache.lucene.index.Term)16 IndexReader (org.apache.lucene.index.IndexReader)14 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)14 IndexSchema (org.apache.solr.schema.IndexSchema)14 DocList (org.apache.solr.search.DocList)14 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)13 SolrDocument (org.apache.solr.common.SolrDocument)13 FieldType (org.apache.solr.schema.FieldType)13 Query (org.apache.lucene.search.Query)12