use of org.apache.solr.core.SolrCore 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.core.SolrCore in project lucene-solr by apache.
the class TolerantUpdateProcessorTest method add.
protected SolrQueryResponse add(final String chain, SolrParams requestParams, final Collection<SolrInputDocument> docs) throws IOException {
SolrCore core = h.getCore();
UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
assertNotNull("No Chain named: " + chain, pc);
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap<Object>());
if (requestParams == null) {
requestParams = new ModifiableSolrParams();
}
SolrQueryRequest req = new LocalSolrQueryRequest(core, requestParams);
UpdateRequestProcessor processor = null;
try {
processor = pc.createProcessor(req, rsp);
for (SolrInputDocument doc : docs) {
AddUpdateCommand cmd = new AddUpdateCommand(req);
cmd.solrDoc = doc;
processor.processAdd(cmd);
}
processor.finish();
} finally {
IOUtils.closeQuietly(processor);
req.close();
}
return rsp;
}
use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class UpdateProcessorTestBase method processAdd.
/**
* Runs a document through the specified chain, and returns the final
* document used when the chain is completed (NOTE: some chains may
* modify the document in place
*/
protected SolrInputDocument processAdd(final String chain, final SolrParams requestParams, final SolrInputDocument docIn) throws IOException {
SolrCore core = h.getCore();
UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
assertNotNull("No Chain named: " + chain, pc);
SolrQueryResponse rsp = new SolrQueryResponse();
SolrQueryRequest req = new LocalSolrQueryRequest(core, requestParams);
try {
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
AddUpdateCommand cmd = new AddUpdateCommand(req);
cmd.solrDoc = docIn;
UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
if (null != processor) {
// test chain might be empty or short circuited.
processor.processAdd(cmd);
}
return cmd.solrDoc;
} finally {
SolrRequestInfo.clearRequestInfo();
req.close();
}
}
use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class UpdateProcessorTestBase method processDeleteById.
protected void processDeleteById(final String chain, String id) throws IOException {
SolrCore core = h.getCore();
UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
assertNotNull("No Chain named: " + chain, pc);
SolrQueryResponse rsp = new SolrQueryResponse();
SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
DeleteUpdateCommand cmd = new DeleteUpdateCommand(req);
cmd.setId(id);
UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
try {
processor.processDelete(cmd);
} finally {
req.close();
}
}
use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class UpdateRequestProcessorFactoryTest method testUpdateDistribChainSkipping.
public void testUpdateDistribChainSkipping() throws Exception {
// a key part of this test is verifying that LogUpdateProcessor is found in all chains because it
// is a @RunAlways processor -- but in order for that to work, we have to sanity check that the log
// level is at least "INFO" otherwise the factory won't even produce a processor and all our assertions
// are for nought. (see LogUpdateProcessorFactory.getInstance)
//
// TODO: maybe create a new mock Processor w/ @RunAlways annot if folks feel requiring INFO is evil.
assertTrue("Tests must be run with INFO level logging " + "otherwise LogUpdateProcessor isn't used and can't be tested.", log.isInfoEnabled());
final int EXPECTED_CHAIN_LENGTH = 5;
SolrCore core = h.getCore();
for (final String name : Arrays.asList("distrib-chain-explicit", "distrib-chain-implicit", "distrib-chain-noop")) {
UpdateRequestProcessor proc;
List<UpdateRequestProcessor> procs;
UpdateRequestProcessorChain chain = core.getUpdateProcessingChain(name);
assertNotNull(name, chain);
// either explicitly, or because of injection
assertEquals(name + " chain length: " + chain.toString(), EXPECTED_CHAIN_LENGTH, chain.getProcessors().size());
// test a basic (non distrib) chain
proc = chain.createProcessor(req(), new SolrQueryResponse());
procs = procToList(proc);
assertEquals(name + " procs size: " + procs.toString(), // -1 = NoOpDistributingUpdateProcessorFactory produces no processor
EXPECTED_CHAIN_LENGTH - ("distrib-chain-noop".equals(name) ? 1 : 0), procs.size());
// Custom comes first in all three of our chains
assertTrue(name + " first processor isn't a CustomUpdateRequestProcessor: " + procs.toString(), (// compare them both just because i'm going insane and the more checks the better
proc instanceof CustomUpdateRequestProcessor && procs.get(0) instanceof CustomUpdateRequestProcessor));
// Log should always come second in our chain.
assertNotNull(name + " proc.next is null", proc.next);
assertNotNull(name + " second proc is null", procs.get(1));
assertTrue(name + " second proc isn't LogUpdateProcessor: " + procs.toString(), (// compare them both just because i'm going insane and the more checks the better
proc.next instanceof LogUpdateProcessorFactory.LogUpdateProcessor && procs.get(1) instanceof LogUpdateProcessorFactory.LogUpdateProcessor));
// fetch the distributed version of this chain
proc = chain.createProcessor(req(DISTRIB_UPDATE_PARAM, "non_blank_value"), new SolrQueryResponse());
procs = procToList(proc);
assertNotNull(name + " (distrib) chain produced null proc", proc);
assertFalse(name + " (distrib) procs is empty", procs.isEmpty());
// for these 3 (distrib) chains, the first proc should always be LogUpdateProcessor
assertTrue(name + " (distrib) first proc should be LogUpdateProcessor because of @RunAllways: " + procs.toString(), (// compare them both just because i'm going insane and the more checks the better
proc instanceof LogUpdateProcessorFactory.LogUpdateProcessor && procs.get(0) instanceof LogUpdateProcessorFactory.LogUpdateProcessor));
// for these 3 (distrib) chains, the last proc should always be RunUpdateProcessor
assertTrue(name + " (distrib) last processor isn't a RunUpdateProcessor: " + procs.toString(), procs.get(procs.size() - 1) instanceof RunUpdateProcessor);
// either 1 proc was droped in distrib mode, or 1 for the "implicit" chain
assertEquals(name + " (distrib) chain has wrong length: " + procs.toString(), // -1 = distrib-chain-implicit: does RemoveBlank before distrib
EXPECTED_CHAIN_LENGTH - ("distrib-chain-explicit".equals(name) ? 1 : 2), procs.size());
}
}
Aggregations