org.apache.solr.highlight.DefaultSolrHighlighter Java Examples

The following examples show how to use org.apache.solr.highlight.DefaultSolrHighlighter. 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: HighlightComponent.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void inform(SolrCore core) {
  List<PluginInfo> children = info.getChildren("highlighting");
  if(children.isEmpty()) {
    DefaultSolrHighlighter defHighlighter = new DefaultSolrHighlighter(core);
    defHighlighter.init(PluginInfo.EMPTY_INFO);
    solrConfigHighlighter = defHighlighter;
  } else {
    solrConfigHighlighter = core.createInitInstance(children.get(0),SolrHighlighter.class,null, DefaultSolrHighlighter.class.getName());
  }

}
 
Example #2
Source File: HighlightComponent.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected SolrHighlighter getHighlighter(SolrParams params) {
  HighlightMethod method = HighlightMethod.parse(params.get(HighlightParams.METHOD));
  if (method == null) {
    return solrConfigHighlighter;
  }

  switch (method) {
    case UNIFIED:
      if (solrConfigHighlighter instanceof UnifiedSolrHighlighter) {
        return solrConfigHighlighter;
      }
      return new UnifiedSolrHighlighter(); // TODO cache one?
    case POSTINGS:
      if (solrConfigHighlighter instanceof PostingsSolrHighlighter) {
        return solrConfigHighlighter;
      }
      return new PostingsSolrHighlighter(); // TODO cache one?
    case FAST_VECTOR: // fall-through
    case ORIGINAL:
      if (solrConfigHighlighter instanceof DefaultSolrHighlighter) {
        return solrConfigHighlighter;
      } else {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
            "In order to use " + HighlightParams.METHOD + "=" + method.getMethodName() + " the configured" +
                " highlighter in solrconfig must be " + DefaultSolrHighlighter.class);
      }
    default: throw new AssertionError();
  }
}
 
Example #3
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 );
}