org.apache.solr.handler.component.SearchComponent Java Examples

The following examples show how to use org.apache.solr.handler.component.SearchComponent. 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: MtasSolrComponentPrefix.java    From mtas with Apache License 2.0 6 votes vote down vote up
public void modifyRequest(ResponseBuilder rb, SearchComponent who,
    ShardRequest sreq) {
  if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) {
    if (sreq.params.getBool(PARAM_MTAS_PREFIX, false)
        && (sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) {
      // do nothing
    } else {
      // remove prefix for other requests
      Set<String> keys = MtasSolrResultUtil
          .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_PREFIX);
      sreq.params.remove(PARAM_MTAS_PREFIX);
      for (String key : keys) {
        sreq.params.remove(
            PARAM_MTAS_PREFIX + "." + key + "." + NAME_MTAS_PREFIX_FIELD);
        sreq.params.remove(
            PARAM_MTAS_PREFIX + "." + key + "." + NAME_MTAS_PREFIX_KEY);
      }
    }
  }
}
 
Example #2
Source File: NumFoundSearchComponent.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@Override
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) {
	System.out.println("===== MODIFY REQUEST =====");
	System.out.println("who=" + who);
	System.out.println("purpose=" + sreq.purpose);
	if ((sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) > 0) {
		if (fieldListIncludes(rb, DJOIN_FIELD)) {
			Set<String> fl = new HashSet<>(getFieldList(sreq.params));
			fl.add(SHARD_FIELD);
			sreq.params.set(CommonParams.FL, String.join(",", fl));
		}
		
		// enable faceting on shards to get join ids
		sreq.params.set("facet", true);
		sreq.params.set("facet.field", joinField);
	}
}
 
Example #3
Source File: FacetModule.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) {
  FacetComponentState facetState = getFacetComponentState(rb);
  if (facetState == null) return;

  if ((sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) {
    sreq.purpose |= FacetModule.PURPOSE_GET_JSON_FACETS;
    sreq.params.set(FACET_INFO, "{}"); // The presence of FACET_INFO (_facet_) turns on json faceting
  } else {
    // turn off faceting on other requests
    /*** distributedProcess will need to use other requests for refinement
     sreq.params.remove("json.facet");  // this just saves space... the presence of FACET_INFO really control the faceting
     sreq.params.remove(FACET_INFO);
     **/
  }
}
 
Example #4
Source File: MtasSolrComponentDocument.java    From mtas with Apache License 2.0 6 votes vote down vote up
public void modifyRequest(ResponseBuilder rb, SearchComponent who,
    ShardRequest sreq) {
  if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
      && sreq.params.getBool(PARAM_MTAS_DOCUMENT, false)) {
    if ((sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) != 0) {
      // do nothing
    } else {
      Set<String> keys = MtasSolrResultUtil
          .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_DOCUMENT);
      sreq.params.remove(PARAM_MTAS_DOCUMENT);
      for (String key : keys) {
        sreq.params.remove(
            PARAM_MTAS_DOCUMENT + "." + key + "." + NAME_MTAS_DOCUMENT_FIELD);
        sreq.params.remove(
            PARAM_MTAS_DOCUMENT + "." + key + "." + NAME_MTAS_DOCUMENT_KEY);
        sreq.params.remove(PARAM_MTAS_DOCUMENT + "." + key + "."
            + NAME_MTAS_DOCUMENT_PREFIX);
      }
    }
  }

}
 
Example #5
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 #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: PluginBag.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public static void initInstance(Object inst, PluginInfo info) {
  if (inst instanceof PluginInfoInitialized) {
    ((PluginInfoInitialized) inst).init(info);
  } else if (inst instanceof NamedListInitializedPlugin) {
    ((NamedListInitializedPlugin) inst).init(info.initArgs);
  } else if (inst instanceof SolrRequestHandler) {
    ((SolrRequestHandler) inst).init(info.initArgs);
  }
  if (inst instanceof SearchComponent) {
    ((SearchComponent) inst).setName(info.name);
  }
  if (inst instanceof RequestHandlerBase) {
    ((RequestHandlerBase) inst).setPluginInfo(info);
  }

}
 
