org.apache.solr.common.params.HighlightParams Java Examples

The following examples show how to use org.apache.solr.common.params.HighlightParams. 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: UnifiedSolrHighlighter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public SolrExtendedUnifiedHighlighter(SolrQueryRequest req) {
  super(req.getSearcher(), req.getSchema().getIndexAnalyzer());
  this.params = req.getParams();
  this.schema = req.getSchema();
  this.setMaxLength(
      params.getInt(HighlightParams.MAX_CHARS, DEFAULT_MAX_CHARS));
  this.setCacheFieldValCharsThreshold(
      params.getInt(HighlightParams.CACHE_FIELD_VAL_CHARS_THRESHOLD, DEFAULT_CACHE_CHARS_THRESHOLD));

  final RTimerTree timerTree;
  if (req.getRequestTimer() != null) { //It may be null if not used in a search context.
    timerTree = req.getRequestTimer();
  } else {
    timerTree = new RTimerTree(); // since null checks are annoying
  }
  loadFieldValuesTimer = timerTree.sub("loadFieldValues"); // we assume a new timer, state of STARTED
  loadFieldValuesTimer.pause(); // state of PAUSED now with about zero time. Will fail if state isn't STARTED.
}
 
Example #2
Source File: AlfrescoHighlighterIT.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void highlightingPrePostTest()
{
    SolrServletRequest req = areq(params( "q", "name:long", "qt", "/afts", "start", "0", "rows", "5",
            HighlightParams.HIGHLIGHT, "true",
            HighlightParams.Q, "long",
            HighlightParams.FIELDS, "content,name,title",
            HighlightParams.SIMPLE_PRE, "<al>",
            HighlightParams.SIMPLE_POST, "<fresco>",
            HighlightParams.SNIPPETS, String.valueOf(4),
            HighlightParams.FRAGSIZE, String.valueOf(40)),
            "{\"locales\":[\"en\"], \"tenants\": [ \"\" ]}");

    assertQ(req,
            "*[count(//lst[@name='highlighting']/lst)=2]",
            "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.='some very <al>long<fresco> name']",
            "//lst[@name='highlighting']/lst[1]/arr[@name='title']/str[.='title1 is very <al>long<fresco>']",
            "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.='this is some <al>long<fresco> text.  It has the']",
            "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.=' word <al>long<fresco> in many places.  In fact, it has']",
            "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.=' <al>long<fresco> on some different fragments.  Let us']",
            "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.=' see what happens to <al>long<fresco> in this case.']");
}
 
Example #3
Source File: TestDymReSearcher.java    From solr-researcher with Apache License 2.0 6 votes vote down vote up
@Test
public void testFacetAndHighlightWithCommonMisspellings() {
  assertQ(req(CommonParams.QT, "standardResWithCommonMisspellings", 
      CommonParams.Q, "foo:bobo AND foo:marley",
      SpellingParams.SPELLCHECK_COLLATE, "true", 
      SpellingParams.SPELLCHECK_BUILD, "true", 
      SpellingParams.SPELLCHECK_COUNT, "10", 
      SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true",
      FacetParams.FACET, "true", 
      FacetParams.FACET_FIELD, "foo", 
      FacetParams.FACET_FIELD, "id",
      FacetParams.FACET_FIELD, "bar", 
      FacetParams.FACET_QUERY, "id:[0 TO 20]", 
      FacetParams.FACET_QUERY, "id:[1 TO 100]",
      HighlightParams.HIGHLIGHT, "true", 
      HighlightParams.FIELDS, "foo",
      DymReSearcher.COMPONENT_NAME, "true",
      SpellCheckComponent.COMPONENT_NAME, "true")
      ,"//result[@name='spellchecked_response'][@numFound='3']"
      ,"//result[@name='response'][@numFound='0']"
      ,"//arr[@name='extended_spellchecker_suggestions']/str[1][.='foo:bono AND foo:marley']"
      ,"//lst[@name='spellchecked_facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='bob'][.='3']"
      ,"//lst[@name='spellchecked_facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='marley'][.='3']"
      ,"//lst[@name='spellchecked_highlighting']/lst[@name='9']/arr[@name='foo']/str[1]"
      );
}
 
