Package org.apache.lucene.search.highlight

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


    numRequests++;
    if( defaults != null ) {
      params = new DefaultSolrParams( params, defaults );
    }
   
    return new SimpleHTMLFormatter(
        params.getFieldParam(fieldName, HighlightParams.SIMPLE_PRE,  "<em>" ),
        params.getFieldParam(fieldName, HighlightParams.SIMPLE_POST, "</em>"));
  }
View Full Code Here


            //QueryParser qp = new QueryParser( LUCENE_PAGE_CONTENTS, getLuceneAnalyzer() );
            Query luceneQuery = qp.parse( query );

            if( (flags & FLAG_CONTEXTS) != 0 )
            {
                highlighter = new Highlighter(new SimpleHTMLFormatter("<span class=\"searchmatch\">", "</span>"),
                                              new SimpleHTMLEncoder(),
                                              new QueryScorer(luceneQuery));
            }

            try
View Full Code Here

        Document doc=multiReader.document(docid);
        String content=doc.get("content");
       
        Scorer qs=new QueryScorer(q);
       
        SimpleHTMLFormatter formatter=new SimpleHTMLFormatter("<span class=\"hl\">","</span>");
        Highlighter hl=new Highlighter(formatter,qs);
        String[] fragments=hl.getBestFragments(analyzer, "content",content, 1);
       
        Map<String,String[]> fields=convert(doc);
        fields.put("fragment",fragments);
View Full Code Here

        Document doc=multiReader.document(docid);
        String content=doc.get("content");
       
        Scorer qs=new QueryScorer(q);
       
        SimpleHTMLFormatter formatter=new SimpleHTMLFormatter("<span class=\"hl\">","</span>");
        Highlighter hl=new Highlighter(formatter,qs);
        String[] fragments=hl.getBestFragments(analyzer, "content",content, 1);
       
        Map<String,String[]> fields=convert(doc);
        fields.put("fragment",fragments);
View Full Code Here

  try
  {
   if (queryString.length() > 0)
   { Query query = qp.parse(queryString.toString());
     QueryScorer qScorer = new QueryScorer(query);
     SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span class=\"hlight\">", "</span>");
     Highlighter highlighter = new Highlighter(formatter, qScorer);
     Fragmenter fragmenter = new SimpleFragmenter(80);        //*-- use fragments of 50 bytes each
     highlighter.setTextFragmenter(fragmenter);
     TokenStream tokenStream = sAnalyzer.tokenStream("contents", new StringReader(text));
     result = highlighter.getBestFragments(tokenStream, text, 3, "...<br>")//*-- collect upto three fragments
View Full Code Here

    /**
     * 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

    Query fixedQuery = fixSuperQuery(query, null, fieldLessFieldName);

    Analyzer analyzer = fieldManager.getAnalyzerForQuery();

    SimpleHTMLFormatter htmlFormatter = new SimpleHTMLFormatter(preTag, postTag);
    Document result = new Document();
    for (IndexableField f : document) {
      String name = f.name();
      if (fieldLessFieldName.equals(name) || FIELDS_NOT_TO_HIGHLIGHT.contains(name)) {
        result.add(f);
View Full Code Here

    numRequests++;
    if( defaults != null ) {
      params = new DefaultSolrParams( params, defaults );
    }
   
    return new SimpleHTMLFormatter(
        params.getFieldParam(fieldName, HighlightParams.SIMPLE_PRE,  "<em>" ),
        params.getFieldParam(fieldName, HighlightParams.SIMPLE_POST, "</em>"));
  }
View Full Code Here

            //QueryParser qp = new QueryParser( LUCENE_PAGE_CONTENTS, getLuceneAnalyzer() );
            Query luceneQuery = qp.parse( query );

            if( (flags & FLAG_CONTEXTS) != 0 )
            {
                highlighter = new Highlighter(new SimpleHTMLFormatter("<span class=\"searchmatch\">", "</span>"),
                                              new SimpleHTMLEncoder(),
                                              new QueryScorer(luceneQuery));
            }

            try
View Full Code Here

        // these placeholders are later on replaced by the given prefix and suffix
        // this additional step is necessary to encode the fragment text properly
        // see F00004C66
        String prefixPlaceholder = "$HIGHLIGHT_PREFIX$";
        String suffixPlaceholder = "$HIGHLIGHT_SUFFIX$";       
        SimpleHTMLFormatter formatter = new SimpleHTMLFormatter(prefixPlaceholder, suffixPlaceholder);

        // create highlighter
        Highlighter highlighter = getwgacore().getLuceneManager().createHighlighter(name, query, formatter);
       
        // retrieve itemtext
View Full Code Here

TOP

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

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.