So, just like I said.... call Query.rewrite() and pass the returned Query to the Highlighter, not the original FuzzyQuery. I believe the javadocs for Highlighter even mention this? Or at least its an FAQ that hopefully is on the wiki or easily findable somehow.

        Erik


On Apr 4, 2006, at 9:10 AM, Fisheye wrote:


Ok, thanks Erik. So probably my code may explain it:

---------------------------------------------------------------------- ---------------------------------------------------------

    public void searchQuery(String q, float rel, String indexDir){
        
        String excerpt = "";
        
        try{
                
          Searcher searcher = new IndexSearcher(indexDir);
          Analyzer analyzer = new StandardAnalyzer();

          Term searchTerm = new Term("text", q);
          FuzzyQuery fuzzyQuery = new FuzzyQuery(searchTerm, rel/100);

                System.out.println("Searching for: " + q);
                
                Hits hits = searcher.search(fuzzyQuery);
                System.out.println(hits.length() + " total matching documents");
                
                for (int i = 0; i < hits.length(); i++){
                                
                                    Document doc = hits.doc(i);
                                    String path = doc.get("path");
                                
                                    SearchTextHighlighter processText =
                                        new SearchTextHighlighter();
                                
//                                  excerpt =
//                                      processText.getExcerpt(doc.get("text"), 
q, fuzzyQuery);
                                
                                    if (path != null){
                                        
                                          System.out.println(i + ".-------");
                                          System.out.println("  Path:    " + 
path);
System.out.println(" Score: " + hits.score (i)); System.out.println(" DocID: " + doc.get ("docID"));
                                          System.out.println("  Snippet: " + 
excerpt);
                                          System.out.println();
                        
                                    }else{
                                        
                                          String url = doc.get("url");
                        
                                          if (url != null){
                                                
                                                                System.out.println(i + 
". " + url);
                                                                System.out.println("   - 
" + doc.get("title"));
                                                                
System.out.println("Score: " + hits.score(i));
                                                                
                                          }else{
                                                
                                                        System.out.println(i +
                                                                        ". " + "No 
path nor URL for this document");
                                          }
                                    }
                }

          searcher.close();

        }catch (Exception e){
                
                e.printStackTrace();
        }
      }

---------------------------------------------------------------------- ---------------------------------------------------------

Method getExcerpt does the following:

---------------------------------------------------------------------- ---------------------------------------------------------

public String getExcerpt(String textToCompute, String queryText, Query
query) {

    String excerpt = "";
    String vTemp = "";
    Analyzer analyzer = new StandardAnalyzer();
    Highlighter highlighter = new Highlighter(new QueryScorer(query));

    if(textToCompute != null ){

      TokenStream tokenStream = analyzer.tokenStream("text",
            new StringReader(textToCompute));

      try {

vTemp = highlighter.getBestFragment(tokenStream, textToCompute);
        excerpt = vTemp.replaceAll("" + queryText + "", queryText);
      }
      catch (IOException ex) {


      }
    }

    return excerpt;
  }

---------------------------------------------------------------------- ---------------------------------------------------------
--
View this message in context: http://www.nabble.com/highlighting--- fuzzy-search-t1392775.html#a3743994
Sent from the Lucene - Java Users forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to