Example #4
Source File: AlfrescoHighlighterIT.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void highlightingMergeContinuousFragmentsTest()
{
    SolrServletRequest req = areq(params( "q", "name:long", "qt", "/afts", "start", "0", "rows", "5",
            HighlightParams.HIGHLIGHT, "true",
            HighlightParams.Q, "'some long'",
            HighlightParams.FIELDS, "name",
            HighlightParams.MERGE_CONTIGUOUS_FRAGMENTS, "true",
            HighlightParams.SIMPLE_PRE, "{",
            HighlightParams.SIMPLE_POST, "}",
            HighlightParams.SNIPPETS, String.valueOf(4),
            HighlightParams.FRAGSIZE, String.valueOf(40)),
            "{\"locales\":[\"en\"], \"tenants\": [ \"\" ]}");

    assertQ(req,
            "*[count(//lst[@name='highlighting']/lst/arr)=1]",
            "//lst[@name='highlighting']/lst/arr[@name='name']/str[.='this is {some} {long} text.  It has the word long in many places.  In fact, it has long on some different fragments.  Let us see what happens to long in this case.']"
    );
}
 
Example #5
Source File: AlfrescoHighlighterIT.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void highlightingPluralsTest()
{
    SolrServletRequest req = areq(params( "q", "name:plural", "qt", "/afts", "start", "0", "rows", "5",
            HighlightParams.HIGHLIGHT, "true",
            //HighlightParams.Q, "lon*",
            HighlightParams.FIELDS, "name",
            HighlightParams.HIGHLIGHT_MULTI_TERM, "false",
            HighlightParams.SIMPLE_PRE, "{",
            HighlightParams.SIMPLE_POST, "}",
            HighlightParams.SNIPPETS, String.valueOf(1),
            HighlightParams.FRAGSIZE, String.valueOf(100)),
            "{\"locales\":[\"en\"], \"tenants\": [ \"\" ]}");

    assertQ(req,
            "*[count(//lst[@name='highlighting']/lst)=1]",
            "*[count(//lst[@name='highlighting']/lst/arr[@name='name'])=1]",
            "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.='MixedCabbageString and {plurals} and discussion']");
}
 
Example #6
Source File: AlfrescoHighlighterIT.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void highlightingStemmingTest()
{
    SolrServletRequest req = areq(params( "q", "name:discuss", "qt", "/afts", "start", "0", "rows", "5",
            HighlightParams.HIGHLIGHT, "true",
            //HighlightParams.Q, "lon*",
            HighlightParams.FIELDS, "name",
            HighlightParams.HIGHLIGHT_MULTI_TERM, "false",
            HighlightParams.SIMPLE_PRE, "{",
            HighlightParams.SIMPLE_POST, "}",
            HighlightParams.SNIPPETS, String.valueOf(1),
            HighlightParams.FRAGSIZE, String.valueOf(100)),
            "{\"locales\":[\"en\"], \"tenants\": [ \"\" ]}");

    assertQ(req,
            "*[count(//lst[@name='highlighting']/lst)=1]",
            "*[count(//lst[@name='highlighting']/lst/arr[@name='name'])=1]",
            "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.='MixedCabbageString and plurals and {discussion}']");
}
 
Example #7
Source File: AlfrescoHighlighterIT.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void highlightingSnippetsFragSizeTest()
{
    SolrServletRequest req = areq(params( "q", "name:long", "qt", "/afts", "start", "0", "rows", "5",
            HighlightParams.HIGHLIGHT, "true",
            HighlightParams.Q, "long",
            HighlightParams.FIELDS, "content,name,title",
            HighlightParams.SNIPPETS, "4",
            HighlightParams.FRAGSIZE, "40"),
            "{\"locales\":[\"en\"], \"tenants\": [ \"\" ]}");

    assertQ(req,
            "*[count(//lst[@name='highlighting']/lst)=2]",
            "//lst[@name='highlighting']/lst[1]/arr[@name='name']/str[.='some very <em>long</em> name']",
            "//lst[@name='highlighting']/lst[1]/arr[@name='title']/str[.='title1 is very <em>long</em>']",
            "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.='this is some <em>long</em> text.  It has the']",
            "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.=' word <em>long</em> in many places.  In fact, it has']",
            "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.=' <em>long</em> on some different fragments.  Let us']",
            "//lst[@name='highlighting']/lst[2]/arr[@name='name']/str[.=' see what happens to <em>long</em> in this case.']");
}
 
