Java Code Examples for org.apache.solr.core.SolrCore#getSearchComponent()

The following examples show how to use org.apache.solr.core.SolrCore#getSearchComponent() . 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: TestXJoinValueSourceParser.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void initialise() throws Exception {
  SolrCore core = h.getCore();

  XJoinSearchComponent xjsc = (XJoinSearchComponent)core.getSearchComponent(componentName);
  DummyXJoinResultsFactory xjrf = (DummyXJoinResultsFactory)xjsc.getResultsFactory();
  XJoinResults<?> results = xjrf.getResults(null);
  
  // mock SolrQueryRequest with join results in the context
  sqr = mock(SolrQueryRequest.class);
  Map<Object, Object> context = new HashMap<>();
  context.put(xjsc.getResultsTag(), results);
  when(sqr.getContext()).thenReturn(context);
  when(sqr.getCore()).thenReturn(core);
  
  searcher = core.getRegisteredSearcher().get();
  
  missingDoc = new Integer(xjrf.getMissingId());
}
 
Example 2
Source File: AbstractXJoinTestCase.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
protected NamedList test(ModifiableSolrParams params, String componentName) {
  SolrCore core = h.getCore();

  SearchComponent sc = core.getSearchComponent(componentName);
  assertTrue("XJoinSearchComponent not found in solrconfig", sc != null);
    
  QParserPlugin qp = core.getQueryPlugin("xjoin");
  assertTrue("XJoinQParserPlugin not found in solrconfig", qp != null);
  
  params.add("q", "*:*");
  params.add("fq", "{!xjoin}" + componentName);

  SolrQueryResponse rsp = new SolrQueryResponse();
  rsp.add("responseHeader", new SimpleOrderedMap<>());
  SolrQueryRequest req = new LocalSolrQueryRequest(core, params);

  SolrRequestHandler handler = core.getRequestHandler("standard");
  handler.handleRequest(req, rsp);
  req.close();
  assertNull(rsp.getException());
    
  return rsp.getValues();
}
 
Example 3
Source File: TestXJoinValueSourceParser.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void initialise() throws Exception {
  SolrCore core = h.getCore();

  XJoinSearchComponent xjsc = (XJoinSearchComponent)core.getSearchComponent(componentName);
  DummyXJoinResultsFactory xjrf = (DummyXJoinResultsFactory)xjsc.getResultsFactory();
  XJoinResults<?> results = xjrf.getResults(null);
  
  // mock SolrQueryRequest with join results in the context
  sqr = mock(SolrQueryRequest.class);
  Map<Object, Object> context = new HashMap<>();
  context.put(xjsc.getResultsTag(), results);
  when(sqr.getContext()).thenReturn(context);
  when(sqr.getCore()).thenReturn(core);
  
  searcher = core.getRegisteredSearcher().get();
  
  missingDoc = new Integer(xjrf.getMissingId());
}
 
Example 4
Source File: AbstractXJoinTestCase.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
protected NamedList test(ModifiableSolrParams params, String componentName) {
  SolrCore core = h.getCore();

  SearchComponent sc = core.getSearchComponent(componentName);
  assertTrue("XJoinSearchComponent not found in solrconfig", sc != null);
    
  QParserPlugin qp = core.getQueryPlugin("xjoin");
  assertTrue("XJoinQParserPlugin not found in solrconfig", qp != null);
  
  params.add("q", "*:*");
  params.add("fq", "{!xjoin}" + componentName);

  SolrQueryResponse rsp = new SolrQueryResponse();
  rsp.add("responseHeader", new SimpleOrderedMap<>());
  SolrQueryRequest req = new LocalSolrQueryRequest(core, params);

  SolrRequestHandler handler = core.getRequestHandler("standard");
  handler.handleRequest(req, rsp);
  req.close();
  assertNull(rsp.getException());
    
  return rsp.getValues();
}
 
Example 5
Source File: TestXJoinValueSourceParser.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void initialise() throws Exception {
  SolrCore core = h.getCore();

  XJoinSearchComponent xjsc = (XJoinSearchComponent)core.getSearchComponent(componentName);
  DummyXJoinResultsFactory xjrf = (DummyXJoinResultsFactory)xjsc.getResultsFactory();
  XJoinResults<?> results = xjrf.getResults(null);
  
  // mock SolrQueryRequest with join results in the context
  sqr = mock(SolrQueryRequest.class);
  Map<Object, Object> context = new HashMap<>();
  context.put(xjsc.getResultsTag(), results);
  when(sqr.getContext()).thenReturn(context);
  when(sqr.getCore()).thenReturn(core);
  
  searcher = core.getRegisteredSearcher().get();
  
  missingDoc = new Integer(xjrf.getMissingId());
}
 
Example 6
Source File: AbstractXJoinTestCase.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
protected NamedList test(ModifiableSolrParams params, String componentName) {
  SolrCore core = h.getCore();

  SearchComponent sc = core.getSearchComponent(componentName);
  assertTrue("XJoinSearchComponent not found in solrconfig", sc != null);
    
  QParserPlugin qp = core.getQueryPlugin("xjoin");
  assertTrue("XJoinQParserPlugin not found in solrconfig", qp != null);
  
  params.add("q", "*:*");
  params.add("fq", "{!xjoin}" + componentName);

  SolrQueryResponse rsp = new SolrQueryResponse();
  rsp.add("responseHeader", new SimpleOrderedMap<>());
  SolrQueryRequest req = new LocalSolrQueryRequest(core, params);

  SolrRequestHandler handler = core.getRequestHandler("standard");
  handler.handleRequest(req, rsp);
  req.close();
  assertNull(rsp.getException());
    
  return rsp.getValues();
}
 
Example 7
Source File: SpellCheckCollatorTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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 8
Source File: SpellCheckCollatorTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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 9
Source File: SpellCheckCollatorTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: SpellCheckCollatorTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: SpellCheckCollatorTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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 12
Source File: TestXJoinQParserPlugin.java    From BioSolr with Apache License 2.0 4 votes vote down vote up
private static void initComponent(SolrCore core, Map<Object, Object> context, String componentName) throws IOException {
  XJoinSearchComponent xjsc = (XJoinSearchComponent)core.getSearchComponent(componentName);
  DummyXJoinResultsFactory xjrf = (DummyXJoinResultsFactory)xjsc.getResultsFactory();
  XJoinResults<?> results = xjrf.getResults(null);
  context.put(xjsc.getResultsTag(), results);    
}
 
Example 13
Source File: TestXJoinQParserPlugin.java    From BioSolr with Apache License 2.0 4 votes vote down vote up
private static void initComponent(SolrCore core, Map<Object, Object> context, String componentName) throws IOException {
  XJoinSearchComponent xjsc = (XJoinSearchComponent)core.getSearchComponent(componentName);
  DummyXJoinResultsFactory xjrf = (DummyXJoinResultsFactory)xjsc.getResultsFactory();
  XJoinResults<?> results = xjrf.getResults(null);
  context.put(xjsc.getResultsTag(), results);    
}
 
Example 14
Source File: TestXJoinQParserPlugin.java    From BioSolr with Apache License 2.0 4 votes vote down vote up
private static void initComponent(SolrCore core, Map<Object, Object> context, String componentName) throws IOException {
  XJoinSearchComponent xjsc = (XJoinSearchComponent)core.getSearchComponent(componentName);
  DummyXJoinResultsFactory xjrf = (DummyXJoinResultsFactory)xjsc.getResultsFactory();
  XJoinResults<?> results = xjrf.getResults(null);
  context.put(xjsc.getResultsTag(), results);    
}