lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r829134 [2/2] - in /lucene/java/branches/lucene_2_9: ./ contrib/ contrib/analyzers/common/src/java/org/apache/lucene/analysis/ar/ contrib/analyzers/common/src/java/org/apache/lucene/analysis/br/ contrib/analyzers/common/src/java/org/apache/...
Date Fri, 23 Oct 2009 17:18:55 GMT
Modified: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/analysis/standard/StandardTokenizer.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/analysis/standard/StandardTokenizer.java?rev=829134&r1=829133&r2=829134&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/analysis/standard/StandardTokenizer.java
(original)
+++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/analysis/standard/StandardTokenizer.java
Fri Oct 23 17:18:53 2009
@@ -27,6 +27,7 @@
 import org.apache.lucene.analysis.tokenattributes.TermAttribute;
 import org.apache.lucene.analysis.tokenattributes.TypeAttribute;
 import org.apache.lucene.util.AttributeSource;
+import org.apache.lucene.util.Version;
 
 /** A grammar-based tokenizer constructed with JFlex
  *
@@ -43,6 +44,14 @@
  * <p>Many applications have specific tokenizer needs.  If this tokenizer does
  * not suit your application, please consider copying this source code
  * directory to your project and maintaining your own grammar-based tokenizer.
+ *
+ * <a name="version"/>
+ * <p>You must specify the required {@link Version}
+ * compatibility when creating StandardAnalyzer:
+ * <ul>
+ *   <li> As of 2.4, Tokens incorrectly identified as acronyms
+ *        are corrected (see <a href="https://issues.apache.org/jira/browse/LUCENE-1068">LUCENE-1608</a>
+ * </ul>
  */
 
 public class StandardTokenizer extends Tokenizer {
@@ -107,9 +116,12 @@
   /**
    * Creates a new instance of the {@link StandardTokenizer}. Attaches the
    * <code>input</code> to a newly created JFlex scanner.
+   *
+   * @deprecated Use {@link #StandardTokenizer(Version,
+   * Reader)} instead
    */
   public StandardTokenizer(Reader input) {
-    this(input, false);
+    this(Version.LUCENE_24, input);
   }
 
   /**
@@ -120,6 +132,8 @@
    * @param replaceInvalidAcronym Set to true to replace mischaracterized acronyms with HOST.
    *
    * See http://issues.apache.org/jira/browse/LUCENE-1068
+   *
+   * @deprecated Use {@link #StandardTokenizer(Version, Reader)} instead
    */
   public StandardTokenizer(Reader input, boolean replaceInvalidAcronym) {
     super();
@@ -128,7 +142,23 @@
   }
 
   /**
+   * Creates a new instance of the {@link org.apache.lucene.analysis.standard.StandardTokenizer}.
 Attaches
+   * the <code>input</code> to the newly created JFlex scanner.
+   *
+   * @param input The input reader
+   *
+   * See http://issues.apache.org/jira/browse/LUCENE-1068
+   */
+  public StandardTokenizer(Version matchVersion, Reader input) {
+    super();
+    this.scanner = new StandardTokenizerImpl(input);
+    init(input, matchVersion);
+  }
+
+  /**
    * Creates a new StandardTokenizer with a given {@link AttributeSource}. 
+   *
+   * @deprecated Use {@link #StandardTokenizer(Version, AttributeSource, Reader)} instead
    */
   public StandardTokenizer(AttributeSource source, Reader input, boolean replaceInvalidAcronym)
{
     super(source);
@@ -137,7 +167,18 @@
   }
 
   /**
+   * Creates a new StandardTokenizer with a given {@link AttributeSource}. 
+   */
+  public StandardTokenizer(Version matchVersion, AttributeSource source, Reader input) {
+    super(source);
+    this.scanner = new StandardTokenizerImpl(input);
+    init(input, matchVersion);
+  }
+
+  /**
    * Creates a new StandardTokenizer with a given {@link org.apache.lucene.util.AttributeSource.AttributeFactory}

+   *
+   * @deprecated Use {@link #StandardTokenizer(Version, org.apache.lucene.util.AttributeSource.AttributeFactory,
Reader)} instead
    */
   public StandardTokenizer(AttributeFactory factory, Reader input, boolean replaceInvalidAcronym)
{
     super(factory);
@@ -145,6 +186,15 @@
     init(input, replaceInvalidAcronym);
   }
 
+  /**
+   * Creates a new StandardTokenizer with a given {@link org.apache.lucene.util.AttributeSource.AttributeFactory}

+   */
+  public StandardTokenizer(Version matchVersion, AttributeFactory factory, Reader input)
{
+    super(factory);
+    this.scanner = new StandardTokenizerImpl(input);
+    init(input, matchVersion);
+  }
+
   private void init(Reader input, boolean replaceInvalidAcronym) {
     this.replaceInvalidAcronym = replaceInvalidAcronym;
     this.input = input;    
@@ -153,6 +203,14 @@
     posIncrAtt = (PositionIncrementAttribute) addAttribute(PositionIncrementAttribute.class);
     typeAtt = (TypeAttribute) addAttribute(TypeAttribute.class);
   }
+
+  private void init(Reader input, Version matchVersion) {
+    if (matchVersion.onOrAfter(Version.LUCENE_24)) {
+      init(input, true);
+    } else {
+      init(input, false);
+    }
+  }
   
   // this tokenizer generates three attributes:
   // offset, positionIncrement and type

Modified: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java?rev=829134&r1=829133&r2=829134&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java
(original)
+++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java
Fri Oct 23 17:18:53 2009
@@ -27,6 +27,7 @@
 import org.apache.lucene.search.MultiPhraseQuery;
 import org.apache.lucene.search.PhraseQuery;
 import org.apache.lucene.search.Query;
+import org.apache.lucene.util.Version;
 
 /**
  * A QueryParser which constructs queries to search multiple fields.
@@ -64,9 +65,43 @@
    *
    * <p>In other words, all the query's terms must appear, but it doesn't matter in
    * what fields they appear.</p>
+   *
+   * @deprecated Please use {@link #MultiFieldQueryParser(Version, String[], Analyzer, Map)}
instead
    */
   public MultiFieldQueryParser(String[] fields, Analyzer analyzer, Map boosts) {
-    this(fields,analyzer);
+    this(Version.LUCENE_24, fields, analyzer);
+    this.boosts = boosts;
+  }
+  
+  /**
+   * Creates a MultiFieldQueryParser. 
+   * Allows passing of a map with term to Boost, and the boost to apply to each term.
+   *
+   * <p>It will, when parse(String query)
+   * is called, construct a query like this (assuming the query consists of
+   * two terms and you specify the two fields <code>title</code> and <code>body</code>):</p>
+   * 
+   * <code>
+   * (title:term1 body:term1) (title:term2 body:term2)
+   * </code>
+   *
+   * <p>When setDefaultOperator(AND_OPERATOR) is set, the result will be:</p>
+   *  
+   * <code>
+   * +(title:term1 body:term1) +(title:term2 body:term2)
+   * </code>
+   * 
+   * <p>When you pass a boost (title=>5 body=>10) you can get </p>
+   * 
+   * <code>
+   * +(title:term1^5.0 body:term1^10.0) +(title:term2^5.0 body:term2^10.0)
+   * </code>
+   *
+   * <p>In other words, all the query's terms must appear, but it doesn't matter in
+   * what fields they appear.</p>
+   */
+  public MultiFieldQueryParser(Version matchVersion, String[] fields, Analyzer analyzer,
Map boosts) {
+    this(matchVersion, fields, analyzer);
     this.boosts = boosts;
   }
   
@@ -89,9 +124,35 @@
    * 
    * <p>In other words, all the query's terms must appear, but it doesn't matter in
    * what fields they appear.</p>
+   *
+   * @deprecated Please use {@link #MultiFieldQueryParser(Version, String[], Analyzer)} instead
    */
   public MultiFieldQueryParser(String[] fields, Analyzer analyzer) {
-    super(null, analyzer);
+    this(Version.LUCENE_24, fields, analyzer);
+  }
+  
+  /**
+   * Creates a MultiFieldQueryParser.
+   *
+   * <p>It will, when parse(String query)
+   * is called, construct a query like this (assuming the query consists of
+   * two terms and you specify the two fields <code>title</code> and <code>body</code>):</p>
+   * 
+   * <code>
+   * (title:term1 body:term1) (title:term2 body:term2)
+   * </code>
+   *
+   * <p>When setDefaultOperator(AND_OPERATOR) is set, the result will be:</p>
+   *  
+   * <code>
+   * +(title:term1 body:term1) +(title:term2 body:term2)
+   * </code>
+   * 
+   * <p>In other words, all the query's terms must appear, but it doesn't matter in
+   * what fields they appear.</p>
+   */
+  public MultiFieldQueryParser(Version matchVersion, String[] fields, Analyzer analyzer)
{
+    super(matchVersion, null, analyzer);
     this.fields = fields;
   }
   
@@ -202,16 +263,40 @@
    * @throws ParseException if query parsing fails
    * @throws IllegalArgumentException if the length of the queries array differs
    *  from the length of the fields array
+   * @deprecated Use {@link #parse(Version,String[],String[],Analyzer)} instead
    */
   public static Query parse(String[] queries, String[] fields,
       Analyzer analyzer) throws ParseException
   {
+    return parse(Version.LUCENE_24, queries, fields, analyzer);
+  }
+
+  /**
+   * Parses a query which searches on the fields specified.
+   * <p>
+   * If x fields are specified, this effectively constructs:
+   * <pre>
+   * <code>
+   * (field1:query1) (field2:query2) (field3:query3)...(fieldx:queryx)
+   * </code>
+   * </pre>
+   * @param matchVersion Lucene version to match; this is passed through to QueryParser.
+   * @param queries Queries strings to parse
+   * @param fields Fields to search on
+   * @param analyzer Analyzer to use
+   * @throws ParseException if query parsing fails
+   * @throws IllegalArgumentException if the length of the queries array differs
+   *  from the length of the fields array
+   */
+  public static Query parse(Version matchVersion, String[] queries, String[] fields,
+      Analyzer analyzer) throws ParseException
+  {
     if (queries.length != fields.length)
       throw new IllegalArgumentException("queries.length != fields.length");
     BooleanQuery bQuery = new BooleanQuery();
     for (int i = 0; i < fields.length; i++)
     {
-      QueryParser qp = new QueryParser(fields[i], analyzer);
+      QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
       Query q = qp.parse(queries[i]);
       if (q!=null && // q never null, just being defensive
           (!(q instanceof BooleanQuery) || ((BooleanQuery)q).getClauses().length>0)) {
@@ -250,14 +335,51 @@
    * @throws ParseException if query parsing fails
    * @throws IllegalArgumentException if the length of the fields array differs
    *  from the length of the flags array
+   * @deprecated Use {@link #parse(Version, String, String[], BooleanClause.Occur[], Analyzer)}
instead
    */
   public static Query parse(String query, String[] fields,
       BooleanClause.Occur[] flags, Analyzer analyzer) throws ParseException {
+    return parse(Version.LUCENE_24, query, fields, flags, analyzer);
+  }
+
+  /**
+   * Parses a query, searching on the fields specified.
+   * Use this if you need to specify certain fields as required,
+   * and others as prohibited.
+   * <p><pre>
+   * Usage:
+   * <code>
+   * String[] fields = {"filename", "contents", "description"};
+   * BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD,
+   *                BooleanClause.Occur.MUST,
+   *                BooleanClause.Occur.MUST_NOT};
+   * MultiFieldQueryParser.parse("query", fields, flags, analyzer);
+   * </code>
+   * </pre>
+   *<p>
+   * The code above would construct a query:
+   * <pre>
+   * <code>
+   * (filename:query) +(contents:query) -(description:query)
+   * </code>
+   * </pre>
+   *
+   * @param matchVersion Lucene version to match; this is passed through to QueryParser.
+   * @param query Query string to parse
+   * @param fields Fields to search on
+   * @param flags Flags describing the fields
+   * @param analyzer Analyzer to use
+   * @throws ParseException if query parsing fails
+   * @throws IllegalArgumentException if the length of the fields array differs
+   *  from the length of the flags array
+   */
+  public static Query parse(Version matchVersion, String query, String[] fields,
+      BooleanClause.Occur[] flags, Analyzer analyzer) throws ParseException {
     if (fields.length != flags.length)
       throw new IllegalArgumentException("fields.length != flags.length");
     BooleanQuery bQuery = new BooleanQuery();
     for (int i = 0; i < fields.length; i++) {
-      QueryParser qp = new QueryParser(fields[i], analyzer);
+      QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
       Query q = qp.parse(query);
       if (q!=null && // q never null, just being defensive 
           (!(q instanceof BooleanQuery) || ((BooleanQuery)q).getClauses().length>0)) {
@@ -297,16 +419,55 @@
    * @throws ParseException if query parsing fails
    * @throws IllegalArgumentException if the length of the queries, fields,
    *  and flags array differ
+   * @deprecated Used {@link #parse(Version, String[], String[], BooleanClause.Occur[], Analyzer)}
instead
    */
   public static Query parse(String[] queries, String[] fields, BooleanClause.Occur[] flags,
       Analyzer analyzer) throws ParseException
   {
+    return parse(Version.LUCENE_24, queries, fields, flags, analyzer);
+  }
+
+  /**
+   * Parses a query, searching on the fields specified.
+   * Use this if you need to specify certain fields as required,
+   * and others as prohibited.
+   * <p><pre>
+   * Usage:
+   * <code>
+   * String[] query = {"query1", "query2", "query3"};
+   * String[] fields = {"filename", "contents", "description"};
+   * BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD,
+   *                BooleanClause.Occur.MUST,
+   *                BooleanClause.Occur.MUST_NOT};
+   * MultiFieldQueryParser.parse(query, fields, flags, analyzer);
+   * </code>
+   * </pre>
+   *<p>
+   * The code above would construct a query:
+   * <pre>
+   * <code>
+   * (filename:query1) +(contents:query2) -(description:query3)
+   * </code>
+   * </pre>
+   *
+   * @param matchVersion Lucene version to match; this is passed through to QueryParser.
+   * @param queries Queries string to parse
+   * @param fields Fields to search on
+   * @param flags Flags describing the fields
+   * @param analyzer Analyzer to use
+   * @throws ParseException if query parsing fails
+   * @throws IllegalArgumentException if the length of the queries, fields,
+   *  and flags array differ
+   */
+  public static Query parse(Version matchVersion, String[] queries, String[] fields, BooleanClause.Occur[]
flags,
+      Analyzer analyzer) throws ParseException
+  {
     if (!(queries.length == fields.length && queries.length == flags.length))
       throw new IllegalArgumentException("queries, fields, and flags array have have different
length");
     BooleanQuery bQuery = new BooleanQuery();
     for (int i = 0; i < fields.length; i++)
     {
-      QueryParser qp = new QueryParser(fields[i], analyzer);
+      QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
       Query q = qp.parse(queries[i]);
       if (q!=null && // q never null, just being defensive
           (!(q instanceof BooleanQuery) || ((BooleanQuery)q).getClauses().length>0)) {

Modified: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/queryParser/QueryParser.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/queryParser/QueryParser.java?rev=829134&r1=829133&r2=829134&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/queryParser/QueryParser.java
(original)
+++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/queryParser/QueryParser.java
Fri Oct 23 17:18:53 2009
@@ -35,6 +35,7 @@
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.WildcardQuery;
 import org.apache.lucene.util.Parameter;
+import org.apache.lucene.util.Version;
 
 /**
  * This class is generated by JavaCC.  The most important method is
@@ -101,6 +102,14 @@
  * <p><b>NOTE</b>: there is a new QueryParser in contrib, which matches
  * the same syntax as this class, but is more modular,
  * enabling substantial customization to how a query is created.
+ *
+ * <a name="version"/>
+ * <p><b>NOTE</b>: You must specify the required {@link Version}
+ * compatibility when creating QueryParser:
+ * <ul>
+ *    <li> As of 2.9, {@link #setEnablePositionIncrements} is true by
+ *         default.
+ * </ul>
  */
 public class QueryParser implements QueryParserConstants {
 
@@ -125,7 +134,7 @@
   boolean lowercaseExpandedTerms = true;
   MultiTermQuery.RewriteMethod multiTermRewriteMethod = MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
   boolean allowLeadingWildcard = false;
-  boolean enablePositionIncrements = false;
+  boolean enablePositionIncrements = true;
 
   Analyzer analyzer;
   String field;
@@ -158,11 +167,26 @@
   /** Constructs a query parser.
    *  @param f  the default field for query terms.
    *  @param a   used to find terms in the query text.
+   *  @deprecated Use {@link #QueryParser(Version, String, Analyzer)} instead
    */
   public QueryParser(String f, Analyzer a) {
+    this(Version.LUCENE_24, f, a);
+  }
+
+  /** Constructs a query parser.
+   *  @param matchVersion  Lucene version to match.  See <a href="#version">above</a>)
+   *  @param f  the default field for query terms.
+   *  @param a   used to find terms in the query text.
+   */
+  public QueryParser(Version matchVersion, String f, Analyzer a) {
     this(new FastCharStream(new StringReader("")));
     analyzer = a;
     field = f;
+    if (matchVersion.onOrAfter(Version.LUCENE_29)) {
+      enablePositionIncrements = true;
+    } else {
+      enablePositionIncrements = false;
+    }
   }
 
   /** Parses a query string, returning a {@link org.apache.lucene.search.Query}.
@@ -759,7 +783,7 @@
       DateTools.Resolution resolution = getDateResolution(field);
       if (resolution == null) {
         // no default or field specific date resolution has been set,
-        // use deprecated DateField to maintain compatibilty with
+        // use deprecated DateField to maintain compatibility with
         // pre-1.9 Lucene versions.
         part1 = DateField.dateToString(d1);
         part2 = DateField.dateToString(d2);
@@ -1155,7 +1179,7 @@
       System.out.println("Usage: java org.apache.lucene.queryParser.QueryParser <input>");
       System.exit(0);
     }
-    QueryParser qp = new QueryParser("field",
+    QueryParser qp = new QueryParser(Version.LUCENE_CURRENT, "field",
                            new org.apache.lucene.analysis.SimpleAnalyzer());
     Query q = qp.parse(args[0]);
     System.out.println(q.toString("field"));
@@ -1591,6 +1615,12 @@
     finally { jj_save(0, xla); }
   }
 
+  private boolean jj_3R_2() {
+    if (jj_scan_token(TERM)) return true;
+    if (jj_scan_token(COLON)) return true;
+    return false;
+  }
+
   private boolean jj_3_1() {
     Token xsp;
     xsp = jj_scanpos;
@@ -1607,12 +1637,6 @@
     return false;
   }
 
-  private boolean jj_3R_2() {
-    if (jj_scan_token(TERM)) return true;
-    if (jj_scan_token(COLON)) return true;
-    return false;
-  }
-
   /** Generated Token Manager. */
   public QueryParserTokenManager token_source;
   /** Current token. */
@@ -1641,7 +1665,7 @@
   private int jj_gc = 0;
 
   /** Constructor with user supplied CharStream. */
-  public QueryParser(CharStream stream) {
+  protected QueryParser(CharStream stream) {
     token_source = new QueryParserTokenManager(stream);
     token = new Token();
     jj_ntk = -1;
@@ -1661,7 +1685,7 @@
   }
 
   /** Constructor with generated Token Manager. */
-  public QueryParser(QueryParserTokenManager tm) {
+  protected QueryParser(QueryParserTokenManager tm) {
     token_source = tm;
     token = new Token();
     jj_ntk = -1;

Modified: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/queryParser/QueryParser.jj
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/queryParser/QueryParser.jj?rev=829134&r1=829133&r2=829134&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/queryParser/QueryParser.jj
(original)
+++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/queryParser/QueryParser.jj
Fri Oct 23 17:18:53 2009
@@ -59,6 +59,7 @@
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.WildcardQuery;
 import org.apache.lucene.util.Parameter;
+import org.apache.lucene.util.Version;
 
 /**
  * This class is generated by JavaCC.  The most important method is
@@ -125,6 +126,14 @@
  * <p><b>NOTE</b>: there is a new QueryParser in contrib, which matches
  * the same syntax as this class, but is more modular,
  * enabling substantial customization to how a query is created.
+ *
+ * <a name="version"/>
+ * <p><b>NOTE</b>: You must specify the required {@link Version}
+ * compatibility when creating QueryParser:
+ * <ul>
+ *    <li> As of 2.9, {@link #setEnablePositionIncrements} is true by
+ *         default.
+ * </ul>
  */
 public class QueryParser {
 
@@ -149,7 +158,7 @@
   boolean lowercaseExpandedTerms = true;
   MultiTermQuery.RewriteMethod multiTermRewriteMethod = MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
   boolean allowLeadingWildcard = false;
-  boolean enablePositionIncrements = false;
+  boolean enablePositionIncrements = true;
 
   Analyzer analyzer;
   String field;
@@ -182,11 +191,27 @@
   /** Constructs a query parser.
    *  @param f  the default field for query terms.
    *  @param a   used to find terms in the query text.
+   *  @deprecated Use {@link #QueryParser(String, Analyzer,
+   *  Version)} instead.
    */
   public QueryParser(String f, Analyzer a) {
+    this(Version.LUCENE_24, f, a);
+  }
+
+  /** Constructs a query parser.
+   *  @param matchVersion  Lucene version to match.  See {@link <a href="#version">above</a>)
+   *  @param f  the default field for query terms.
+   *  @param a   used to find terms in the query text.
+   */
+  public QueryParser(Version matchVersion, String f, Analyzer a) {
     this(new FastCharStream(new StringReader("")));
     analyzer = a;
     field = f;
+    if (matchVersion.onOrAfter(Version.LUCENE_29)) {
+      enablePositionIncrements = true;
+    } else {
+      enablePositionIncrements = false;
+    }
   }
 
   /** Parses a query string, returning a {@link org.apache.lucene.search.Query}.
@@ -1179,7 +1204,7 @@
       System.out.println("Usage: java org.apache.lucene.queryParser.QueryParser <input>");
       System.exit(0);
     }
-    QueryParser qp = new QueryParser("field",
+    QueryParser qp = new QueryParser(Version.LUCENE_CURRENT, "field",
                            new org.apache.lucene.analysis.SimpleAnalyzer());
     Query q = qp.parse(args[0]);
     System.out.println(q.toString("field"));

Modified: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java?rev=829134&r1=829133&r2=829134&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java
(original)
+++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java
Fri Oct 23 17:18:53 2009
@@ -33,6 +33,7 @@
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.WildcardQuery;
 import org.apache.lucene.util.Parameter;
+import org.apache.lucene.util.Version;
 
 /** Token Manager. */
 public class QueryParserTokenManager implements QueryParserConstants

Modified: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/analysis/TestStandardAnalyzer.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/analysis/TestStandardAnalyzer.java?rev=829134&r1=829133&r2=829134&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/analysis/TestStandardAnalyzer.java
(original)
+++ lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/analysis/TestStandardAnalyzer.java
Fri Oct 23 17:18:53 2009
@@ -5,6 +5,7 @@
 import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
 import org.apache.lucene.analysis.tokenattributes.TermAttribute;
 import org.apache.lucene.analysis.tokenattributes.TypeAttribute;
+import org.apache.lucene.util.Version;
 
 import java.io.StringReader;
 
@@ -108,15 +109,24 @@
   }
 
   public void testDomainNames() throws Exception {
-    // Don't reuse a because we alter its state (setReplaceInvalidAcronym)
-    StandardAnalyzer a2 = new StandardAnalyzer();
+    // Don't reuse a because we alter its state
+    // (setReplaceInvalidAcronym)
+
+    // Current lucene should not show the bug
+    StandardAnalyzer a2 = new StandardAnalyzer(Version.LUCENE_CURRENT);
     // domain names
     assertAnalyzesTo(a2, "www.nutch.org", new String[]{"www.nutch.org"});
     //Notice the trailing .  See https://issues.apache.org/jira/browse/LUCENE-1068.
     // the following should be recognized as HOST:
     assertAnalyzesTo(a2, "www.nutch.org.", new String[]{ "www.nutch.org" }, new String[]
{ "<HOST>" });
-    a2.setReplaceInvalidAcronym(false);
+
+    // 2.3 should show the bug
+    a2 = new StandardAnalyzer(Version.LUCENE_23);
     assertAnalyzesTo(a2, "www.nutch.org.", new String[]{ "wwwnutchorg" }, new String[] {
"<ACRONYM>" });
+
+    // 2.4 should not show the bug
+    a2 = new StandardAnalyzer(Version.LUCENE_24);
+    assertAnalyzesTo(a2, "www.nutch.org.", new String[]{ "www.nutch.org" }, new String[]
{ "<HOST>" });
   }
 
   public void testEMailAddresses() throws Exception {

Modified: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/queryParser/TestQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/queryParser/TestQueryParser.java?rev=829134&r1=829133&r2=829134&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/queryParser/TestQueryParser.java
(original)
+++ lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/queryParser/TestQueryParser.java
Fri Oct 23 17:18:53 2009
@@ -47,6 +47,7 @@
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
+import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.MultiTermQuery;
 import org.apache.lucene.search.FuzzyQuery;
@@ -60,7 +61,10 @@
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.WildcardQuery;
 import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.MockRAMDirectory;
 import org.apache.lucene.util.LocalizedTestCase;
+import org.apache.lucene.util.Version;
 
 /**
  * Tests QueryParser.
@@ -1014,4 +1018,49 @@
     BooleanQuery.setMaxClauseCount(originalMaxClauses);
   }
 
+  // LUCENE-2002: make sure defaults for StandardAnalyzer's
+  // enableStopPositionIncr & QueryParser's enablePosIncr
+  // "match"
+  public void testPositionIncrements() throws Exception {
+    Directory dir = new MockRAMDirectory();
+    Analyzer a = new StandardAnalyzer(Version.LUCENE_CURRENT);
+    IndexWriter w = new IndexWriter(dir, a, IndexWriter.MaxFieldLength.UNLIMITED);
+    Document doc = new Document();
+    doc.add(new Field("f", "the wizard of ozzy", Field.Store.NO, Field.Index.ANALYZED));
+    w.addDocument(doc);
+    IndexReader r = w.getReader();
+    w.close();
+    IndexSearcher s = new IndexSearcher(r);
+    QueryParser qp = new QueryParser(Version.LUCENE_CURRENT, "f", a);
+    Query q = qp.parse("\"wizard of ozzy\"");
+    assertEquals(1, s.search(q, 1).totalHits);
+    r.close();
+    dir.close();
+  }
+
+  // LUCENE-2002: when we run javacc to regen QueryParser,
+  // we also run a replaceregexp step to fix 2 of the public
+  // ctors (change them to protected):
+  //
+  //   protected QueryParser(CharStream stream)
+  //
+  //   protected QueryParser(QueryParserTokenManager tm)
+  //
+  // This test is here as a safety, in case that ant step
+  // doesn't work for some reason.
+  public void testProtectedCtors() throws Exception {
+    try {
+      QueryParser.class.getConstructor(new Class[] {CharStream.class});
+      fail("please switch public QueryParser(CharStream) to be protected");
+    } catch (NoSuchMethodException nsme) {
+      // expected
+    }
+    try {
+      QueryParser.class.getConstructor(new Class[] {QueryParserTokenManager.class});
+      fail("please switch public QueryParser(QueryParserTokenManager) to be protected");
+    } catch (NoSuchMethodException nsme) {
+      // expected
+    }
+  }
+
 }



Mime
View raw message