incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [1/6] BLUR-ID-64-changed-parser
Date Thu, 11 Apr 2013 03:10:49 GMT
Updated Branches:
  refs/heads/0.1.5 349e8aab6 -> ed6a0f0ff


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c1231e34/src/blur-query/src/test/java/org/apache/blur/lucene/search/SuperQueryTest.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/test/java/org/apache/blur/lucene/search/SuperQueryTest.java
b/src/blur-query/src/test/java/org/apache/blur/lucene/search/SuperQueryTest.java
new file mode 100644
index 0000000..fffb348
--- /dev/null
+++ b/src/blur-query/src/test/java/org/apache/blur/lucene/search/SuperQueryTest.java
@@ -0,0 +1,199 @@
+package org.apache.blur.search;
+
+/**
+ * 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.
+ */
+
+import static junit.framework.Assert.assertEquals;
+import static org.apache.blur.lucene.LuceneVersionConstant.LUCENE_VERSION;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicLongArray;
+
+import org.apache.blur.lucene.search.FacetQuery;
+import org.apache.blur.lucene.search.SuperQuery;
+import org.apache.blur.thrift.generated.ScoreType;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.document.StringField;
+import org.apache.lucene.index.CorruptIndexException;
+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.IndexableField;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause.Occur;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.LockObtainFailedException;
+import org.apache.lucene.store.RAMDirectory;
+import org.junit.Test;
+
+public class SuperQueryTest {
+
+  private static final String PERSON_NAME = "person.name";
+  private static final String ADDRESS_STREET = "address.street";
+
+  private static final String PRIME_DOC = "_p_";
+  private static final String PRIME_DOC_VALUE = "_true_";
+
+  private static final String NAME1 = "jon";
+  private static final String NAME2 = "jane";
+  private static final String STREET2 = "main st";
+  private static final String STREET1 = "main";
+  private static final String ROW_ID = "rowid";
+
+  @Test
+  public void testSimpleSuperQuery() throws CorruptIndexException, IOException, InterruptedException
{
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(wrapSuper(new TermQuery(new Term(PERSON_NAME, NAME1))), Occur.MUST);
+    booleanQuery.add(wrapSuper(new TermQuery(new Term(ADDRESS_STREET, STREET1))), Occur.MUST);
+
+    Directory directory = createIndex();
+    IndexReader reader = DirectoryReader.open(directory);
+
+    IndexSearcher searcher = new IndexSearcher(reader);
+    TopDocs topDocs = searcher.search(booleanQuery, 10);
+    assertEquals(2, topDocs.totalHits);
+    assertEquals("1", searcher.doc(topDocs.scoreDocs[0].doc).get(ROW_ID));
+    assertEquals("3", searcher.doc(topDocs.scoreDocs[1].doc).get(ROW_ID));
+  }
+
+  @Test
+  public void testAggregateScoreTypes() throws Exception {
+    IndexSearcher searcher = createSearcher();
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.AGGREGATE), Occur.SHOULD);
+    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.AGGREGATE), Occur.MUST);
+    TopDocs topDocs = searcher.search(booleanQuery, 10);
+    printTopDocs(topDocs);
+    assertEquals(3, topDocs.totalHits);
+  }
+
+  @Test
+  public void testBestScoreTypes() throws Exception {
+    IndexSearcher searcher = createSearcher();
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.BEST), Occur.SHOULD);
+    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.BEST), Occur.MUST);
+    TopDocs topDocs = searcher.search(booleanQuery, 10);
+    assertEquals(3, topDocs.totalHits);
+    printTopDocs(topDocs);
+  }
+
+  private void printTopDocs(TopDocs topDocs) {
+    for (int i = 0; i < topDocs.totalHits; i++) {
+      System.out.println("doc " + i + " score " + topDocs.scoreDocs[i].score);
+    }
+
+  }
+
+  @Test
+  public void testConstantScoreTypes() throws Exception {
+    IndexSearcher searcher = createSearcher();
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.CONSTANT), Occur.SHOULD);
+    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.CONSTANT), Occur.MUST);
+    TopDocs topDocs = searcher.search(booleanQuery, 10);
+    assertEquals(3, topDocs.totalHits);
+    printTopDocs(topDocs);
+  }
+
+  @Test
+  public void testSuperScoreTypes() throws Exception {
+    IndexSearcher searcher = createSearcher();
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.SUPER), Occur.SHOULD);
+    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.SUPER), Occur.MUST);
+    TopDocs topDocs = searcher.search(booleanQuery, 10);
+    assertEquals(3, topDocs.totalHits);
+    printTopDocs(topDocs);
+  }
+
+  @Test
+  public void testSuperScoreTypesWithFacet() throws Exception {
+    IndexSearcher searcher = createSearcher();
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.SUPER), Occur.SHOULD);
+    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.SUPER), Occur.MUST);
+
+    BooleanQuery f1 = new BooleanQuery();
+    f1.add(new TermQuery(new Term(PERSON_NAME, NAME1)), Occur.MUST);
+    f1.add(new TermQuery(new Term(PERSON_NAME, NAME2)), Occur.MUST);
+
+    Query[] facets = new Query[] { new SuperQuery(f1, ScoreType.CONSTANT, new Term(PRIME_DOC,
PRIME_DOC_VALUE)) };
+    AtomicLongArray counts = new AtomicLongArray(facets.length);
+    FacetQuery query = new FacetQuery(booleanQuery, facets, counts);
+
+    TopDocs topDocs = searcher.search(query, 10);
+    assertEquals(3, topDocs.totalHits);
+    printTopDocs(topDocs);
+  }
+
+  private static IndexSearcher createSearcher() throws Exception {
+    Directory directory = createIndex();
+    IndexReader reader = DirectoryReader.open(directory);
+    return new IndexSearcher(reader);
+  }
+
+  public static Directory createIndex() throws CorruptIndexException, LockObtainFailedException,
IOException {
+    Directory directory = new RAMDirectory();
+    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(LUCENE_VERSION,
new StandardAnalyzer(LUCENE_VERSION)));
+    writer.addDocuments(addPrime(Arrays.asList(newDocument(newStringField(ROW_ID, "1"), newStringField(PERSON_NAME,
NAME1)),
+        newDocument(newStringField(ROW_ID, "1"), newStringField(PERSON_NAME, NAME1)), newDocument(newStringField(ROW_ID,
"1"), newStringField(ADDRESS_STREET, STREET1)))));
+    writer.addDocuments(addPrime(Arrays.asList(newDocument(newStringField(ROW_ID, "2"), newStringField(PERSON_NAME,
NAME2)),
+        newDocument(newStringField(ROW_ID, "2"), newStringField(ADDRESS_STREET, STREET1)))));
+    writer.addDocuments(addPrime(Arrays.asList(newDocument(newStringField(ROW_ID, "3"), newStringField(PERSON_NAME,
NAME1)),
+        newDocument(newStringField(ROW_ID, "3"), newStringField(ADDRESS_STREET, STREET1)),
newDocument(newStringField(ROW_ID, "3"), newStringField(ADDRESS_STREET, STREET2)))));
+    writer.close();
+    return directory;
+  }
+
+  private static List<Document> addPrime(List<Document> docs) {
+    Document document = docs.get(0);
+    document.add(new StringField(PRIME_DOC, PRIME_DOC_VALUE, Store.NO));
+    return docs;
+  }
+
+  private static Document newDocument(IndexableField... fields) {
+    Document document = new Document();
+    for (IndexableField field : fields) {
+      document.add(field);
+    }
+    return document;
+  }
+
+  private static IndexableField newStringField(String name, String value) {
+    return new StringField(name, value, Store.YES);
+  }
+
+  private Query wrapSuper(Query query) {
+    return new SuperQuery(query, ScoreType.AGGREGATE, new Term(PRIME_DOC, PRIME_DOC_VALUE));
+  }
+
+  private Query wrapSuper(String field, String value, ScoreType scoreType) {
+    return new SuperQuery(new TermQuery(new Term(field, value)), scoreType, new Term(PRIME_DOC,
PRIME_DOC_VALUE));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c1231e34/src/blur-query/src/test/java/org/apache/blur/lucene/search/TestingPagingCollector.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/test/java/org/apache/blur/lucene/search/TestingPagingCollector.java
b/src/blur-query/src/test/java/org/apache/blur/lucene/search/TestingPagingCollector.java
new file mode 100644
index 0000000..5eaad3f
--- /dev/null
+++ b/src/blur-query/src/test/java/org/apache/blur/lucene/search/TestingPagingCollector.java
@@ -0,0 +1,84 @@
+package org.apache.blur.search;
+
+/**
+ * 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.
+ */
+
+import static org.apache.blur.lucene.LuceneVersionConstant.LUCENE_VERSION;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.blur.lucene.search.IterablePaging;
+import org.apache.blur.lucene.search.IterablePaging.ProgressRef;
+import org.apache.blur.lucene.search.IterablePaging.TotalHitsRef;
+import org.apache.lucene.analysis.core.KeywordAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.Field.Index;
+import org.apache.lucene.document.Field.Store;
+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.IndexSearcher;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.store.RAMDirectory;
+import org.junit.Test;
+
+/**
+ * Testing the paging collector.
+ * 
+ * @author Aaron McCurry
+ */
+public class TestingPagingCollector {
+
+  @Test
+  public void testNothingYet() {
+
+  }
+
+  public static void main(String[] args) throws Exception {
+    IndexReader reader = getReaderFlatScore(13245);
+    IndexSearcher searcher = new IndexSearcher(reader);
+
+    TotalHitsRef totalHitsRef = new TotalHitsRef();
+    ProgressRef progressRef = new ProgressRef();
+
+    TermQuery query = new TermQuery(new Term("f1", "value"));
+    IterablePaging paging = new IterablePaging(new AtomicBoolean(true), searcher, query,
100, null, null);
+
+    for (ScoreDoc sd : paging.skipTo(90).gather(20).totalHits(totalHitsRef).progress(progressRef))
{
+
+      System.out.println("time [" + progressRef.queryTime() + "] " + "total hits [" + totalHitsRef.totalHits()
+ "] "
+          + "searches [" + progressRef.searchesPerformed() + "] " + "position [" + progressRef.currentHitPosition()
+          + "] " + "doc id [" + sd.doc + "] " + "score [" + sd.score + "]");
+    }
+  }
+
+  private static IndexReader getReaderFlatScore(int length) throws Exception {
+    RAMDirectory directory = new RAMDirectory();
+    IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(LUCENE_VERSION,
new KeywordAnalyzer()));
+    for (int i = 0; i < length; i++) {
+      Document document = new Document();
+      document.add(new Field("f1", "value", Store.NO, Index.ANALYZED_NO_NORMS));
+      indexWriter.addDocument(document);
+    }
+    indexWriter.close();
+    return IndexReader.open(directory);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c1231e34/src/blur-query/src/test/java/org/apache/blur/search/RandomSuperQueryTest.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/test/java/org/apache/blur/search/RandomSuperQueryTest.java
b/src/blur-query/src/test/java/org/apache/blur/search/RandomSuperQueryTest.java
index bfb5952..707916c 100644
--- a/src/blur-query/src/test/java/org/apache/blur/search/RandomSuperQueryTest.java
+++ b/src/blur-query/src/test/java/org/apache/blur/search/RandomSuperQueryTest.java
@@ -29,7 +29,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Random;
 
-import org.apache.blur.lucene.search.ScoreType;
+import org.apache.blur.thrift.generated.ScoreType;
 import org.apache.blur.lucene.search.SuperQuery;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.document.Document;

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c1231e34/src/blur-query/src/test/java/org/apache/blur/search/SuperQueryTest.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/test/java/org/apache/blur/search/SuperQueryTest.java b/src/blur-query/src/test/java/org/apache/blur/search/SuperQueryTest.java
index 5eaf8b2..fffb348 100644
--- a/src/blur-query/src/test/java/org/apache/blur/search/SuperQueryTest.java
+++ b/src/blur-query/src/test/java/org/apache/blur/search/SuperQueryTest.java
@@ -26,8 +26,8 @@ import java.util.List;
 import java.util.concurrent.atomic.AtomicLongArray;
 
 import org.apache.blur.lucene.search.FacetQuery;
-import org.apache.blur.lucene.search.ScoreType;
 import org.apache.blur.lucene.search.SuperQuery;
+import org.apache.blur.thrift.generated.ScoreType;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field.Store;

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c1231e34/src/blur-query/src/test/java/org/apache/blur/search/TestingPagingCollector.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/test/java/org/apache/blur/search/TestingPagingCollector.java
b/src/blur-query/src/test/java/org/apache/blur/search/TestingPagingCollector.java
new file mode 100644
index 0000000..5eaad3f
--- /dev/null
+++ b/src/blur-query/src/test/java/org/apache/blur/search/TestingPagingCollector.java
@@ -0,0 +1,84 @@
+package org.apache.blur.search;
+
+/**
+ * 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.
+ */
+
+import static org.apache.blur.lucene.LuceneVersionConstant.LUCENE_VERSION;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.blur.lucene.search.IterablePaging;
+import org.apache.blur.lucene.search.IterablePaging.ProgressRef;
+import org.apache.blur.lucene.search.IterablePaging.TotalHitsRef;
+import org.apache.lucene.analysis.core.KeywordAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.Field.Index;
+import org.apache.lucene.document.Field.Store;
+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.IndexSearcher;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.store.RAMDirectory;
+import org.junit.Test;
+
+/**
+ * Testing the paging collector.
+ * 
+ * @author Aaron McCurry
+ */
+public class TestingPagingCollector {
+
+  @Test
+  public void testNothingYet() {
+
+  }
+
+  public static void main(String[] args) throws Exception {
+    IndexReader reader = getReaderFlatScore(13245);
+    IndexSearcher searcher = new IndexSearcher(reader);
+
+    TotalHitsRef totalHitsRef = new TotalHitsRef();
+    ProgressRef progressRef = new ProgressRef();
+
+    TermQuery query = new TermQuery(new Term("f1", "value"));
+    IterablePaging paging = new IterablePaging(new AtomicBoolean(true), searcher, query,
100, null, null);
+
+    for (ScoreDoc sd : paging.skipTo(90).gather(20).totalHits(totalHitsRef).progress(progressRef))
{
+
+      System.out.println("time [" + progressRef.queryTime() + "] " + "total hits [" + totalHitsRef.totalHits()
+ "] "
+          + "searches [" + progressRef.searchesPerformed() + "] " + "position [" + progressRef.currentHitPosition()
+          + "] " + "doc id [" + sd.doc + "] " + "score [" + sd.score + "]");
+    }
+  }
+
+  private static IndexReader getReaderFlatScore(int length) throws Exception {
+    RAMDirectory directory = new RAMDirectory();
+    IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(LUCENE_VERSION,
new KeywordAnalyzer()));
+    for (int i = 0; i < length; i++) {
+      Document document = new Document();
+      document.add(new Field("f1", "value", Store.NO, Index.ANALYZED_NO_NORMS));
+      indexWriter.addDocument(document);
+    }
+    indexWriter.close();
+    return IndexReader.open(directory);
+  }
+
+}


Mime
View raw message