Example #8
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 #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 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 #10
Source File: MtasSolrComponentKwic.java    From mtas with Apache License 2.0 5 votes vote down vote up
public void modifyRequest(ResponseBuilder rb, SearchComponent who,
    ShardRequest sreq) {
  if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) {
    if (sreq.params.getBool(PARAM_MTAS_KWIC, false)
        && (sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) != 0) {
      // do nothing
    } else {
      Set<String> keys = MtasSolrResultUtil
          .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_KWIC);
      sreq.params.remove(PARAM_MTAS_KWIC);
      for (String key : keys) {
        sreq.params
            .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_FIELD);
        sreq.params.remove(
            PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_TYPE);
        sreq.params.remove(
            PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_VALUE);
        sreq.params.remove(
            PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_PREFIX);
        sreq.params.remove(
            PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_IGNORE);
        sreq.params.remove(PARAM_MTAS_KWIC + "." + key + "."
            + NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH);
        sreq.params
            .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_KEY);
        sreq.params.remove(
            PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_PREFIX);
        sreq.params.remove(
            PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_NUMBER);
        sreq.params
            .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_LEFT);
        sreq.params
            .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_RIGHT);
        sreq.params.remove(
            PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_OUTPUT);
      }
    }
  }
}
 
Example #11
Source File: MtasSolrComponentCollection.java    From mtas with Apache License 2.0 5 votes vote down vote up
public void modifyRequest(ResponseBuilder rb, SearchComponent who,
    ShardRequest sreq) {
  // System.out.println(
  // "collection: " + System.nanoTime() + " - " +
  // Thread.currentThread().getId()
  // + " - " + rb.req.getParams().getBool("isShard", false)
  // + " MODIFYREQUEST " + rb.stage + " " + rb.req.getParamString());
  if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
      && sreq.params.getBool(PARAM_MTAS_COLLECTION, false)) {
    if ((sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) {
      // do nothing
    } else {
      // remove for other requests
      Set<String> keys = MtasSolrResultUtil
          .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_COLLECTION);
      sreq.params.remove(PARAM_MTAS_COLLECTION);
      for (String key : keys) {
        sreq.params.remove(PARAM_MTAS_COLLECTION + "." + key + "."
            + NAME_MTAS_COLLECTION_ACTION);
        sreq.params.remove(PARAM_MTAS_COLLECTION + "." + key + "."
            + NAME_MTAS_COLLECTION_ID);
        sreq.params.remove(PARAM_MTAS_COLLECTION + "." + key + "."
            + NAME_MTAS_COLLECTION_FIELD);
        sreq.params.remove(PARAM_MTAS_COLLECTION + "." + key + "."
            + NAME_MTAS_COLLECTION_POST);
        sreq.params.remove(PARAM_MTAS_COLLECTION + "." + key + "."
            + NAME_MTAS_COLLECTION_KEY);
        sreq.params.remove(PARAM_MTAS_COLLECTION + "." + key + "."
            + NAME_MTAS_COLLECTION_URL);
        sreq.params.remove(PARAM_MTAS_COLLECTION + "." + key + "."
            + NAME_MTAS_COLLECTION_COLLECTION);
      }
    }
  }
}
 
Example #12
Source File: MtasJoinQParser.java    From mtas with Apache License 2.0 5 votes vote down vote up
@Override
public Query parse() throws SyntaxError {
  if (id == null) {
    throw new SyntaxError("no " + MTAS_JOIN_QPARSER_COLLECTION);
  } else if (fields == null) {
    throw new SyntaxError("no " + MTAS_JOIN_QPARSER_FIELD);
  } else {

    BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder();

    MtasSolrCollectionCache mtasSolrJoinCache = null;
    for (PluginHolder<SearchComponent> item : req.getCore()
        .getSearchComponents().getRegistry().values()) {
      if (item.get() instanceof MtasSolrSearchComponent) {
        mtasSolrJoinCache = ((MtasSolrSearchComponent) item.get())
            .getCollectionCache();
      }
    }
    if (mtasSolrJoinCache != null) {
      Automaton automaton;
      try {
        automaton = mtasSolrJoinCache.getAutomatonById(id);
        if (automaton != null) {
          for (String field : fields) {
            booleanQueryBuilder.add(
                new AutomatonQuery(new Term(field), automaton), Occur.SHOULD);
          }
        } else {
          throw new IOException("no data for collection '" + id + "'");
        }
      } catch (IOException e) {
        throw new SyntaxError(
            "could not construct automaton: " + e.getMessage(), e);
      }
      return booleanQueryBuilder.build();
    } else {
      throw new SyntaxError("no MtasSolrSearchComponent found");
    }
  }
}
 
