Java Code Examples for org.apache.solr.response.SolrQueryResponse#addResponseHeader()
The following examples show how to use
org.apache.solr.response.SolrQueryResponse#addResponseHeader() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpellCheckCollatorTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings({"unchecked", "rawtypes"}) public void testCollationWithRangeQuery() throws Exception { SolrCore core = h.getCore(); SearchComponent speller = core.getSearchComponent("spellcheck"); assertTrue("speller is null and it shouldn't be", speller != null); ModifiableSolrParams params = new ModifiableSolrParams(); params.add(SpellCheckComponent.COMPONENT_NAME, "true"); params.add(SpellingParams.SPELLCHECK_BUILD, "true"); params.add(SpellingParams.SPELLCHECK_COUNT, "10"); params.add(SpellingParams.SPELLCHECK_COLLATE, "true"); params.add(SpellingParams.SPELLCHECK_ALTERNATIVE_TERM_COUNT, "10"); params.add(CommonParams.Q, "id:[1 TO 10] AND lowerfilt:lovw"); { SolrRequestHandler handler = core.getRequestHandler("/spellCheckCompRH"); SolrQueryResponse rsp = new SolrQueryResponse(); rsp.addResponseHeader(new SimpleOrderedMap()); SolrQueryRequest req = new LocalSolrQueryRequest(core, params); handler.handleRequest(req, rsp); req.close(); NamedList values = rsp.getValues(); NamedList spellCheck = (NamedList) values.get("spellcheck"); NamedList collationHolder = (NamedList) spellCheck.get("collations"); List<String> collations = collationHolder.getAll("collation"); assertTrue(collations.size()==1); String collation = collations.iterator().next(); System.out.println(collation); assertTrue("Incorrect collation: " + collation,"id:[1 TO 10] AND lowerfilt:love".equals(collation)); } }
Example 2
Source File: SpellCheckCollatorTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings({"unchecked", "rawtypes"}) public void testCollateWithFilter() throws Exception { SolrCore core = h.getCore(); SearchComponent speller = core.getSearchComponent("spellcheck"); assertTrue("speller is null and it shouldn't be", speller != null); ModifiableSolrParams params = new ModifiableSolrParams(); params.add(SpellCheckComponent.COMPONENT_NAME, "true"); params.add(SpellingParams.SPELLCHECK_BUILD, "true"); params.add(SpellingParams.SPELLCHECK_COUNT, "10"); params.add(SpellingParams.SPELLCHECK_COLLATE, "true"); params.add(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "10"); params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "10"); params.add(CommonParams.Q, "lowerfilt:(+fauth +home +loane)"); params.add(CommonParams.FQ, "NOT(id:1)"); //Because a FilterQuery is applied which removes doc id#1 from possible hits, we would //not want the collations to return us "lowerfilt:(+faith +hope +loaves)" as this only matches doc id#1. SolrRequestHandler handler = core.getRequestHandler("/spellCheckCompRH"); SolrQueryResponse rsp = new SolrQueryResponse(); rsp.addResponseHeader(new SimpleOrderedMap()); SolrQueryRequest req = new LocalSolrQueryRequest(core, params); handler.handleRequest(req, rsp); req.close(); NamedList values = rsp.getValues(); NamedList spellCheck = (NamedList) values.get("spellcheck"); NamedList collationHolder = (NamedList) spellCheck.get("collations"); List<String> collations = collationHolder.getAll("collation"); assertTrue(collations.size() > 0); for(String collation : collations) { assertTrue(!collation.equals("lowerfilt:(+faith +hope +loaves)")); } }
Example 3
Source File: SpellCheckCollatorTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings({"unchecked", "rawtypes"}) public void testCollateWithGrouping() throws Exception { SolrCore core = h.getCore(); SearchComponent speller = core.getSearchComponent("spellcheck"); assertTrue("speller is null and it shouldn't be", speller != null); ModifiableSolrParams params = new ModifiableSolrParams(); params.add(SpellCheckComponent.COMPONENT_NAME, "true"); params.add(SpellingParams.SPELLCHECK_BUILD, "true"); params.add(SpellingParams.SPELLCHECK_COUNT, "10"); params.add(SpellingParams.SPELLCHECK_COLLATE, "true"); params.add(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "5"); params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "1"); params.add(CommonParams.Q, "lowerfilt:(+fauth)"); params.add(GroupParams.GROUP, "true"); params.add(GroupParams.GROUP_FIELD, "id"); //Because a FilterQuery is applied which removes doc id#1 from possible hits, we would //not want the collations to return us "lowerfilt:(+faith +hope +loaves)" as this only matches doc id#1. SolrRequestHandler handler = core.getRequestHandler("/spellCheckCompRH"); SolrQueryResponse rsp = new SolrQueryResponse(); rsp.addResponseHeader(new SimpleOrderedMap()); SolrQueryRequest req = new LocalSolrQueryRequest(core, params); handler.handleRequest(req, rsp); req.close(); NamedList values = rsp.getValues(); NamedList spellCheck = (NamedList) values.get("spellcheck"); NamedList collationHolder = (NamedList) spellCheck.get("collations"); List<String> collations = collationHolder.getAll("collation"); assertTrue(collations.size() == 1); }
Example 4
Source File: SpellCheckCollatorTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings({"unchecked", "rawtypes"}) public void testZeroTries() throws Exception { SolrCore core = h.getCore(); SearchComponent speller = core.getSearchComponent("spellcheck"); assertTrue("speller is null and it shouldn't be", speller != null); ModifiableSolrParams params = new ModifiableSolrParams(); params.add(SpellCheckComponent.COMPONENT_NAME, "true"); params.add(SpellCheckComponent.SPELLCHECK_BUILD, "true"); params.add(SpellCheckComponent.SPELLCHECK_COUNT, "10"); params.add(SpellCheckComponent.SPELLCHECK_COLLATE, "true"); params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATION_TRIES, "0"); params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "2"); params.add(CommonParams.Q, "lowerfilt:(+fauth)"); SolrRequestHandler handler = core.getRequestHandler("/spellCheckCompRH"); SolrQueryResponse rsp = new SolrQueryResponse(); rsp.addResponseHeader(new SimpleOrderedMap()); SolrQueryRequest req = new LocalSolrQueryRequest(core, params); handler.handleRequest(req, rsp); req.close(); NamedList values = rsp.getValues(); NamedList spellCheck = (NamedList) values.get("spellcheck"); NamedList collationList = (NamedList) spellCheck.get("collations"); List<?> collations = (List<?>) collationList.getAll("collation"); assertTrue(collations.size() == 2); }
Example 5
Source File: SpellCheckCollatorTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings({"unchecked", "rawtypes"}) public void testWithCursorMark() throws Exception { SolrCore core = h.getCore(); SearchComponent speller = core.getSearchComponent("spellcheck"); assertTrue("speller is null and it shouldn't be", speller != null); ModifiableSolrParams params = new ModifiableSolrParams(); params.add(SpellCheckComponent.COMPONENT_NAME, "true"); params.add(SpellCheckComponent.SPELLCHECK_BUILD, "true"); params.add(SpellCheckComponent.SPELLCHECK_COUNT, "10"); params.add(SpellCheckComponent.SPELLCHECK_COLLATE, "true"); params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATION_TRIES, "2"); params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "1"); params.add(CommonParams.Q, "lowerfilt:(+fauth)"); params.add(CommonParams.SORT, "id asc"); params.add(CursorMarkParams.CURSOR_MARK_PARAM, CursorMarkParams.CURSOR_MARK_START); SolrRequestHandler handler = core.getRequestHandler("/spellCheckCompRH"); SolrQueryResponse rsp = new SolrQueryResponse(); rsp.addResponseHeader(new SimpleOrderedMap()); SolrQueryRequest req = new LocalSolrQueryRequest(core, params); handler.handleRequest(req, rsp); req.close(); NamedList values = rsp.getValues(); NamedList spellCheck = (NamedList) values.get("spellcheck"); NamedList collationList = (NamedList) spellCheck.get("collations"); List<?> collations = (List<?>) collationList.getAll("collation"); assertTrue(collations.size() == 1); }
Example 6
Source File: DocExpirationUpdateProcessorFactory.java From lucene-solr with Apache License 2.0 | 4 votes |
public void run() { // setup the request context early so the logging (including any from // shouldWeDoPeriodicDelete() ) includes the core context info final LocalSolrQueryRequest req = new LocalSolrQueryRequest (factory.core, Collections.<String,String[]>emptyMap()); try { // HACK: to indicate to PKI that this is a server initiated request for the purposes // of distributed requet/credential forwarding... req.setUserPrincipalName(PKIAuthenticationPlugin.NODE_IS_USER); final SolrQueryResponse rsp = new SolrQueryResponse(); rsp.addResponseHeader(new SimpleOrderedMap<>(1)); SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp)); try { if (! factory.iAmInChargeOfPeriodicDeletes() ) { // No-Op return; } log.info("Beginning periodic deletion of expired docs"); UpdateRequestProcessorChain chain = core.getUpdateProcessingChain(deleteChainName); UpdateRequestProcessor proc = chain.createProcessor(req, rsp); if (null == proc) { log.warn("No active processors, skipping automatic deletion of expired docs using chain: {}" , deleteChainName); return; } try { DeleteUpdateCommand del = new DeleteUpdateCommand(req); del.setQuery("{!cache=false}" + expireField + ":[* TO " + SolrRequestInfo.getRequestInfo().getNOW().toInstant() + "]"); proc.processDelete(del); // TODO: should this be more configurable? // TODO: in particular: should hard commit be optional? CommitUpdateCommand commit = new CommitUpdateCommand(req, false); commit.softCommit = true; commit.openSearcher = true; proc.processCommit(commit); } finally { try { proc.finish(); } finally { proc.close(); } } log.info("Finished periodic deletion of expired docs"); } catch (IOException ioe) { log.error("IOException in periodic deletion of expired docs: {}", ioe.getMessage(), ioe); // DO NOT RETHROW: ScheduledExecutor will suppress subsequent executions } catch (RuntimeException re) { log.error("Runtime error in periodic deletion of expired docs: {}", re.getMessage(), re); // DO NOT RETHROW: ScheduledExecutor will suppress subsequent executions } finally { SolrRequestInfo.clearRequestInfo(); } } finally { req.close(); } }