Example #8
Source File: RegexFragmenter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public Fragmenter getFragmenter(String fieldName, SolrParams params )
{ 
  numRequests.inc();
  params = SolrParams.wrapDefaults(params, defaults);

  int fragsize  = params.getFieldInt(   fieldName, HighlightParams.FRAGSIZE,  LuceneRegexFragmenter.DEFAULT_FRAGMENT_SIZE );
  int increment = params.getFieldInt(   fieldName, HighlightParams.INCREMENT, LuceneRegexFragmenter.DEFAULT_INCREMENT_GAP );
  float slop    = params.getFieldFloat( fieldName, HighlightParams.SLOP,      LuceneRegexFragmenter.DEFAULT_SLOP );
  int maxchars  = params.getFieldInt(   fieldName, HighlightParams.MAX_RE_CHARS, LuceneRegexFragmenter.DEFAULT_MAX_ANALYZED_CHARS );
  String rawpat = params.getFieldParam( fieldName, HighlightParams.PATTERN,   LuceneRegexFragmenter.DEFAULT_PATTERN_RAW );

  Pattern p = rawpat == defaultPatternRaw ? defaultPattern : Pattern.compile(rawpat);

  if( fragsize <= 0 ) {
    return new NullFragmenter();
  }
  
  return new LuceneRegexFragmenter( fragsize, increment, slop, maxchars, p );
}
 
Example #9
Source File: AlfrescoHighlighterIT.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void highlightingBooleanConjunctionTest()
{
    SolrServletRequest req = areq(params( "q", "title:(is AND long)", "qt", "/afts", "start", "0", "rows", "5",
            HighlightParams.HIGHLIGHT, "true",
            HighlightParams.FIELDS, "title",
            HighlightParams.HIGHLIGHT_MULTI_TERM, "false",
            HighlightParams.SIMPLE_PRE, "{",
            HighlightParams.SIMPLE_POST, "}"),
            "{\"locales\":[\"en\"], \"tenants\": [ \"\" ]}");

    assertQ(req,
            "*[count(//lst[@name='highlighting']/lst)=1]",
            "*[count(//lst[@name='highlighting']/lst/arr[@name='title'])=1]",
            "//lst[@name='highlighting']/lst[1]/arr[@name='title']/str[.='title1 {is} very {long}']");
}
 
Example #10
Source File: DefaultQuerqyDismaxQParserTest.java    From querqy with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatHighlightingIsNotAppliedToBoostQuery() {
    SolrQueryRequest req = req("q", "o",
            DisMaxParams.QF, "f1",
            HighlightParams.HIGHLIGHT, "true",
            HighlightParams.FIELDS, "f1",
            HighlightParams.SIMPLE_PRE, "PRE",
            HighlightParams.SIMPLE_POST, "POST",
            "defType", "querqy",
            "debugQuery", "true");

    assertQ("UP token is highlighted",
            req,
            "//lst[@name='highlighting']//arr[@name='f1']/str[not(contains(.,'PREuPOST'))]"
    );
    req.close();

}
 
Example #11
Source File: DefaultSolrHighlighter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Return a {@link org.apache.lucene.search.highlight.QueryScorer} suitable for this Query and field.
 *
 * @param query       The current query
 * @param tokenStream document text tokenStream that implements reset() efficiently (e.g. CachingTokenFilter).
 *                    If it's used, call reset() first.
 * @param fieldName   The name of the field
 * @param request     The SolrQueryRequest
 */
protected QueryScorer getSpanQueryScorer(Query query, String fieldName, TokenStream tokenStream, SolrQueryRequest request) {
  QueryScorer scorer = new QueryScorer(query,
          request.getParams().getFieldBool(fieldName, HighlightParams.FIELD_MATCH, false) ? fieldName : null) {
    @Override
    protected WeightedSpanTermExtractor newTermExtractor(String defaultField) {
      return new CustomSpanTermExtractor(defaultField);
    }
  };
  scorer.setExpandMultiTermQuery(request.getParams().getBool(HighlightParams.HIGHLIGHT_MULTI_TERM, true));

  boolean defaultPayloads = true;//overwritten below
  try {
    // It'd be nice to know if payloads are on the tokenStream but the presence of the attribute isn't a good
    // indicator.
    final Terms terms = request.getSearcher().getSlowAtomicReader().terms(fieldName);
    if (terms != null) {
      defaultPayloads = terms.hasPayloads();
    }
  } catch (IOException e) {
    log.error("Couldn't check for existence of payloads", e);
  }
  scorer.setUsePayloads(request.getParams().getFieldBool(fieldName, HighlightParams.PAYLOADS, defaultPayloads));
  return scorer;
}
 
