lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Haye ...@snyder-haye.com>
Subject Re: Custom "multi term" SpanQuery subclass issue
Date Fri, 16 Sep 2005 00:09:58 GMT
While I'd certainly have been willing to submit mine as a patch, yours is 
more elegant. I like the use of clone(), and I see now that other rewrite 
methods do it that way now (maybe they always did).

--Martin


On 9/15/05, Erik Hatcher <erik@ehatchersolutions.com> wrote:
> 
> I just added an overridden rewrite method to SpanNearQuery as below
> and it worked great. I'd be happy to do similar to all SpanQuery
> subclasses that accept SpanQuery's in their constructors. Any
> objections?
> 
> Thanks,
> Erik
> 
> 
> public Query rewrite(IndexReader reader) throws IOException {
> SpanNearQuery clone = null;
> for (int i = 0 ; i < clauses.size(); i++) {
> SpanQuery c = (SpanQuery)clauses.get(i);
> SpanQuery query = (SpanQuery) c.rewrite(reader);
> if (query != c) { // clause rewrote: must
> clone
> if (clone == null)
> clone = (SpanNearQuery) this.clone();
> clone.clauses.set(i,query);
> }
> }
> if (clone != null) {
> return clone; // some clauses rewrote
> } else {
> return this; // no clauses rewrote
> }
> }
> 
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message