Example #13
Source File: AbstractReSearcherComponent.java    From solr-researcher with Apache License 2.0 5 votes vote down vote up
@Override
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) {
  if (!checkComponentShouldProcess(rb)) {
    return;
  }

  sreq.params.set(getComponentName(), "false");
}
 
Example #14
Source File: SpellcheckHandler.java    From customized-symspell with MIT License 5 votes vote down vote up
private void initSpellCheck() {
  List<SearchComponent> components = getComponents();
  SearchComponent spellComponent = null;
  for (SearchComponent searchComponent : components) {
    if (searchComponent instanceof SpellcheckComponent) {
      spellComponent = searchComponent;
      break;
    }
  }
  if (spellComponent == null) {
    throw new SolrException(ErrorCode.BAD_REQUEST, "Component Should be SpellCheck");
  }
  spellCheckComponent = (SpellcheckComponent) spellComponent;
  spellChecker = spellCheckComponent.getSpellChecker();
}
 
Example #15
Source File: RangerSolrAuthorizer.java    From ranger with Apache License 2.0 5 votes vote down vote up
private void init0(){
	if(LOG.isDebugEnabled()) {
		LOG.debug("==> RangerSolrAuthorizer.init0()");
	}

	try {
		rangerPluginClassLoader = RangerPluginClassLoader.getInstance(RANGER_PLUGIN_TYPE, this.getClass());

		@SuppressWarnings("unchecked")
		Class<AuthorizationPlugin> cls = (Class<AuthorizationPlugin>) Class.forName(RANGER_SOLR_AUTHORIZER_IMPL_CLASSNAME, true, rangerPluginClassLoader);

		activatePluginClassLoader();

		Object impl = cls.newInstance();
		rangerSolrAuthorizerImpl = (AuthorizationPlugin)impl;
		rangerSearchComponentImpl = (SearchComponent)impl;
	} catch (Exception e) {
		// check what need to be done
		LOG.error("Error Enabling RangerSolrPlugin", e);
	} finally {
		deactivatePluginClassLoader();
	}

	if(LOG.isDebugEnabled()) {
		LOG.debug("<== RangerSolrAuthorizer.init0()");
	}
}
 
Example #16
Source File: HighlighterTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void payloadFilteringSpanQuery() throws IOException {
  clearIndex();

  String FIELD_NAME = "payloadDelimited";
  assertU(adoc("id", "0", FIELD_NAME, "word|7 word|2"));
  assertU(commit());

  //We search at a lower level than typical Solr tests because there's no QParser for payloads

  //Create query matching this payload
  Query query = new SpanPayloadCheckQuery(new SpanTermQuery(new Term(FIELD_NAME, "word")),
      Collections.singletonList(new BytesRef(new byte[]{0, 0, 0, 7})));//bytes for integer 7

  //invoke highlight component... the hard way
  final SearchComponent hlComp = h.getCore().getSearchComponent("highlight");
  SolrQueryRequest req = req("hl", "true", "hl.fl", FIELD_NAME, HighlightParams.USE_PHRASE_HIGHLIGHTER, "true");
  try {
    SolrQueryResponse resp = new SolrQueryResponse();
    ResponseBuilder rb = new ResponseBuilder(req, resp, Collections.singletonList(hlComp));
    rb.setHighlightQuery(query);
    rb.setResults(req.getSearcher().getDocListAndSet(query, (DocSet) null, null, 0, 1));
    //highlight:
    hlComp.prepare(rb);
    hlComp.process(rb);
    //inspect response
    final String[] snippets = (String[]) resp.getValues().findRecursive("highlighting", "0", FIELD_NAME);
    assertEquals("<em>word|7</em> word|2", snippets[0]);
  } finally {
    req.close();
  }
}
 
Example #17
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 #18
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 #19
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 #20
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 #21
Source File: SolrCore.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Register the default search components
 */
private void loadSearchComponents() {
  Map<String, SearchComponent> instances = createInstances(SearchComponent.standard_components);
  for (Map.Entry<String, SearchComponent> e : instances.entrySet()) e.getValue().setName(e.getKey());
  searchComponents.init(instances, this);

  for (String name : searchComponents.keySet()) {
    if (searchComponents.isLoaded(name) && searchComponents.get(name) instanceof HighlightComponent) {
      if (!HighlightComponent.COMPONENT_NAME.equals(name)) {
        searchComponents.put(HighlightComponent.COMPONENT_NAME, searchComponents.getRegistry().get(name));
      }
      break;
    }
  }
}
 