Example #12
Source File: TestDymReSearcher.java    From solr-researcher with Apache License 2.0 6 votes vote down vote up
@Test
public void testFacetAndHighlight() {
  assertQ(req(CommonParams.QT, "standardGoodSuggestion", 
      CommonParams.Q, "foo:bobo AND foo:marley",
      SpellingParams.SPELLCHECK_COLLATE, "true", 
      SpellingParams.SPELLCHECK_BUILD, "true", 
      SpellingParams.SPELLCHECK_COUNT, "10", 
      SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true",
      FacetParams.FACET, "true", 
      FacetParams.FACET_FIELD, "foo", 
      FacetParams.FACET_FIELD, "id", 
      FacetParams.FACET_FIELD, "bar", 
      FacetParams.FACET_QUERY, "id:[0 TO 20]", 
      FacetParams.FACET_QUERY, "id:[1 TO 100]", 
      HighlightParams.HIGHLIGHT, "true", 
      HighlightParams.FIELDS, "foo",
      DymReSearcher.COMPONENT_NAME, "true",
      SpellCheckComponent.COMPONENT_NAME, "true")
      ,"//result[@name='spellchecked_response'][@numFound='7']"
      ,"//result[@name='response'][@numFound='0']"
      ,"//arr[@name='extended_spellchecker_suggestions']/str[1][.='foo:bob AND foo:marley']"
      ,"//lst[@name='spellchecked_facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='bob'][.='7']"
      ,"//lst[@name='spellchecked_facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='marley'][.='7']"
      ,"//lst[@name='spellchecked_highlighting']/lst[@name='2']/arr[@name='foo']/str[1]");
}
 
Example #13
Source File: DefaultQuerqyDismaxQParserTest.java    From querqy with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatHighlightingIsApplied() {
    SolrQueryRequest req = req("q", "a",
            DisMaxParams.QF, "f1",
            HighlightParams.HIGHLIGHT, "true",
            HighlightParams.FIELDS, "f1",
            HighlightParams.SIMPLE_PRE, "PRE",
            HighlightParams.SIMPLE_POST, "POST",
            "defType", "querqy",
            "debugQuery", "true");

    assertQ("Highlighting not working",
            req,
            "//lst[@name='highlighting']//arr[@name='f1']/str[text()='PREaPOST']"
    );
    req.close();

}
 
Example #14
Source File: DefaultQuerqyDismaxQParserTest.java    From querqy with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatHighlightingIsAppliedToSynonyms() {
    SolrQueryRequest req = req("q", "o",
            DisMaxParams.QF, "f1",
            HighlightParams.HIGHLIGHT, "true",
            HighlightParams.FIELDS, "f1",
            HighlightParams.SIMPLE_PRE, "PRE",
            HighlightParams.SIMPLE_POST, "POST",
            "defType", "querqy",
            "debugQuery", "true");

    assertQ("UP token is highlighted",
            req,
            "//lst[@name='highlighting']//arr[@name='f1']/str[contains(.,'PREsPOST')]"
    );
    req.close();

}
 
Example #15
Source File: UnifiedSolrHighlighter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public NamedList<Object> doHighlighting(DocList docs, Query query, SolrQueryRequest req, String[] defaultFields) throws IOException {
  final SolrParams params = req.getParams();

  // if highlighting isn't enabled, then why call doHighlighting?
  if (!isHighlightingEnabled(params))
    return null;

  int[] docIDs = toDocIDs(docs);

  // fetch the unique keys
  String[] keys = getUniqueKeys(req.getSearcher(), docIDs);

  // query-time parameters
  String[] fieldNames = getHighlightFields(query, req, defaultFields);

  int maxPassages[] = new int[fieldNames.length];
  for (int i = 0; i < fieldNames.length; i++) {
    maxPassages[i] = params.getFieldInt(fieldNames[i], HighlightParams.SNIPPETS, 1);
  }

  UnifiedHighlighter highlighter = getHighlighter(req);
  Map<String, String[]> snippets = highlighter.highlightFields(fieldNames, query, docIDs, maxPassages);
  return encodeSnippets(keys, fieldNames, snippets);
}
 
