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;
}
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']"));
}
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");
}
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());
}
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();
}
Aggregations