I actually didn't commit this. Mladen and I exchanged a few emails off the list. The code below does not allow custom Queries to use MultiSearcher, as it hard-codes existing Queries. It would be better to change the code so that if all instanceof checks fail, the code tries to use the combine(Query[]) provided by the custom Query. If that implementation does not provide is (e.g. throws UnsupportedOperationException), then that Query just can't be used with MultiSearcher, and the caller (developer) has to be aware of that.
Thoughts? Otis --- Otis Gospodnetic <[EMAIL PROTECTED]> wrote: > Hvala Mladen. > > This looks good to me, so I'll check it in. > However, I think....ah, I see. > I was going to say: what about other Query sub-classes, but I guess > combine is not abstract, and Query's combine method throws > UnsupportedOperationException, so you can't assume the Query > instances > passed to combine have combine.... > > Otis > P.S. > Do some code that throws exception with the old rewrite method, so I > can add it to the existing TestMultiSearcher unit test? > P.P.S. > CRLFs fixed - stuff from a recent contribution developed under > Windows. > > --- Mladen Turk <[EMAIL PROTECTED]> wrote: > > > > 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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]