Example #16
Source File: HighlightComponent.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare(ResponseBuilder rb) throws IOException {
  SolrParams params = rb.req.getParams();
  rb.doHighlights = solrConfigHighlighter.isHighlightingEnabled(params);
  if(rb.doHighlights){
    rb.setNeedDocList(true);
    String hlq = params.get(HighlightParams.Q);
    String hlparser = MoreObjects.firstNonNull(params.get(HighlightParams.QPARSER),
                                            params.get(QueryParsing.DEFTYPE, QParserPlugin.DEFAULT_QTYPE));
    if(hlq != null){
      try {
        QParser parser = QParser.getParser(hlq, hlparser, rb.req);
        rb.setHighlightQuery(parser.getHighlightQuery());
      } catch (SyntaxError e) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
      }
    }
  }
}
 
Example #17
Source File: PostingsSolrHighlighter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
protected UnifiedHighlighter getHighlighter(SolrQueryRequest req) {
  // Adjust the highlight parameters to match what the old PostingsHighlighter had.
  ModifiableSolrParams invariants = new ModifiableSolrParams();
  invariants.set(HighlightParams.OFFSET_SOURCE, "POSTINGS");
  invariants.set(HighlightParams.FIELD_MATCH, true);
  invariants.set(HighlightParams.USE_PHRASE_HIGHLIGHTER, false);
  invariants.set(HighlightParams.FRAGSIZE, -1);

  ModifiableSolrParams defaults = new ModifiableSolrParams();
  defaults.set(HighlightParams.DEFAULT_SUMMARY, true);
  defaults.set(HighlightParams.TAG_ELLIPSIS, "... ");

  SolrParams newParams = SolrParams.wrapDefaults(
      invariants,// this takes precedence
      SolrParams.wrapDefaults(
          req.getParams(), // then this (original)
          defaults // finally our defaults
      )
  );
  try (LocalSolrQueryRequest fakeReq = new LocalSolrQueryRequest(req.getCore(), newParams)) {
    return super.getHighlighter(fakeReq);
  }
}
 
Example #18
Source File: DefaultSolrHighlighter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/** Highlights and returns the highlight object for this field -- a String[] by default.  Null if none. */
@SuppressWarnings("unchecked")
protected Object doHighlightingByFastVectorHighlighter(SolrDocument doc, int docId,
                                                       SchemaField schemaField, FvhContainer fvhContainer,
                                                       IndexReader reader, SolrQueryRequest req) throws IOException {
  SolrParams params = req.getParams();
  String fieldName = schemaField.getName();
  SolrFragmentsBuilder solrFb = getSolrFragmentsBuilder(fieldName, params);

  String[] snippets = fvhContainer.fvh.getBestFragments(fvhContainer.fieldQuery, reader, docId, fieldName,
          params.getFieldInt(fieldName, HighlightParams.FRAGSIZE, 100),
          params.getFieldInt(fieldName, HighlightParams.SNIPPETS, 1),
          getFragListBuilder(fieldName, params),
          getFragmentsBuilder(fieldName, params),
          solrFb.getPreTags(params, fieldName),
          solrFb.getPostTags(params, fieldName),
          getEncoder(fieldName, params));
  if (snippets != null && snippets.length > 0)
    return snippets;
  return null;
}
 
Example #19
Source File: AbstractSolrQuery.java    From dubbox with Apache License 2.0 6 votes vote down vote up
private void appendHighlightFormatOptions(HighlightOptions options, SolrQueryMethod queryMethod) {
	String formatter = queryMethod.getHighlightFormatter();
	if (formatter != null) {
		options.setFormatter(formatter);
	}
	String highlightPrefix = queryMethod.getHighlightPrefix();
	if (highlightPrefix != null) {
		if (isSimpleHighlightingOption(formatter)) {
			options.setSimplePrefix(highlightPrefix);
		} else {
			options.addHighlightParameter(new HighlightParameter(HighlightParams.TAG_PRE, highlightPrefix));
		}
	}
	String highlightPostfix = queryMethod.getHighlightPostfix();
	if (highlightPostfix != null) {
		if (isSimpleHighlightingOption(formatter)) {
			options.setSimplePostfix(highlightPostfix);
		} else {
			options.addHighlightParameter(new HighlightParameter(HighlightParams.TAG_POST, highlightPostfix));
		}
	}
}
 
