This snippet from the Highlighter JUnit test should reveal the solution:

    public void testFieldSpecificHighlighting() throws IOException, 
ParseException
    {
        String docMainText="fred is one of the people";
        QueryParser parser=new QueryParser(FIELD_NAME,analyzer);
        Query query=parser.parse("fred category:people");
        
        //highlighting respects fieldnames used in query
        QueryScorer fieldSpecificScorer=new QueryScorer(query, "contents");
        Highlighter fieldSpecificHighlighter =
            new Highlighter(new SimpleHTMLFormatter(),fieldSpecificScorer);
        fieldSpecificHighlighter.setTextFragmenter(new NullFragmenter());
        String 
result=fieldSpecificHighlighter.getBestFragment(analyzer,FIELD_NAME,docMainText);
        assertEquals("Should match",result,"<B>fred</B> is one of the people");
        
        //highlighting does not respect fieldnames used in query
        QueryScorer fieldInSpecificScorer=new QueryScorer(query);
        Highlighter fieldInSpecificHighlighter =
            new Highlighter(new SimpleHTMLFormatter(),fieldInSpecificScorer);
        fieldInSpecificHighlighter.setTextFragmenter(new NullFragmenter());
        
result=fieldInSpecificHighlighter.getBestFragment(analyzer,FIELD_NAME,docMainText);
        assertEquals("Should match",result,"<B>fred</B> is one of the 
<B>people</B>");        
        
        reader.close();        
    }

Cheers
Mark


----- Original Message ----
From: moraleslos <[EMAIL PROTECTED]>
To: java-user@lucene.apache.org
Sent: Tuesday, 27 February, 2007 5:22:02 PM
Subject: Highlighting issues


In my search query I have two fields to search, a metadata field and the
actual contents. The metadata field is just an enum containing FIRST and
LAST. Here is an example search query:

Content:"Barry Bonds" and Metadata:FIRST


I have Lucene highlight the hits like this:

...
getBestFragment(standardAnalyzer, "Content", content);
...


Now I would only expect the highlighted text to show the key words Barry
Bonds but instead some of the highlighted text I get back actually
highlights the enum FIRST. For example, one highlighted result is this:
********************************************
...attempting to slide into <p>first</p> base...
********************************************

The above result is not what I had in mind. Any ideas on why the highlighter
is highlighting my enum field and not only my keywords from the content
field? Thanks in advance!

-los 
-- 
View this message in context: 
http://www.nabble.com/Highlighting-issues-tf3302760.html#a9187114
Sent from the Lucene - Java Users mailing list archive at Nabble.com.


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






                
___________________________________________________________ 
All New Yahoo! Mail – Tired of unwanted email come-ons? Let our SpamGuard 
protect you. http://uk.docs.yahoo.com/nowyoucan.html

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

Reply via email to