Example #22
Source File: SolrCore.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public <T extends Object> T createInitInstance(PluginInfo info, Class<T> cast, String msg, String defClassName) {
  if (info == null) return null;
  T o = createInstance(info.className == null ? defClassName : info.className, cast, msg, this, getResourceLoader(info.pkgName));
  if (o instanceof PluginInfoInitialized) {
    ((PluginInfoInitialized) o).init(info);
  } else if (o instanceof NamedListInitializedPlugin) {
    ((NamedListInitializedPlugin) o).init(info.initArgs);
  }
  if (o instanceof SearchComponent) {
    ((SearchComponent) o).setName(info.name);
  }
  return o;
}
 
Example #23
Source File: MergeSearchComponent.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
@Override
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) {
  // do the filterQParser stuff first
  super.modifyRequest(rb, who, sreq);
  
  if (! doMerge(rb)) {
    return;
  }
  
  ReturnFields rf = rb.rsp.getReturnFields();
  if (rf.wantsAllFields()) {
    // we already have what we need since we ask for everything...
    return;
  }

  IndexSchema schema = rb.req.getCore().getLatestSchema();
  for (SchemaField field : schema.getFields().values()) {
    if (! rf.wantsField(field.getName())) {
      continue;
    }
    for (String source : schema.getCopySources(field.getName())) {
      if (rf.wantsField(source)) {
        continue;
      }
      sreq.params.add(CommonParams.FL, source);
    }
  }
}
 
Example #24
Source File: ReSearcherRequestContext.java    From solr-researcher with Apache License 2.0 4 votes vote down vote up
public void setQueryOnlyComponents(List<SearchComponent> queryOnlyComponents) {
  this.queryOnlyComponents = queryOnlyComponents;
}
 
Example #25
Source File: MtasSolrSearchComponent.java    From mtas with Apache License 2.0 4 votes vote down vote up
@Override
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) {
	 // System.out
	 // .println(System.nanoTime() + " - " + Thread.currentThread().getId()
	 // + " - " + rb.req.getParams().getBool(ShardParams.IS_SHARD, false)
	 // + " MODIFY REQUEST " + rb.stage + " " + rb.req.getParamString());
	MtasSolrStatus solrStatus = Objects
			.requireNonNull((MtasSolrStatus) rb.req.getContext().get(MtasSolrStatus.class), "couldn't find status");
	solrStatus.setStage(rb.stage);
	try {
		if (sreq.params.getBool(PARAM_MTAS, false)) {
			if (sreq.params.getBool(MtasSolrComponentStatus.PARAM_MTAS_STATUS, false)) {
				searchStatus.modifyRequest(rb, who, sreq);
			} else if (requestHandler != null) {
				sreq.params.add(MtasSolrComponentStatus.PARAM_MTAS_STATUS, CommonParams.TRUE);
			}
			if (requestHandler != null) {
				sreq.params.add(MtasSolrComponentStatus.PARAM_MTAS_STATUS + "."
						+ MtasSolrComponentStatus.NAME_MTAS_STATUS_KEY, solrStatus.shardKey(rb.stage));
			}
			if (sreq.params.getBool(MtasSolrComponentVersion.PARAM_MTAS_VERSION, false)) {
				searchVersion.modifyRequest(rb, who, sreq);
			}
			if (sreq.params.getBool(MtasSolrComponentStats.PARAM_MTAS_STATS, false)) {
				searchStats.modifyRequest(rb, who, sreq);
			}
			if (sreq.params.getBool(MtasSolrComponentTermvector.PARAM_MTAS_TERMVECTOR, false)) {
				searchTermvector.modifyRequest(rb, who, sreq);
			}
			if (sreq.params.getBool(MtasSolrComponentPrefix.PARAM_MTAS_PREFIX, false)) {
				searchPrefix.modifyRequest(rb, who, sreq);
			}
			if (sreq.params.getBool(MtasSolrComponentFacet.PARAM_MTAS_FACET, false)) {
				searchFacet.modifyRequest(rb, who, sreq);
			}
			if (sreq.params.getBool(MtasSolrComponentCollection.PARAM_MTAS_COLLECTION, false)) {
				searchCollection.modifyRequest(rb, who, sreq);
			}
			if (sreq.params.getBool(MtasSolrComponentGroup.PARAM_MTAS_GROUP, false)) {
				searchGroup.modifyRequest(rb, who, sreq);
			}
			if (sreq.params.getBool(MtasSolrComponentList.PARAM_MTAS_LIST, false)) {
				searchList.modifyRequest(rb, who, sreq);
			}
			if (sreq.params.getBool(MtasSolrComponentDocument.PARAM_MTAS_DOCUMENT, false)) {
				searchDocument.modifyRequest(rb, who, sreq);
			}
			if (sreq.params.getBool(MtasSolrComponentKwic.PARAM_MTAS_KWIC, false)) {
				searchKwic.modifyRequest(rb, who, sreq);
			}
		}
	} catch (ExitableDirectoryReader.ExitingReaderException e) {
		solrStatus.setError(e.getMessage());
	}
}
 
