use of org.apache.solr.search.SolrIndexSearcher in project lucene-solr by apache.
the class ClassificationUpdateProcessorIntegrationTest method getDoc.
private Document getDoc(String id) throws IOException {
try (SolrQueryRequest req = req()) {
SolrIndexSearcher searcher = req.getSearcher();
TermQuery query = new TermQuery(new Term(ID, id));
TopDocs doc1 = searcher.search(query, 1);
ScoreDoc scoreDoc = doc1.scoreDocs[0];
return searcher.doc(scoreDoc.doc);
}
}
use of org.apache.solr.search.SolrIndexSearcher in project lucene-solr by apache.
the class TestQuerySenderNoQuery method testSearcherEvents.
// Determine that when the query lists are commented out of both new and
// first searchers in the config, we don't throw an NPE
@Test
public void testSearcherEvents() throws Exception {
SolrCore core = h.getCore();
SolrEventListener newSearcherListener = core.newSearcherListeners.get(0);
assertTrue("Not an instance of QuerySenderListener", newSearcherListener instanceof QuerySenderListener);
QuerySenderListener qsl = (QuerySenderListener) newSearcherListener;
RefCounted<SolrIndexSearcher> currentSearcherRef = core.getSearcher();
SolrIndexSearcher currentSearcher = currentSearcherRef.get();
SolrIndexSearcher dummy = null;
//test first Searcher (since param is null)
qsl.newSearcher(currentSearcher, dummy);
MockQuerySenderListenerReqHandler mock = (MockQuerySenderListenerReqHandler) core.getRequestHandler("mock");
assertNotNull("Mock is null", mock);
assertNull("Req (firstsearcher) is not null", mock.req);
SolrIndexSearcher newSearcher = new SolrIndexSearcher(core, core.getNewIndexDir(), core.getLatestSchema(), core.getSolrConfig().indexConfig, "testQuerySenderNoQuery", false, core.getDirectoryFactory());
// get newSearcher.
qsl.newSearcher(newSearcher, currentSearcher);
assertNull("Req (newsearcher) is not null", mock.req);
newSearcher.close();
currentSearcherRef.decref();
}
use of org.apache.solr.search.SolrIndexSearcher in project lucene-solr by apache.
the class WordBreakSolrSpellCheckerTest method testStandAlone.
@Test
public void testStandAlone() throws Exception {
SolrCore core = h.getCore();
WordBreakSolrSpellChecker checker = new WordBreakSolrSpellChecker();
NamedList<String> params = new NamedList<>();
params.add("field", "lowerfilt");
params.add(WordBreakSolrSpellChecker.PARAM_BREAK_WORDS, "true");
params.add(WordBreakSolrSpellChecker.PARAM_COMBINE_WORDS, "true");
params.add(WordBreakSolrSpellChecker.PARAM_MAX_CHANGES, "10");
checker.init(params, core);
RefCounted<SolrIndexSearcher> searcher = core.getSearcher();
QueryConverter qc = new SpellingQueryConverter();
qc.setAnalyzer(new MockAnalyzer(random()));
{
//Prior to SOLR-8175, the required term would cause an AIOOBE.
Collection<Token> tokens = qc.convert("+pine apple good ness");
SpellingOptions spellOpts = new SpellingOptions(tokens, searcher.get().getIndexReader(), 10);
SpellingResult result = checker.getSuggestions(spellOpts);
searcher.decref();
assertTrue(result != null && result.getSuggestions() != null);
assertTrue(result.getSuggestions().size() == 5);
}
Collection<Token> tokens = qc.convert("paintable pine apple good ness");
SpellingOptions spellOpts = new SpellingOptions(tokens, searcher.get().getIndexReader(), 10);
SpellingResult result = checker.getSuggestions(spellOpts);
searcher.decref();
assertTrue(result != null && result.getSuggestions() != null);
assertTrue(result.getSuggestions().size() == 9);
for (Map.Entry<Token, LinkedHashMap<String, Integer>> s : result.getSuggestions().entrySet()) {
Token orig = s.getKey();
String[] corr = s.getValue().keySet().toArray(new String[0]);
if (orig.toString().equals("paintable")) {
assertTrue(orig.startOffset() == 0);
assertTrue(orig.endOffset() == 9);
assertTrue(orig.length() == 9);
assertTrue(corr.length == 3);
//1 op ; max doc freq=5
assertTrue(corr[0].equals("paint able"));
//1 op ; max doc freq=2
assertTrue(corr[1].equals("pain table"));
//2 ops
assertTrue(corr[2].equals("pa in table"));
} else if (orig.toString().equals("pine apple")) {
assertTrue(orig.startOffset() == 10);
assertTrue(orig.endOffset() == 20);
assertTrue(orig.length() == 10);
assertTrue(corr.length == 1);
assertTrue(corr[0].equals("pineapple"));
} else if (orig.toString().equals("paintable pine")) {
assertTrue(orig.startOffset() == 0);
assertTrue(orig.endOffset() == 14);
assertTrue(orig.length() == 14);
assertTrue(corr.length == 1);
assertTrue(corr[0].equals("paintablepine"));
} else if (orig.toString().equals("good ness")) {
assertTrue(orig.startOffset() == 21);
assertTrue(orig.endOffset() == 30);
assertTrue(orig.length() == 9);
assertTrue(corr.length == 1);
assertTrue(corr[0].equals("goodness"));
} else if (orig.toString().equals("pine apple good ness")) {
assertTrue(orig.startOffset() == 10);
assertTrue(orig.endOffset() == 30);
assertTrue(orig.length() == 20);
assertTrue(corr.length == 1);
assertTrue(corr[0].equals("pineapplegoodness"));
} else if (orig.toString().equals("pine")) {
assertTrue(orig.startOffset() == 10);
assertTrue(orig.endOffset() == 14);
assertTrue(orig.length() == 4);
assertTrue(corr.length == 1);
assertTrue(corr[0].equals("pi ne"));
} else if (orig.toString().equals("pine")) {
assertTrue(orig.startOffset() == 10);
assertTrue(orig.endOffset() == 14);
assertTrue(orig.length() == 4);
assertTrue(corr.length == 1);
assertTrue(corr[0].equals("pi ne"));
} else if (orig.toString().equals("apple")) {
assertTrue(orig.startOffset() == 15);
assertTrue(orig.endOffset() == 20);
assertTrue(orig.length() == 5);
assertTrue(corr.length == 0);
} else if (orig.toString().equals("good")) {
assertTrue(orig.startOffset() == 21);
assertTrue(orig.endOffset() == 25);
assertTrue(orig.length() == 4);
assertTrue(corr.length == 0);
} else if (orig.toString().equals("ness")) {
assertTrue(orig.startOffset() == 26);
assertTrue(orig.endOffset() == 30);
assertTrue(orig.length() == 4);
assertTrue(corr.length == 0);
} else {
fail("Unexpected original result: " + orig);
}
}
}
use of org.apache.solr.search.SolrIndexSearcher in project lucene-solr by apache.
the class UninvertDocValuesMergePolicyTest method withNewRawReader.
private static void withNewRawReader(TestHarness h, DirectoryReaderConsumer consumer) {
try (SolrCore core = h.getCoreInc()) {
final RefCounted<SolrIndexSearcher> searcherRef = core.openNewSearcher(true, true);
final SolrIndexSearcher searcher = searcherRef.get();
try {
try {
consumer.accept(searcher.getRawReader());
} catch (Exception e) {
fail(e.toString());
}
} finally {
searcherRef.decref();
}
}
}
use of org.apache.solr.search.SolrIndexSearcher in project lucene-solr by apache.
the class VersionInfo method getVersionFromIndex.
/**
* Returns the latest version from the index, searched by the given id (bytes) as seen from the realtime searcher.
* Returns null if no document can be found in the index for the given id.
*/
public Long getVersionFromIndex(BytesRef idBytes) {
// TODO: we could cache much of this and invalidate during a commit.
// TODO: most DocValues classes are threadsafe - expose which.
RefCounted<SolrIndexSearcher> newestSearcher = ulog.uhandler.core.getRealtimeSearcher();
try {
SolrIndexSearcher searcher = newestSearcher.get();
long lookup = searcher.lookupId(idBytes);
// this means the doc doesn't exist in the index yet
if (lookup < 0)
return null;
ValueSource vs = versionField.getType().getValueSource(versionField, null);
Map context = ValueSource.newContext(searcher);
vs.createWeight(context, searcher);
FunctionValues fv = vs.getValues(context, searcher.getTopReaderContext().leaves().get((int) (lookup >> 32)));
long ver = fv.longVal((int) lookup);
return ver;
} catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error reading version from index", e);
} finally {
if (newestSearcher != null) {
newestSearcher.decref();
}
}
}
Aggregations