On Fri, Aug 29, 2008 at 12:18 PM, Chris Hostetter
<[EMAIL PROTECTED]> wrote:
> Are we really sure we want to do this w/o making it configurable on
> the QParser? (ala: SOLR-218)

I thought about that, but these expanding term queries that have no
bounds are really broken... people who depend on them are playing with
fire.  Imagine everything working fine for months, docs being
occasionally added, until *boom* a magic limit is hit.

I wouldn't be opposed to a config option I guess... but I think the
default should be something that doesn't unpredictably break (so it
still wouldn't be 100% back compatible).

IMO, Highlighting really needs to be fixed to go through a different
mechanism than extractTerms().

-Yonik

> Unless I'm missing something this change breaks back compatibility of for
> users who highlight wildcard queries.  As i recall: we even have users who
> force their prefix queries to be wildcards by using "Hippo?*" instead of
> "Hippo*" just so they can get highlighting.
>
> +0
>
>
> : Date: Thu, 28 Aug 2008 20:54:25 -0000
> : From: [EMAIL PROTECTED]
> : Reply-To: solr-dev@lucene.apache.org
> : To: [EMAIL PROTECTED]
> : Subject: svn commit: r689978 - in /lucene/solr/trunk: CHANGES.txt
> :     src/java/org/apache/solr/search/SolrQueryParser.java
> :     src/java/org/apache/solr/search/WildcardFilter.java
> :     src/test/org/apache/solr/ConvertedLegacyTest.java
> :
> : Author: yonik
> : Date: Thu Aug 28 13:54:24 2008
> : New Revision: 689978
> :
> : URL: http://svn.apache.org/viewvc?rev=689978&view=rev
> : Log:
> : SOLR-737: use a constant score query for wildcards
> :
> : Added:
> :     lucene/solr/trunk/src/java/org/apache/solr/search/WildcardFilter.java   
> (with props)
> : Modified:
> :     lucene/solr/trunk/CHANGES.txt
> :     lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryParser.java
> :     lucene/solr/trunk/src/test/org/apache/solr/ConvertedLegacyTest.java
> :
> : Modified: lucene/solr/trunk/CHANGES.txt
> : URL: 
> http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=689978&r1=689977&r2=689978&view=diff
> : 
> ==============================================================================
> : --- lucene/solr/trunk/CHANGES.txt (original)
> : +++ lucene/solr/trunk/CHANGES.txt Thu Aug 28 13:54:24 2008
> : @@ -396,6 +396,10 @@
> :
> :   3. SOLR-647: reference count the SolrCore uses to prevent a premature
> :      close while a core is still in use.  (Henri Biestro, Noble Paul, yonik)
> : +
> : + 4. SOLR-737: SolrQueryParser now uses a ConstantScoreQuery for wildcard
> : +    queries that prevent an exception from being thrown when the number
> : +    of matching terms exceeds the BooleanQuery clause limit.  (yonik)
> :
> :  Optimizations
> :   1. SOLR-276: improve JSON writer speed. (yonik)
> :
> : Modified: 
> lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryParser.java
> : URL: 
> http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryParser.java?rev=689978&r1=689977&r2=689978&view=diff
> : 
> ==============================================================================
> : --- lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryParser.java 
> (original)
> : +++ lucene/solr/trunk/src/java/org/apache/solr/search/SolrQueryParser.java 
> Thu Aug 28 13:54:24 2008
> : @@ -22,6 +22,8 @@
> :  import org.apache.lucene.queryParser.QueryParser;
> :  import org.apache.lucene.search.ConstantScoreRangeQuery;
> :  import org.apache.lucene.search.Query;
> : +import org.apache.lucene.search.WildcardQuery;
> : +import org.apache.lucene.search.ConstantScoreQuery;
> :  import org.apache.lucene.analysis.Analyzer;
> :  import org.apache.solr.common.SolrException;
> :  import org.apache.solr.schema.FieldType;
> : @@ -144,4 +146,12 @@
> :      return new ConstantScorePrefixQuery(t);
> :    }
> :
> : +  protected Query getWildcardQuery(String field, String termStr) throws 
> ParseException {
> : +    Query q = super.getWildcardQuery(field, termStr);
> : +    if (q instanceof WildcardQuery) {
> : +      // use a constant score query to avoid overflowing clauses
> : +      return new ConstantScoreQuery(new 
> WildcardFilter(((WildcardQuery)q).getTerm()));
> : +    }
> : +    return q;
> : +  }
> :  }
> :
> : Added: lucene/solr/trunk/src/java/org/apache/solr/search/WildcardFilter.java
> : URL: 
> http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/WildcardFilter.java?rev=689978&view=auto
> : 
> ==============================================================================
> : --- lucene/solr/trunk/src/java/org/apache/solr/search/WildcardFilter.java 
> (added)
> : +++ lucene/solr/trunk/src/java/org/apache/solr/search/WildcardFilter.java 
> Thu Aug 28 13:54:24 2008
> : @@ -0,0 +1,103 @@
> : +/**
> : + * Licensed to the Apache Software Foundation (ASF) under one or more
> : + * contributor license agreements.  See the NOTICE file distributed with
> : + * this work for additional information regarding copyright ownership.
> : + * The ASF licenses this file to You under the Apache License, Version 2.0
> : + * (the "License"); you may not use this file except in compliance with
> : + * the License.  You may obtain a copy of the License at
> : + *
> : + *     http://www.apache.org/licenses/LICENSE-2.0
> : + *
> : + * Unless required by applicable law or agreed to in writing, software
> : + * distributed under the License is distributed on an "AS IS" BASIS,
> : + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> : + * See the License for the specific language governing permissions and
> : + * limitations under the License.
> : + */
> : +
> : +package org.apache.solr.search;
> : +
> : +import org.apache.lucene.search.Filter;
> : +import org.apache.lucene.search.DocIdSet;
> : +import org.apache.lucene.search.WildcardTermEnum;
> : +import org.apache.lucene.index.Term;
> : +import org.apache.lucene.index.IndexReader;
> : +import org.apache.lucene.index.TermEnum;
> : +import org.apache.lucene.index.TermDocs;
> : +import org.apache.lucene.util.OpenBitSet;
> : +
> : +import java.util.BitSet;
> : +import java.io.IOException;
> : +
> : +
> : +/**
> : + *
> : + * @version $Id$
> : + */
> : +public class WildcardFilter extends Filter {
> : +  protected final Term term;
> : +
> : +  public WildcardFilter(Term wildcardTerm) {
> : +    this.term = wildcardTerm;
> : +  }
> : +
> : +  public Term getTerm() { return term; }
> : +
> : +  /**
> : +   * @deprecated Use [EMAIL PROTECTED] #getDocIdSet(IndexReader)} instead.
> : +   */
> : +  public BitSet bits(IndexReader reader) throws IOException {
> : +    final BitSet bitSet = new BitSet(reader.maxDoc());
> : +    new WildcardGenerator(term) {
> : +      public void handleDoc(int doc) {
> : +        bitSet.set(doc);
> : +      }
> : +    }.generate(reader);
> : +    return bitSet;
> : +  }
> : +
> : +  public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
> : +    final OpenBitSet bitSet = new OpenBitSet(reader.maxDoc());
> : +    new WildcardGenerator(term) {
> : +      public void handleDoc(int doc) {
> : +        bitSet.set(doc);
> : +      }
> : +    }.generate(reader);
> : +    return bitSet;
> : +  }
> : +
> : +  public String toString () {
> : +    StringBuilder sb = new StringBuilder();
> : +    sb.append("WildcardFilter(");
> : +    sb.append(term.toString());
> : +    sb.append(")");
> : +    return sb.toString();
> : +  }
> : +}
> : +
> : +
> : +abstract class WildcardGenerator implements IdGenerator {
> : +  protected final Term wildcard;
> : +
> : +  WildcardGenerator(Term wildcard) {
> : +    this.wildcard = wildcard;
> : +  }
> : +
> : +  public void generate(IndexReader reader) throws IOException {
> : +    TermEnum enumerator = new WildcardTermEnum(reader, wildcard);
> : +    TermDocs termDocs = reader.termDocs();
> : +    try {
> : +      do {
> : +        Term term = enumerator.term();
> : +        if (term==null) break;
> : +        termDocs.seek(term);
> : +        while (termDocs.next()) {
> : +          handleDoc(termDocs.doc());
> : +        }
> : +      } while (enumerator.next());
> : +    } finally {
> : +      termDocs.close();
> : +      enumerator.close();
> : +    }
> : +  }
> : +}
> :
> : Propchange: 
> lucene/solr/trunk/src/java/org/apache/solr/search/WildcardFilter.java
> : 
> ------------------------------------------------------------------------------
> :     svn:eol-style = native
> :
> : Propchange: 
> lucene/solr/trunk/src/java/org/apache/solr/search/WildcardFilter.java
> : 
> ------------------------------------------------------------------------------
> :     svn:executable = *
> :
> : Propchange: 
> lucene/solr/trunk/src/java/org/apache/solr/search/WildcardFilter.java
> : 
> ------------------------------------------------------------------------------
> :     svn:keywords = Date Author Id Revision HeadURL
> :
> : Modified: 
> lucene/solr/trunk/src/test/org/apache/solr/ConvertedLegacyTest.java
> : URL: 
> http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/ConvertedLegacyTest.java?rev=689978&r1=689977&r2=689978&view=diff
> : 
> ==============================================================================
> : --- lucene/solr/trunk/src/test/org/apache/solr/ConvertedLegacyTest.java 
> (original)
> : +++ lucene/solr/trunk/src/test/org/apache/solr/ConvertedLegacyTest.java Thu 
> Aug 28 13:54:24 2008
> : @@ -812,6 +812,9 @@
> :              );
> :      // val_s:* %//[EMAIL PROTECTED]"8"]
> :
> : +    // test wildcard query
> : +    assertQ(req("val_s:a*p*") ,"//[EMAIL PROTECTED]'3']");
> : +    assertQ(req("val_s:p?a*") ,"//[EMAIL PROTECTED]'3']");
> :
> :      assertU("<delete><query>id:[100 TO 110]</query></delete>");
> :
> :
> :
>
>
>
> -Hoss
>
>

Reply via email to