I'm trying to use getBestFragments to concatenate the most relevant segments
of a document, but it only returns one. I must be doing something wrong
here. Here is the the code:
private static void createResult(float in_score,                        String 
in_category,             
String in_subject,                      String in_path,                 Query 
in_query) {               // read file
content using path              byte[] encoded;         try {                   
encoded =
Files.readAllBytes(Paths.get(in_path));         } catch (IOException e) {       
                // TODO
Auto-generated catch block                      e.printStackTrace();            
        return null;            }          
QueryScorer queryScorer = new QueryScorer(in_query);        Highlighter
highlighter = new Highlighter(_formatter, queryScorer);            
highlighter.setTextFragmenter(new SimpleSpanFragmenter(queryScorer, 100));      
   
highlighter.setMaxDocCharsToAnalyze(Integer.MAX_VALUE);             String[]
t_res;          try {                   t_res = 
highlighter.getBestFragments(_analyzer,
_querySearchContext,                                    new String(encoded), 
5);                        //t_res.length is
always 1                                        } catch (IOException e) {       
                // TODO Auto-generated catch block              
e.printStackTrace();                    return null;            } catch 
(InvalidTokenOffsetsException
e) {                    // TODO Auto-generated catch block                      
e.printStackTrace();                    return
null;           }                       String t_html = "...";          
for(String value : t_res) {                     t_html
+= value.replace("\n", "").replace("\r", "").replace("-", "").replace("\t","
") + "...";             }                System.out.println(t_html);}




--
View this message in context: 
http://lucene.472066.n3.nabble.com/getBestFragments-only-returning-1-item-tp4198479.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.

Reply via email to