lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <luc...@mikemccandless.com>
Subject Re: svn commit: r1397282 - in /lucene/dev/trunk/lucene: analysis/common/src/test/org/apache/lucene/analysis/standard/TestStandardFactories.java core/src/test/org/apache/lucene/search/TestBooleanQuery.java
Date Thu, 11 Oct 2012 21:29:21 GMT
Woops, no!  I'll fix ...

Mike McCandless

http://blog.mikemccandless.com


On Thu, Oct 11, 2012 at 5:06 PM, Robert Muir <rcmuir@gmail.com> wrote:
> Did you intend to also commit the original test to TestStandardFactories?
>
> On Thu, Oct 11, 2012 at 4:22 PM,  <mikemccand@apache.org> wrote:
>> Author: mikemccand
>> Date: Thu Oct 11 20:22:14 2012
>> New Revision: 1397282
>>
>> URL: http://svn.apache.org/viewvc?rev=1397282&view=rev
>> Log:
>> LUCENE-4477/LUCENE-4401: add test case
>>
>> Modified:
>>     lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/standard/TestStandardFactories.java
>>     lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java
>>
>> Modified: lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/standard/TestStandardFactories.java
>> URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/standard/TestStandardFactories.java?rev=1397282&r1=1397281&r2=1397282&view=diff
>> ==============================================================================
>> --- lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/standard/TestStandardFactories.java
(original)
>> +++ lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/standard/TestStandardFactories.java
Thu Oct 11 20:22:14 2012
>> @@ -17,12 +17,14 @@ package org.apache.lucene.analysis.stand
>>   * limitations under the License.
>>   */
>>
>> +import java.io.IOException;
>>  import java.io.Reader;
>>  import java.io.StringReader;
>>  import java.util.Collections;
>>  import java.util.HashMap;
>>  import java.util.Map;
>>
>> +import org.apache.lucene.analysis.Analyzer;
>>  import org.apache.lucene.analysis.BaseTokenStreamTestCase;
>>  import org.apache.lucene.analysis.MockTokenizer;
>>  import org.apache.lucene.analysis.TokenStream;
>> @@ -32,6 +34,23 @@ import org.apache.lucene.analysis.core.L
>>  import org.apache.lucene.analysis.core.LowerCaseTokenizerFactory;
>>  import org.apache.lucene.analysis.core.WhitespaceTokenizerFactory;
>>  import org.apache.lucene.analysis.miscellaneous.ASCIIFoldingFilterFactory;
>> +import org.apache.lucene.analysis.util.CharArraySet;
>> +import org.apache.lucene.document.Document;
>> +import org.apache.lucene.document.Field;
>> +import org.apache.lucene.document.TextField;
>> +import org.apache.lucene.index.DirectoryReader;
>> +import org.apache.lucene.index.IndexReader;
>> +import org.apache.lucene.index.IndexWriter;
>> +import org.apache.lucene.index.IndexWriterConfig;
>> +import org.apache.lucene.index.Term;
>> +import org.apache.lucene.search.BooleanClause;
>> +import org.apache.lucene.search.BooleanQuery;
>> +import org.apache.lucene.search.IndexSearcher;
>> +import org.apache.lucene.search.ScoreDoc;
>> +import org.apache.lucene.search.TopScoreDocCollector;
>> +import org.apache.lucene.search.spans.SpanQuery;
>> +import org.apache.lucene.search.spans.SpanTermQuery;
>> +import org.apache.lucene.store.Directory;
>>
>>  /**
>>   * Simple tests to ensure the standard lucene factories are working.
>> @@ -188,4 +207,48 @@ public class TestStandardFactories exten
>>      TokenStream stream = factory.create(tokenizer);
>>      assertTokenStreamContents(stream, new String[] { "Ceska" });
>>    }
>> +
>> +  public void testBooleanSpanQuery() throws Exception {
>> +    boolean failed = false;
>> +    int hits = 0;
>> +    Directory directory = newDirectory();
>> +    try{
>> +      CharArraySet stops = CharArraySet.EMPTY_SET;
>> +      Analyzer indexerAnalyzer = new StandardAnalyzer(TEST_VERSION_CURRENT, stops);
>> +      //Analyzer indexerAnalyzer = new MockAnalyzer(LuceneProjectVersion.LUCENE_VERSION);
>> +      //Directory directory = new RAMDirectory();
>> +
>> +      IndexWriterConfig config = new IndexWriterConfig(TEST_VERSION_CURRENT, indexerAnalyzer);
>> +      IndexWriter writer = new IndexWriter(directory, config);
>> +      String FIELD = "content";
>> +      Document d = new Document();
>> +      d.add(new TextField(FIELD, "clockwork orange", Field.Store.YES));
>> +      writer.addDocument(d);
>> +      writer.close();
>> +
>> +      IndexReader indexReader = DirectoryReader.open(directory);
>> +      IndexSearcher searcher = new IndexSearcher(indexReader);
>> +
>> +      BooleanQuery query = new BooleanQuery();
>> +      SpanQuery sq1 = new SpanTermQuery(new Term(FIELD, "clockwork"));
>> +      SpanQuery sq2 = new SpanTermQuery(new Term(FIELD, "clckwork"));
>> +      query.add(sq1, BooleanClause.Occur.SHOULD);
>> +      query.add(sq2, BooleanClause.Occur.SHOULD);
>> +      TopScoreDocCollector collector = TopScoreDocCollector.create(1000, true);
>> +      searcher.search(query, collector);
>> +      hits = collector.topDocs().scoreDocs.length;
>> +      for (ScoreDoc scoreDoc : collector.topDocs().scoreDocs){
>> +        System.out.println(scoreDoc.doc);
>> +      }
>> +      indexReader.close();
>> +    } catch (java.lang.ArrayIndexOutOfBoundsException e){
>> +      failed = true;
>> +    } catch (IOException e){
>> +
>> +      e.printStackTrace();
>> +    }
>> +    assertEquals("Bug in boolean query composed of span queries", failed, false);
>> +    assertEquals("Bug in boolean query composed of span queries", hits, 1);
>> +    directory.close();
>> +  }
>>  }
>>
>> Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java
>> URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java?rev=1397282&r1=1397281&r2=1397282&view=diff
>> ==============================================================================
>> --- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java
(original)
>> +++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java
Thu Oct 11 20:22:14 2012
>> @@ -24,14 +24,21 @@ import java.util.concurrent.ExecutorServ
>>  import java.util.concurrent.Executors;
>>  import java.util.concurrent.TimeUnit;
>>
>> +import org.apache.lucene.analysis.Analyzer;
>> +import org.apache.lucene.analysis.MockAnalyzer;
>>  import org.apache.lucene.document.Document;
>>  import org.apache.lucene.document.Field;
>>  import org.apache.lucene.document.TextField;
>> +import org.apache.lucene.index.DirectoryReader;
>>  import org.apache.lucene.index.IndexReader;
>> +import org.apache.lucene.index.IndexWriter;
>> +import org.apache.lucene.index.IndexWriterConfig;
>>  import org.apache.lucene.index.MultiReader;
>>  import org.apache.lucene.index.RandomIndexWriter;
>>  import org.apache.lucene.index.Term;
>>  import org.apache.lucene.search.similarities.DefaultSimilarity;
>> +import org.apache.lucene.search.spans.SpanQuery;
>> +import org.apache.lucene.search.spans.SpanTermQuery;
>>  import org.apache.lucene.store.Directory;
>>  import org.apache.lucene.util.LuceneTestCase;
>>  import org.apache.lucene.util.NamedThreadFactory;
>> @@ -283,4 +290,40 @@ public class TestBooleanQuery extends Lu
>>      r.close();
>>      d.close();
>>    }
>> +
>> +  // LUCENE-4477 / LUCENE-4401:
>> +  public void testBooleanSpanQuery() throws Exception {
>> +    boolean failed = false;
>> +    int hits = 0;
>> +    Directory directory = newDirectory();
>> +    Analyzer indexerAnalyzer = new MockAnalyzer(random());
>> +
>> +    IndexWriterConfig config = new IndexWriterConfig(TEST_VERSION_CURRENT, indexerAnalyzer);
>> +    IndexWriter writer = new IndexWriter(directory, config);
>> +    String FIELD = "content";
>> +    Document d = new Document();
>> +    d.add(new TextField(FIELD, "clockwork orange", Field.Store.YES));
>> +    writer.addDocument(d);
>> +    writer.close();
>> +
>> +    IndexReader indexReader = DirectoryReader.open(directory);
>> +    IndexSearcher searcher = new IndexSearcher(indexReader);
>> +
>> +    BooleanQuery query = new BooleanQuery();
>> +    SpanQuery sq1 = new SpanTermQuery(new Term(FIELD, "clockwork"));
>> +    SpanQuery sq2 = new SpanTermQuery(new Term(FIELD, "clckwork"));
>> +    query.add(sq1, BooleanClause.Occur.SHOULD);
>> +    query.add(sq2, BooleanClause.Occur.SHOULD);
>> +    TopScoreDocCollector collector = TopScoreDocCollector.create(1000, true);
>> +    searcher.search(query, collector);
>> +    hits = collector.topDocs().scoreDocs.length;
>> +    for (ScoreDoc scoreDoc : collector.topDocs().scoreDocs){
>> +      System.out.println(scoreDoc.doc);
>> +    }
>> +    indexReader.close();
>> +    assertEquals("Bug in boolean query composed of span queries", failed, false);
>> +    assertEquals("Bug in boolean query composed of span queries", hits, 1);
>> +    directory.close();
>> +  }
>> +
>>  }
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: dev-help@lucene.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


Mime
View raw message