incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject git commit: BLUR:114 fixed.
Date Mon, 03 Jun 2013 15:31:20 GMT
Updated Branches:
  refs/heads/0.1.5 0225159f6 -> 1970012af


BLUR:114 fixed.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/1970012a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/1970012a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/1970012a

Branch: refs/heads/0.1.5
Commit: 1970012af06cc1ee4e665ca187e7f71429fb564a
Parents: 0225159
Author: Gagan <gagandeepjuneja@gmail.com>
Authored: Mon Jun 3 21:00:15 2013 +0530
Committer: Gagan <gagandeepjuneja@gmail.com>
Committed: Mon Jun 3 21:00:15 2013 +0530

----------------------------------------------------------------------
 .../main/java/org/apache/blur/utils/BlurUtil.java  |   25 ++++++++++--
 .../java/org/apache/blur/utils/BlurUtilsTest.java  |   30 +++++++++++++++
 2 files changed, 51 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/1970012a/src/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java b/src/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
index 913a1a0..2323eae 100644
--- a/src/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
+++ b/src/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
@@ -76,10 +76,13 @@ import org.apache.lucene.index.AtomicReader;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.SlowCompositeReaderWrapper;
 import org.apache.lucene.index.Term;
+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.util.RamUsageEstimator;
+import org.apache.lucene.search.BooleanClause;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.KeeperException.Code;
@@ -583,10 +586,24 @@ public class BlurUtil {
   public static List<Document> fetchDocuments(IndexReader reader, Term term,
       ResetableDocumentStoredFieldVisitor fieldSelector, Selector selector) throws IOException
{
     IndexSearcher indexSearcher = new IndexSearcher(reader);
-    int docFreq = reader.docFreq(term);
-    TopDocs topDocs = indexSearcher.search(new TermQuery(term), docFreq);
-    int totalHits = topDocs.totalHits;
-    List<Document> docs = new ArrayList<Document>();
+		int docFreq = reader.docFreq(term);
+		BooleanQuery booleanQueryForFamily = null;
+		BooleanQuery booleanQuery = null;
+		if (selector.getColumnFamiliesToFetchSize() > 0) {
+			booleanQueryForFamily = new BooleanQuery();
+			for (String familyName : selector.getColumnFamiliesToFetch()) {
+				booleanQueryForFamily.add(new TermQuery(new Term(
+						BlurConstants.FAMILY, familyName)),
+						BooleanClause.Occur.SHOULD);
+			}
+			booleanQuery = new BooleanQuery();
+			booleanQuery.add(new TermQuery(term), BooleanClause.Occur.MUST);
+			booleanQuery.add(booleanQueryForFamily, BooleanClause.Occur.MUST);
+		}
+		Query query = booleanQuery == null ? new TermQuery(term) : booleanQuery;
+		TopDocs topDocs = indexSearcher.search(query, docFreq);
+		int totalHits = topDocs.totalHits;
+		List<Document> docs = new ArrayList<Document>();
 
     int start = selector.getStartRecord();
     int end = selector.getMaxRecordsToFetch() + start;

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/1970012a/src/blur-core/src/test/java/org/apache/blur/utils/BlurUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/org/apache/blur/utils/BlurUtilsTest.java b/src/blur-core/src/test/java/org/apache/blur/utils/BlurUtilsTest.java
index bd40b6e..4923862 100644
--- a/src/blur-core/src/test/java/org/apache/blur/utils/BlurUtilsTest.java
+++ b/src/blur-core/src/test/java/org/apache/blur/utils/BlurUtilsTest.java
@@ -24,8 +24,11 @@ import static org.junit.Assert.fail;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.HashSet;
+import java.util.List;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.blur.thrift.generated.Selector;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -38,6 +41,7 @@ import org.apache.lucene.index.CorruptIndexException;
 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.store.LockObtainFailedException;
 import org.apache.lucene.store.RAMDirectory;
 import org.junit.Test;
@@ -156,6 +160,27 @@ public class BlurUtilsTest {
       // Should throw exception
     }
   }
+  
+  @Test
+  public void testFetchDocuments() throws CorruptIndexException, LockObtainFailedException,
IOException{
+	  Selector selector = new Selector();
+	  HashSet<String> columnFamiliesToFetch = new HashSet<String>();
+	  columnFamiliesToFetch.add("f1");
+	  columnFamiliesToFetch.add("f2");
+	  selector.setColumnFamiliesToFetch(columnFamiliesToFetch);
+	  
+	  ResetableDocumentStoredFieldVisitor resetableDocumentStoredFieldVisitor = new ResetableDocumentStoredFieldVisitor();
+	  List<Document> docs = BlurUtil.fetchDocuments(getReader(), new Term("a","b"), resetableDocumentStoredFieldVisitor,
selector);
+	  assertEquals(docs.size(),1);
+  }
+  
+  @Test
+  public void testFetchDocumentsWithoutFamily() throws CorruptIndexException, LockObtainFailedException,
IOException{
+	  Selector selector = new Selector();
+	  ResetableDocumentStoredFieldVisitor resetableDocumentStoredFieldVisitor = new ResetableDocumentStoredFieldVisitor();
+	  List<Document> docs = BlurUtil.fetchDocuments(getReader(), new Term("a","b"), resetableDocumentStoredFieldVisitor,
selector);
+	  assertEquals(docs.size(),2);
+  }
 
   private void rm(File file) {
     if (!file.exists()) {
@@ -181,7 +206,12 @@ public class BlurUtilsTest {
     IndexWriter writer = new IndexWriter(directory, conf);
     Document doc = new Document();
     doc.add(new Field("a", "b", Store.YES, Index.NOT_ANALYZED_NO_NORMS));
+    doc.add(new Field("family", "f1", Store.YES, Index.NOT_ANALYZED_NO_NORMS));
+    
+    Document doc1 = new Document();
+    doc1.add(new Field("a", "b", Store.YES, Index.NOT_ANALYZED_NO_NORMS));
     writer.addDocument(doc);
+    writer.addDocument(doc1);
     writer.close();
     return IndexReader.open(directory);
   }


Mime
View raw message