Package org.apache.lucene.search.highlight

Examples of org.apache.lucene.search.highlight.Formatter


    /**
     * Add snippets to the search-results. It adds a new field
     * SNIPPET_FIELDNAME_PREFIX_field with the snippet for each field
     */
    private void addSnippets (GroupedSearchResults res, org.apache.lucene.search.Query query) throws IOException {   
        Formatter simpleHtmlFormatter= new SimpleHTMLFormatter(HIGHLIGHTER_PREFIX, HIGHLIGHTER_SUFFIX);
        for (int i= 0; i < snippetOfFields.length; i++) {
            String fieldToSnippet = snippetOfFields[i];  
            int snippetLength= snippetsLength[i];
            QueryScorer scorer= new QueryScorer(query, fieldToSnippet);
            addSnippets(res, fieldToSnippet, snippetLength, scorer, simpleHtmlFormatter);
View Full Code Here


        }

        CachingTokenFilter tokenStream =
            new CachingTokenFilter( context.getAnalyzer().tokenStream( field.getKey(), new StringReader( text ) ) );

        Formatter formatter = null;

        if ( MatchHighlightMode.HTML.equals( hr.getHighlightMode() ) )
        {
            formatter = new SimpleHTMLFormatter();
        }
View Full Code Here

        } catch (IOException e) {
          log
              .error("Cannot rewrite Query object; returning original text");
          return text;
        }
        Formatter formatter = null;
        if (args.length == 4) {
          formatter = new SimpleHTMLFormatter(args[2].toString(),
              args[3].toString());
        } else {
          formatter = new SimpleHTMLFormatter();
View Full Code Here

   * @param subLength 截取长度
   * @param fields 字段名
   */
  public List<T> keywordsHighlight(BooleanQuery query, List<T> list, int subLength, String... fields){
    Analyzer analyzer = new IKAnalyzer();
    Formatter formatter = new SimpleHTMLFormatter("<span class=\"highlight\">", "</span>");  
    Highlighter highlighter = new Highlighter(formatter, new QueryScorer(query));
    highlighter.setTextFragmenter(new SimpleFragmenter(subLength));
    for(T entity : list){
      try {
        for (String field : fields){
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.highlight.Formatter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.