You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Hoss Man (JIRA)" <ji...@apache.org> on 2006/02/10 08:47:56 UTC

[jira] Commented: (LUCENE-495) Suggested Patches to MultiPhraseQuery and QueryTermExtractor (for use with HighLighter)

    [ http://issues.apache.org/jira/browse/LUCENE-495?page=comments#action_12365855 ] 

Hoss Man commented on LUCENE-495:
---------------------------------

if you could post a test case (or a patch to an existing test case) that demonstrates the error in the existing code, and shows that your patch fixes that bug, thats one of the best ways to encourage that a patch get applied.

> Suggested Patches to MultiPhraseQuery and QueryTermExtractor (for use with HighLighter)
> ---------------------------------------------------------------------------------------
>
>          Key: LUCENE-495
>          URL: http://issues.apache.org/jira/browse/LUCENE-495
>      Project: Lucene - Java
>         Type: Improvement
>   Components: Search
>     Versions: 1.9
>  Environment: All
>     Reporter: Michael Harhen

>
> I encountered a problem with the Highlighter, where it was not recognizing MultiPhraseQuery.
> To fix this, I developed the following two patches:
> =====================================================
> 1. Addition to org.apache.lucene.search.MultiPhraseQuery:
> Add the following method:
> /** Returns the set of terms in this phrase. */
> public Term[] getTerms() {
>   ArrayList allTerms = new ArrayList();
>   Iterator iterator = termArrays.iterator();
>   while (iterator.hasNext()) {
>     Term[] terms = (Term[])iterator.next();
>     for (int i = 0, n = terms.length; i < n; ++i) {
>       allTerms.add(terms[i]);
>     }
>   }
>   return (Term[])allTerms.toArray(new Term[0]);
> }
> =====================================================
> 2. Patch to org.apache.lucene.search.highlight.QueryTermExtractor:
> a) Add the following import:
> import org.apache.lucene.search.MultiPhraseQuery;
> b) Add the following code to the end of the getTerms(...) method:
>       else  if(query instanceof MultiPhraseQuery)
>               getTermsFromMultiPhraseQuery((MultiPhraseQuery) query, terms, fieldName);
>   }
> c) Add the following method:
>  private static final void getTermsFromMultiPhraseQuery(MultiPhraseQuery query, HashSet terms, String fieldName)
>  {
>    Term[] queryTerms = query.getTerms();
>    int i;
>    for (i = 0; i < queryTerms.length; i++)
>    {
>        if((fieldName==null)||(queryTerms[i].field()==fieldName))
>        {
>            terms.add(new WeightedTerm(query.getBoost(),queryTerms[i].text()));
>        }
>    }
>  }
> =====================================================
> Can the team update the repository?
> Thanks
> Michael Harhen 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org