Example #20
Source File: HighlightComponent.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) {
  if (!rb.doHighlights) return;

  // Turn on highlighting only only when retrieving fields
  if ((sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) != 0) {
      sreq.purpose |= ShardRequest.PURPOSE_GET_HIGHLIGHTS;
      // should already be true...
      sreq.params.set(HighlightParams.HIGHLIGHT, "true");      
  } else {
    sreq.params.set(HighlightParams.HIGHLIGHT, "false");      
  }
}
 
Example #21
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 #22
Source File: UnifiedSolrHighlighter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * parse custom separator char for {@link CustomSeparatorBreakIterator}
 */
protected char parseBiSepChar(String sepChar) {
  if (sepChar == null) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, HighlightParams.BS_SEP + " not passed");
  }
  if (sepChar.length() != 1) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, HighlightParams.BS_SEP +
        " must be a single char but got: '" + sepChar + "'");
  }
  return sepChar.charAt(0);
}
 
Example #23
Source File: SolrFragmentsBuilder.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected char getMultiValuedSeparatorChar( SolrParams params ){
  String separator = params.get( HighlightParams.MULTI_VALUED_SEPARATOR, " " );
  if( separator.length() > 1 ){
    throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
        HighlightParams.MULTI_VALUED_SEPARATOR + " parameter must be a char, but is \"" + separator + "\"" );
  }
  return separator.charAt( 0 );
}
 
Example #24
Source File: TestQueryRelaxerComponent.java    From solr-researcher with Apache License 2.0 5 votes vote down vote up
@Test
public void testHighlighting() {
  assertQ(req(CommonParams.QT, "dismax_relaxer", CommonParams.Q, "bobo marley ",
      QueryRelaxerComponent.COMPONENT_NAME, "true", HighlightParams.HIGHLIGHT, "true", HighlightParams.FIELDS, "foo")
            ,"//result[@name='response'][@numFound='0']"
            ,"//arr[@name='relaxer_suggestions']/lst[1]/str[@name='relaxedQuery'][.='marley']"
            ,"//arr[@name='relaxer_suggestions']/lst[1]/str[@name='relaxedType'][.='query']"
            ,"//arr[@name='relaxer_suggestions']/lst[1]/lst[@name='relaxer_highlighting']/lst[@name='2']/arr[@name='foo']/str[1]"
          );
}
 
Example #25
Source File: SolrQuery.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public SolrQuery setHighlight(boolean b) {
  if (b) {
    this.set(HighlightParams.HIGHLIGHT, true);
  } else {
    this.remove(HighlightParams.HIGHLIGHT);
    this.remove(HighlightParams.FIELD_MATCH);
    this.remove(HighlightParams.FIELDS);
    this.remove(HighlightParams.FORMATTER);
    this.remove(HighlightParams.FRAGSIZE);
    this.remove(HighlightParams.SIMPLE_POST);
    this.remove(HighlightParams.SIMPLE_PRE);
    this.remove(HighlightParams.SNIPPETS);
  }
  return this;
}
 
Example #26
Source File: UnifiedSolrHighlighter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected OffsetSource getOffsetSource(String field) {
  String sourceStr = params.getFieldParam(field, HighlightParams.OFFSET_SOURCE);
  if (sourceStr != null) {
    return OffsetSource.valueOf(sourceStr.toUpperCase(Locale.ROOT));
  } else {
    return super.getOffsetSource(field);
  }
}
 
Example #27
Source File: SolrQuery.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** remove a field for highlighting
 * 
 * @param f field name to not highlight
 * @return <i>true</i>, if removed, <br> <i>false</i>, otherwise
 */
public boolean removeHighlightField(String f) {
  boolean b = this.remove(HighlightParams.FIELDS, f);
  if (this.get(HighlightParams.FIELDS) == null) {
    this.setHighlight(false);
  }
  return b;
}
 
