lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r805624 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/search/MatchAllDocsQuery.java src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java
Date Tue, 18 Aug 2009 23:09:18 GMT
Author: markrmiller
Date: Tue Aug 18 23:09:18 2009
New Revision: 805624

URL: http://svn.apache.org/viewvc?rev=805624&view=rev
Log:
LUCENE-1819: MatchAllDocsQuery.toString(field) should produce output that is parsable by the
QueryParser. 

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/search/MatchAllDocsQuery.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=805624&r1=805623&r2=805624&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Aug 18 23:09:18 2009
@@ -490,6 +490,9 @@
 23. LUCENE-1801: Changed all Tokenizers or TokenStreams in core/contrib)
     that are the source of Tokens to always call
     AttributeSource.clearAttributes() first. (Uwe Schindler)
+    
+24. LUCENE-1819: MatchAllDocsQuery.toString(field) should produce output
+    that is parsable by the QueryParser.  (John Wang, Mark Miller)
 
 New features
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/MatchAllDocsQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/MatchAllDocsQuery.java?rev=805624&r1=805623&r2=805624&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/MatchAllDocsQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/MatchAllDocsQuery.java Tue Aug 18
23:09:18 2009
@@ -151,7 +151,7 @@
 
   public String toString(String field) {
     StringBuffer buffer = new StringBuffer();
-    buffer.append("MatchAllDocsQuery");
+    buffer.append("*:*");
     buffer.append(ToStringUtils.boost(getBoost()));
     return buffer.toString();
   }

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java?rev=805624&r1=805623&r2=805624&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java Tue Aug
18 23:09:18 2009
@@ -18,26 +18,30 @@
 
 import java.io.IOException;
 
+import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.document.Document;
 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.queryParser.QueryParser;
 import org.apache.lucene.store.RAMDirectory;
 
 import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.Version;
 
 /**
  * Tests MatchAllDocsQuery.
  *
  */
 public class TestMatchAllDocsQuery extends LuceneTestCase {
-
-  public void testQuery() throws IOException {
+  private Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
+  
+  public void testQuery() throws Exception {
 
     RAMDirectory dir = new RAMDirectory();
-    IndexWriter iw = new IndexWriter(dir, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
+    IndexWriter iw = new IndexWriter(dir, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
     iw.setMaxBufferedDocs(2);  // force multi-segment
     addDoc("one", iw, 1f);
     addDoc("two", iw, 20f);
@@ -95,6 +99,18 @@
     hits = is.search(new MatchAllDocsQuery(), null, 1000).scoreDocs;
     assertEquals(2, hits.length);
     
+    // test parsable toString()
+    QueryParser qp = new QueryParser("key", analyzer);
+    hits = is.search(qp.parse(new MatchAllDocsQuery().toString()), null, 1000).scoreDocs;
+    assertEquals(2, hits.length);
+
+    // test parsable toString() with non default boost
+    Query maq = new MatchAllDocsQuery();
+    maq.setBoost(2.3f);
+    Query pq = qp.parse(maq.toString());
+    hits = is.search(pq, null, 1000).scoreDocs;
+    assertEquals(2, hits.length);
+    
     is.close();
     ir.close();
     dir.close();



Mime
View raw message