lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r378052 - /lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestMultiAnalyzer.java
Date Wed, 15 Feb 2006 18:36:01 GMT
Author: yonik
Date: Wed Feb 15 10:36:00 2006
New Revision: 378052

URL: http://svn.apache.org/viewcvs?rev=378052&view=rev
Log:
TestMultiAnalyzer - test subclassing and default phrase slop: LUCENE-483

Modified:
    lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestMultiAnalyzer.java

Modified: lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestMultiAnalyzer.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestMultiAnalyzer.java?rev=378052&r1=378051&r2=378052&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestMultiAnalyzer.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/queryParser/TestMultiAnalyzer.java Wed Feb
15 10:36:00 2006
@@ -20,6 +20,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.lucene.search.Query;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.LowerCaseFilter;
 import org.apache.lucene.analysis.Token;
@@ -79,12 +80,39 @@
     // phrase with non-default boost:
     assertEquals("\"(multi multi2) foo\"^2.0", qp.parse("\"multi foo\"^2").toString());
 
+    // phrase after changing default slop
+    qp.setPhraseSlop(99);
+    assertEquals("\"(multi multi2) foo\"~99 bar",
+                 qp.parse("\"multi foo\" bar").toString());
+    assertEquals("\"(multi multi2) foo\"~99 \"foo bar\"~2",
+                 qp.parse("\"multi foo\" \"foo bar\"~2").toString());
+    qp.setPhraseSlop(0);
+
     // non-default operator:
     qp.setDefaultOperator(QueryParser.AND_OPERATOR);
     assertEquals("+(multi multi2) +foo", qp.parse("multi foo").toString());
 
   }
+    
+  public void testMultiAnalyzerWithSubclassOfQueryParser() throws ParseException {
+
+    DumbQueryParser qp = new DumbQueryParser("", new MultiAnalyzer());
+    qp.setPhraseSlop(99); // modified default slop
 
+    // direct call to (super's) getFieldQuery to demonstrate differnce
+    // between phrase and multiphrase with modified default slop
+    assertEquals("\"foo bar\"~99",
+                 qp.getSuperFieldQuery("","foo bar").toString());
+    assertEquals("\"(multi multi2) bar\"~99",
+                 qp.getSuperFieldQuery("","multi bar").toString());
+
+    
+    // ask sublcass to parse phrase with modified default slop
+    assertEquals("\"(multi multi2) foo\"~99 bar",
+                 qp.parse("\"multi foo\" bar").toString());
+    
+  }
+    
   public void testPosIncrementAnalyzer() throws ParseException {
     QueryParser qp = new QueryParser("", new PosIncrementAnalyzer());
     assertEquals("quick brown", qp.parse("the quick brown").toString());
@@ -190,4 +218,39 @@
     }
   }
 
+    /** a very simple subclass of QueryParser */
+    private final static class DumbQueryParser extends QueryParser {
+        
+        public DumbQueryParser(String f, Analyzer a) {
+            super(f, a);
+        }
+
+        /** expose super's version */
+        public Query getSuperFieldQuery(String f, String t) 
+            throws ParseException {
+            return super.getFieldQuery(f,t);
+        }
+        /** wrap super's version */
+        protected Query getFieldQuery(String f, String t)
+            throws ParseException {
+            return new DumbQueryWrapper(getSuperFieldQuery(f,t));
+        }
+    }
+    
+    /**
+     * A very simple wrapper to prevent instanceof checks but uses
+     * the toString of the query it wraps.
+     */
+    private final static class DumbQueryWrapper extends Query {
+
+        private Query q;
+        public DumbQueryWrapper(Query q) {
+            super();
+            this.q = q;
+        }
+        public String toString(String f) {
+            return q.toString(f);
+        }
+    }
+    
 }



Mime
View raw message