You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Mladen Turk <mt...@apache.org> on 2004/02/26 22:24:01 UTC

MultiSearcher.java CRLF and rewrite PATCH

Hi,

Seems that MultiSearcher.java in CVS is using CRLF line endings.
Is that intentional, and can it be formatted like the rest of code.
Or is it just my CVS client?


Second thing is that I have a patch for it, fixing rewrite.
Current implementation throws exception when using multiple searchers,
and mixed queries.

I've implemented my own combine instead relaying on original Query
combine (that might be unimplemented in particular Query implementation
class).

It's very useful for term highlighting.

MT.

Here is the code (since the file in CVS uses CRLF):


  /*
   * Combine as many queries as possible
   */
  private Query combine(Query[] queries) throws IOException {

    if (queries.length < 2) {
        return queries[0];
    }

    Query[] combined = new Query[2];
    combined[0] = new BooleanQuery();
    for (int i = 0; i < queries.length; i++) {
        combined[1] = queries[i];
        if (queries[i] instanceof BooleanQuery ||
            queries[i] instanceof MultiTermQuery ||
            queries[i] instanceof PrefixQuery ||
            queries[i] instanceof RangeQuery) {
            combined[0] = Query.mergeBooleanQueries(combined);
        }
        else if (queries[i] instanceof PhraseQuery) {
            Term[] queryTerms = ((PhraseQuery)queries[i]).getTerms();
            for (int j = 0; j < queryTerms.length; j++) {
                TermQuery q = new TermQuery(queryTerms[j]);
                ((BooleanQuery)combined[0]).add(q, true, false);
            }           
        }
    }                
    
    return combined[0];
    
  }
  
  public Query rewrite(Query original) throws IOException {
    Query[] queries = new Query[searchables.length];
    for (int i = 0; i < searchables.length; i++) {
      queries[i] = searchables[i].rewrite(original);
    }
    return combine(queries);
  }



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