本文整理汇总了Java中org.apache.solr.handler.component.SearchComponent类的典型用法代码示例。如果您正苦于以下问题:Java SearchComponent类的具体用法?Java SearchComponent怎么用?Java SearchComponent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SearchComponent类属于org.apache.solr.handler.component包,在下文中一共展示了SearchComponent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadSearchComponents
import org.apache.solr.handler.component.SearchComponent; //导入依赖的package包/类
/**
* Register the default search components
*/
private Map<String, SearchComponent> loadSearchComponents()
{
Map<String, SearchComponent> components = new HashMap<>();
initPlugins(components,SearchComponent.class);
for (Map.Entry<String, SearchComponent> e : components.entrySet()) {
SearchComponent c = e.getValue();
if (c instanceof HighlightComponent) {
HighlightComponent hl = (HighlightComponent) c;
if(!HighlightComponent.COMPONENT_NAME.equals(e.getKey())){
components.put(HighlightComponent.COMPONENT_NAME,hl);
}
break;
}
}
addIfNotPresent(components,HighlightComponent.COMPONENT_NAME,HighlightComponent.class);
addIfNotPresent(components,QueryComponent.COMPONENT_NAME,QueryComponent.class);
addIfNotPresent(components,FacetComponent.COMPONENT_NAME,FacetComponent.class);
addIfNotPresent(components,MoreLikeThisComponent.COMPONENT_NAME,MoreLikeThisComponent.class);
addIfNotPresent(components,StatsComponent.COMPONENT_NAME,StatsComponent.class);
addIfNotPresent(components,DebugComponent.COMPONENT_NAME,DebugComponent.class);
addIfNotPresent(components,RealTimeGetComponent.COMPONENT_NAME,RealTimeGetComponent.class);
addIfNotPresent(components,ExpandComponent.COMPONENT_NAME,ExpandComponent.class);
return components;
}
示例2: loadSearchComponents
import org.apache.solr.handler.component.SearchComponent; //导入依赖的package包/类
/**
* Register the default search components
*/
private Map<String, SearchComponent> loadSearchComponents()
{
Map<String, SearchComponent> components = new HashMap<String, SearchComponent>();
initPlugins(components,SearchComponent.class);
for (Map.Entry<String, SearchComponent> e : components.entrySet()) {
SearchComponent c = e.getValue();
if (c instanceof HighlightComponent) {
HighlightComponent hl = (HighlightComponent) c;
if(!HighlightComponent.COMPONENT_NAME.equals(e.getKey())){
components.put(HighlightComponent.COMPONENT_NAME,hl);
}
break;
}
}
addIfNotPresent(components,HighlightComponent.COMPONENT_NAME,HighlightComponent.class);
addIfNotPresent(components,QueryComponent.COMPONENT_NAME,QueryComponent.class);
addIfNotPresent(components,FacetComponent.COMPONENT_NAME,FacetComponent.class);
addIfNotPresent(components,MoreLikeThisComponent.COMPONENT_NAME,MoreLikeThisComponent.class);
addIfNotPresent(components,StatsComponent.COMPONENT_NAME,StatsComponent.class);
addIfNotPresent(components,DebugComponent.COMPONENT_NAME,DebugComponent.class);
addIfNotPresent(components,RealTimeGetComponent.COMPONENT_NAME,RealTimeGetComponent.class);
return components;
}
示例3: loadSearchComponents
import org.apache.solr.handler.component.SearchComponent; //导入依赖的package包/类
/**
* Register the default search components
*/
private Map<String, SearchComponent> loadSearchComponents() {
Map<String, SearchComponent> components = new HashMap<String, SearchComponent>();
initPlugins(components, SearchComponent.class);
for(Map.Entry<String, SearchComponent> e : components.entrySet()) {
SearchComponent c = e.getValue();
if(c instanceof HighlightComponent) {
HighlightComponent hl = (HighlightComponent) c;
if(!HighlightComponent.COMPONENT_NAME.equals(e.getKey())) {
components.put(HighlightComponent.COMPONENT_NAME, hl);
}
break;
}
}
addIfNotPresent(components, HighlightComponent.COMPONENT_NAME, HighlightComponent.class);
addIfNotPresent(components, QueryComponent.COMPONENT_NAME, QueryComponent.class);
addIfNotPresent(components, FacetComponent.COMPONENT_NAME, FacetComponent.class);
addIfNotPresent(components, MoreLikeThisComponent.COMPONENT_NAME, MoreLikeThisComponent.class);
addIfNotPresent(components, StatsComponent.COMPONENT_NAME, StatsComponent.class);
addIfNotPresent(components, DebugComponent.COMPONENT_NAME, DebugComponent.class);
addIfNotPresent(components, RealTimeGetComponent.COMPONENT_NAME, RealTimeGetComponent.class);
return components;
}
示例4: test
import org.apache.solr.handler.component.SearchComponent; //导入依赖的package包/类
@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();
}
示例5: modifyRequest
import org.apache.solr.handler.component.SearchComponent; //导入依赖的package包/类
@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);
}
}
示例6: modifyRequest
import org.apache.solr.handler.component.SearchComponent; //导入依赖的package包/类
@Override
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) {
if (!checkComponentShouldProcess(rb)) {
return;
}
sreq.params.set(getComponentName(), "false");
}
示例7: modifyRequest
import org.apache.solr.handler.component.SearchComponent; //导入依赖的package包/类
@Override
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) {
SolrParams params = rb.req.getParams();
if (!params.getBool(COMPONENT_NAME, false) || !params.getBool(ClusteringParams.USE_SEARCH_RESULTS, false)) {
return;
}
sreq.params.remove(COMPONENT_NAME);
if( ( sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS ) != 0 ){
String fl = sreq.params.get(CommonParams.FL,"*");
// if fl=* then we don't need check
if( fl.indexOf( '*' ) >= 0 ) return;
Set<String> fields = getSearchClusteringEngine(rb).getFieldsToLoad(rb.req);
if( fields == null || fields.size() == 0 ) return;
StringBuilder sb = new StringBuilder();
String[] flparams = fl.split( "[,\\s]+" );
Set<String> flParamSet = new HashSet<>(flparams.length);
for( String flparam : flparams ){
// no need trim() because of split() by \s+
flParamSet.add(flparam);
}
for( String aFieldToLoad : fields ){
if( !flParamSet.contains( aFieldToLoad ) ){
sb.append( ',' ).append( aFieldToLoad );
}
}
if( sb.length() > 0 ){
sreq.params.set( CommonParams.FL, fl + sb.toString() );
}
}
}
示例8: createInitInstance
import org.apache.solr.handler.component.SearchComponent; //导入依赖的package包/类
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);
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;
}
示例9: addIfNotPresent
import org.apache.solr.handler.component.SearchComponent; //导入依赖的package包/类
private <T> void addIfNotPresent(Map<String ,T> registry, String name, Class<? extends T> c){
if(!registry.containsKey(name)){
T searchComp = resourceLoader.newInstance(c.getName(), c);
if (searchComp instanceof NamedListInitializedPlugin){
((NamedListInitializedPlugin)searchComp).init( new NamedList<String>() );
}
if(searchComp instanceof SearchComponent) {
((SearchComponent)searchComp).setName(name);
}
registry.put(name, searchComp);
if (searchComp instanceof SolrInfoMBean){
infoRegistry.put(((SolrInfoMBean)searchComp).getName(), (SolrInfoMBean)searchComp);
}
}
}
示例10: getSearchComponent
import org.apache.solr.handler.component.SearchComponent; //导入依赖的package包/类
/**
* @return a Search Component registered to a given name. Throw an exception if the component is undefined
*/
public SearchComponent getSearchComponent( String name )
{
SearchComponent component = searchComponents.get( name );
if( component == null ) {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
"Unknown Search Component: "+name );
}
return component;
}
示例11: testCallMBeanInfo
import org.apache.solr.handler.component.SearchComponent; //导入依赖的package包/类
/**
* Gets a list of everything we can find in the classpath and makes sure it has
* a name, description, etc...
*/
public void testCallMBeanInfo() throws Exception {
List<Class> classes = new ArrayList<>();
classes.addAll(getClassesForPackage(StandardRequestHandler.class.getPackage().getName()));
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(LRUCache.class.getPackage().getName()));
// System.out.println(classes);
int checked = 0;
for( Class clazz : classes ) {
if( SolrInfoMBean.class.isAssignableFrom( clazz ) ) {
try {
SolrInfoMBean info = (SolrInfoMBean)clazz.newInstance();
//System.out.println( info.getClass() );
assertNotNull( info.getName() );
assertNotNull( info.getDescription() );
assertNotNull( info.getCategory() );
if( info instanceof LRUCache ) {
continue;
}
assertNotNull( info.toString() );
// increase code coverage...
assertNotNull( info.getDocs() + "" );
assertNotNull( info.getStatistics()+"" );
checked++;
}
catch( InstantiationException ex ) {
// expected...
//System.out.println( "unable to initalize: "+clazz );
}
}
}
assertTrue( "there are at least 10 SolrInfoMBean that should be found in the classpath, found " + checked, checked > 10 );
}
示例12: testCollateWithFilter
import org.apache.solr.handler.component.SearchComponent; //导入依赖的package包/类
@Test
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.add("responseHeader", 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 suggestions = (NamedList) spellCheck.get("suggestions");
List<String> collations = suggestions.getAll("collation");
assertTrue(collations.size() > 0);
for(String collation : collations) {
assertTrue(!collation.equals("lowerfilt:(+faith +hope +loaves)"));
}
}
示例13: testCollateWithGrouping
import org.apache.solr.handler.component.SearchComponent; //导入依赖的package包/类
@Test
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.add("responseHeader", 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 suggestions = (NamedList) spellCheck.get("suggestions");
List<String> collations = suggestions.getAll("collation");
assertTrue(collations.size() == 1);
}
示例14: testZeroTries
import org.apache.solr.handler.component.SearchComponent; //导入依赖的package包/类
@Test
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.add("responseHeader", 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 suggestions = (NamedList) spellCheck.get("suggestions");
List<String> collations = suggestions.getAll("collation");
assertTrue(collations.size() == 2);
}
示例15: modifyRequest
import org.apache.solr.handler.component.SearchComponent; //导入依赖的package包/类
@Override
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) {
SolrParams params = rb.req.getParams();
if (!params.getBool(COMPONENT_NAME, false) || !params.getBool(ClusteringParams.USE_SEARCH_RESULTS, false)) {
return;
}
sreq.params.remove(COMPONENT_NAME);
if( ( sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS ) != 0 ){
String fl = sreq.params.get(CommonParams.FL,"*");
// if fl=* then we don't need check
if( fl.indexOf( '*' ) >= 0 ) return;
Set<String> fields = getSearchClusteringEngine(rb).getFieldsToLoad(rb.req);
if( fields == null || fields.size() == 0 ) return;
StringBuilder sb = new StringBuilder();
String[] flparams = fl.split( "[,\\s]+" );
Set<String> flParamSet = new HashSet<String>(flparams.length);
for( String flparam : flparams ){
// no need trim() because of split() by \s+
flParamSet.add(flparam);
}
for( String aFieldToLoad : fields ){
if( !flParamSet.contains( aFieldToLoad ) ){
sb.append( ',' ).append( aFieldToLoad );
}
}
if( sb.length() > 0 ){
sreq.params.set( CommonParams.FL, fl + sb.toString() );
}
}
}