Example #28
Source File: AlfrescoHighlighterIT.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void highlightingPhraseQueriesTest()
{
    //Phrase hightling is on by default
    SolrServletRequest req = areq(params( "q", "name:long", "qt", "/afts", "start", "0", "rows", "5",
            HighlightParams.HIGHLIGHT, "true",
            HighlightParams.Q, "\"some long\"",
            HighlightParams.FIELDS, "name",
            HighlightParams.SIMPLE_PRE, "(",
            HighlightParams.SIMPLE_POST, ")",
            HighlightParams.SNIPPETS, String.valueOf(1),
            HighlightParams.FRAGSIZE, String.valueOf(100)),
            "{\"locales\":[\"en\"], \"tenants\": [ \"\" ]}");

    assertQ(req,
            "//lst[@name='highlighting']/lst/arr/str[.='this is (some) (long) text.  It has the word long in many places.  In fact, it has long on some']");

    req = areq(params( "q", "name:long", "qt", "/afts", "start", "0", "rows", "5",
            HighlightParams.HIGHLIGHT, "true",
            HighlightParams.Q, "\"some long\"",
            HighlightParams.FIELDS, "name",
            HighlightParams.USE_PHRASE_HIGHLIGHTER, "false",
            HighlightParams.SIMPLE_PRE, "(",
            HighlightParams.SIMPLE_POST, ")",
            HighlightParams.SNIPPETS, String.valueOf(1),
            HighlightParams.FRAGSIZE, String.valueOf(100)),
            "{\"locales\":[\"en\"], \"tenants\": [ \"\" ]}");

    assertQ(req,
            "//lst[@name='highlighting']/lst/arr/str[.='(some) very (long) name']",
            "//lst[@name='highlighting']/lst/arr/str[.='this is (some) (long) text.  It has the word (long) in many places.  In fact, it has (long) on (some)']");
}
 
Example #29
Source File: TestDymReSearcher.java    From solr-researcher with Apache License 2.0 5 votes vote down vote up
@Test
public void testOriginalAndSpellcheckedFacet() {
  assertQ(req(CommonParams.QT, "standardGoodSuggestionAllowSomeOriginalResults", 
      CommonParams.Q, "foo:elvos OR foo:presley",
      SpellingParams.SPELLCHECK_COLLATE, "true", 
      SpellingParams.SPELLCHECK_BUILD, "true", 
      SpellingParams.SPELLCHECK_COUNT, "10", 
      SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true",
      FacetParams.FACET, "true", 
      FacetParams.FACET_FIELD, "foo", 
      FacetParams.FACET_FIELD, "id", 
      FacetParams.FACET_FIELD, "bar", 
      FacetParams.FACET_QUERY, "id:[0 TO 20]", 
      FacetParams.FACET_QUERY, "id:[1 TO 100]", 
      HighlightParams.HIGHLIGHT, "true", 
      HighlightParams.FIELDS, "foo",
      DymReSearcher.COMPONENT_NAME, "true",
      SpellCheckComponent.COMPONENT_NAME, "true")
      ,"//result[@name='spellchecked_response'][@numFound='3']"
      ,"//result[@name='response'][@numFound='1']"
      ,"//arr[@name='extended_spellchecker_suggestions']/str[1][.='foo:elvis OR foo:presley']"
      // check spellchecked facets:
      ,"//lst[@name='spellchecked_facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='elvi'][.='3']"
      ,"//lst[@name='spellchecked_facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='presley'][.='1']"
      ,"//lst[@name='spellchecked_facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='2'][.='1']"
      // check original facets:
      ,"//lst[@name='facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='elvi'][.='1']"
      ,"//lst[@name='facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='presley'][.='1']"
      );
}
 
Example #30
Source File: UnifiedSolrHighlighter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected PassageScorer getScorer(String fieldName) {
  float k1 = params.getFieldFloat(fieldName, HighlightParams.SCORE_K1, 1.2f);
  float b = params.getFieldFloat(fieldName, HighlightParams.SCORE_B, 0.75f);
  float pivot = params.getFieldFloat(fieldName, HighlightParams.SCORE_PIVOT, 87f);
  return new PassageScorer(k1, b, pivot);
}