Example #26
Source File: MtasSolrComponentStatus.java    From mtas with Apache License 2.0 4 votes vote down vote up
@Override
public void modifyRequest(ResponseBuilder rb, SearchComponent who,
    ShardRequest sreq) {
  sreq.params.remove(PARAM_MTAS_STATUS + "." + NAME_MTAS_STATUS_KEY);
}
 
Example #27
Source File: MtasSolrComponentVersion.java    From mtas with Apache License 2.0 4 votes vote down vote up
@Override
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) {
	// do nothing
}
 
Example #28
Source File: AbstractReSearcherComponent.java    From solr-researcher with Apache License 2.0 4 votes vote down vote up
public List<SearchComponent> getQueryOnlyComponents() {
  return queryOnlyComponents;
}
 
Example #29
Source File: ReSearcherRequestContext.java    From solr-researcher with Apache License 2.0 4 votes vote down vote up
public List<SearchComponent> getQueryOnlyComponents() {
  return queryOnlyComponents;
}
 
Example #30
Source File: SolrInfoBeanTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/**
 * Gets a list of everything we can find in the classpath and makes sure it has
 * a name, description, etc...
 */
@SuppressWarnings({"unchecked"})
public void testCallMBeanInfo() throws Exception {
  @SuppressWarnings({"rawtypes"})
  List<Class> classes = new ArrayList<>();
  classes.addAll(getClassesForPackage(SearchHandler.class.getPackage().getName()));
  classes.addAll(getClassesForPackage(SearchComponent.class.getPackage().getName()));
  classes.addAll(getClassesForPackage(LukeRequestHandler.class.getPackage().getName()));
  classes.addAll(getClassesForPackage(DefaultSolrHighlighter.class.getPackage().getName()));
  classes.addAll(getClassesForPackage(CaffeineCache.class.getPackage().getName()));
 // System.out.println(classes);
  
  int checked = 0;
  SolrMetricManager metricManager = h.getCoreContainer().getMetricManager();
  String registry = h.getCore().getCoreMetricManager().getRegistryName();
  SolrMetricsContext solrMetricsContext = new SolrMetricsContext(metricManager, registry, "foo");
  String scope = TestUtil.randomSimpleString(random(), 2, 10);
  for(@SuppressWarnings({"rawtypes"})Class clazz : classes ) {
    if( SolrInfoBean.class.isAssignableFrom( clazz ) ) {
      try {
        SolrInfoBean info = (SolrInfoBean)clazz.getConstructor().newInstance();
        if (info instanceof SolrMetricProducer) {
          ((SolrMetricProducer)info).initializeMetrics(solrMetricsContext, scope);
        }
        
        //System.out.println( info.getClass() );
        assertNotNull( info.getClass().getCanonicalName(), info.getName() );
        assertNotNull( info.getClass().getCanonicalName(), info.getDescription() );
        assertNotNull( info.getClass().getCanonicalName(), info.getCategory() );
        
        if( info instanceof CaffeineCache ) {
          continue;
        }
        
        assertNotNull( info.toString() );
        checked++;
      }
      catch( ReflectiveOperationException ex ) {
        // expected...
        //System.out.println( "unable to initialize: "+clazz );
      }
    }
  }
  assertTrue( "there are at least 10 SolrInfoBean that should be found in the classpath, found " + checked, checked > 10 );
}