Small code cleanup and formatting.
Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/23408a05 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/23408a05 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/23408a05 Branch: refs/heads/master Commit: 23408a05fff4a5a4c546cbe1c6eb05e7d4f7cfc2 Parents: c448cca Author: Aaron McCurry <[email protected]> Authored: Mon Aug 12 11:13:41 2013 -0400 Committer: Aaron McCurry <[email protected]> Committed: Mon Aug 12 11:13:41 2013 -0400 ---------------------------------------------------------------------- .../java/org/apache/blur/utils/BlurUtil.java | 81 +++++++++++--------- .../apache/blur/thrift/generated/Selector.java | 4 +- .../apache/blur/thrift/generated/Selector.java | 4 +- 3 files changed, 49 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/23408a05/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java b/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java index 9c9c85d..7919bc5 100644 --- a/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java +++ b/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java @@ -734,59 +734,68 @@ public class BlurUtil { throws IOException { IndexSearcher indexSearcher = new IndexSearcher(reader); int docFreq = reader.docFreq(term); - + int start = selector.getStartRecord(); int end = selector.getMaxRecordsToFetch() + start; - + + // remove potential duplicates provided from the client + List<String> families = new ArrayList<String>(); + if (selector.getColumnFamiliesToFetch() != null) { + for (String family : selector.getColumnFamiliesToFetch()) { + if (!families.contains(family)) { + families.add(family); + } + } + } + List<Document> docs = new ArrayList<Document>(); List<ScoreDoc> scoreDocs = new ArrayList<ScoreDoc>(); int count = 0; int totalHits = 0; - while (scoreDocs.size() < end ){ - Query query = getQuery(term, selector, count++); - if(query == null){ - break; - } - TopDocs topDocs = indexSearcher.search(query, docFreq); - totalHits += topDocs.totalHits; - scoreDocs.addAll(Arrays.asList(topDocs.scoreDocs)); - topDocs = null; - } - + while (scoreDocs.size() < end) { + Query query = getQuery(term, families, count++); + if (query == null) { + break; + } + TopDocs topDocs = indexSearcher.search(query, docFreq); + totalHits += topDocs.totalHits; + scoreDocs.addAll(Arrays.asList(topDocs.scoreDocs)); + topDocs = null; + } + int totalHeap = 0; for (int i = start; i < end; i++) { - if (i >= totalHits) { - break; - } - if (totalHeap >= maxHeap) { - LOG.warn("Max heap size exceeded for this request [{0}] max [{1}] for [{2}] and rowid [{3}]", totalHeap, + if (i >= totalHits) { + break; + } + if (totalHeap >= maxHeap) { + LOG.warn("Max heap size exceeded for this request [{0}] max [{1}] for [{2}] and rowid [{3}]", totalHeap, maxHeap, context, term.text()); - break; - } - int doc = scoreDocs.get(i).doc; - indexSearcher.doc(doc, fieldSelector); - docs.add(fieldSelector.getDocument()); - int heapSize = fieldSelector.getSize(); - totalHeap += heapSize; - fieldSelector.reset(); - } + break; + } + int doc = scoreDocs.get(i).doc; + indexSearcher.doc(doc, fieldSelector); + docs.add(fieldSelector.getDocument()); + int heapSize = fieldSelector.getSize(); + totalHeap += heapSize; + fieldSelector.reset(); + } return docs; } -private static Query getQuery(Term term, - Selector selector, int index) { + private static Query getQuery(Term term, List<String> families, int index) { BooleanQuery booleanQuery = null; - int familySize = selector.getColumnFamiliesToFetchSize(); - if ( familySize > 0 && index < familySize) { + int familySize = families.size(); + if (familySize > 0 && index < familySize) { booleanQuery = new BooleanQuery(); booleanQuery.add(new TermQuery(term), BooleanClause.Occur.MUST); - booleanQuery.add(new TermQuery(new Term(BlurConstants.FAMILY, selector.getColumnFamiliesToFetch().get(index))), BooleanClause.Occur.MUST); + booleanQuery.add(new TermQuery(new Term(BlurConstants.FAMILY, families.get(index))), BooleanClause.Occur.MUST); } - if (booleanQuery == null && index == 0){ - return new TermQuery(term); + if (booleanQuery == null && index == 0) { + return new TermQuery(term); } - return booleanQuery; -} + return booleanQuery; + } public static AtomicReader getAtomicReader(IndexReader reader) throws IOException { return SlowCompositeReaderWrapper.wrap(reader); http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/23408a05/blur-thrift/src/main/java/org/apache/blur/thrift/generated/Selector.java ---------------------------------------------------------------------- diff --git a/blur-thrift/src/main/java/org/apache/blur/thrift/generated/Selector.java b/blur-thrift/src/main/java/org/apache/blur/thrift/generated/Selector.java index dbce74f..3a0f81b 100644 --- a/blur-thrift/src/main/java/org/apache/blur/thrift/generated/Selector.java +++ b/blur-thrift/src/main/java/org/apache/blur/thrift/generated/Selector.java @@ -1281,7 +1281,7 @@ public class Selector implements org.apache.blur.thirdparty.thrift_0_9_0.TBase<S for (int _i20 = 0; _i20 < _map19.size; ++_i20) { String _key21; // required - Set<String> _val22; // required + Set<String> _val22; // optional _key21 = iprot.readString(); { org.apache.blur.thirdparty.thrift_0_9_0.protocol.TSet _set23 = iprot.readSetBegin(); @@ -1555,7 +1555,7 @@ public class Selector implements org.apache.blur.thirdparty.thrift_0_9_0.TBase<S for (int _i36 = 0; _i36 < _map35.size; ++_i36) { String _key37; // required - Set<String> _val38; // required + Set<String> _val38; // optional _key37 = iprot.readString(); { org.apache.blur.thirdparty.thrift_0_9_0.protocol.TSet _set39 = new org.apache.blur.thirdparty.thrift_0_9_0.protocol.TSet(org.apache.blur.thirdparty.thrift_0_9_0.protocol.TType.STRING, iprot.readI32()); http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/23408a05/distribution/src/main/scripts/interface/gen-java/org/apache/blur/thrift/generated/Selector.java ---------------------------------------------------------------------- diff --git a/distribution/src/main/scripts/interface/gen-java/org/apache/blur/thrift/generated/Selector.java b/distribution/src/main/scripts/interface/gen-java/org/apache/blur/thrift/generated/Selector.java index dbce74f..3a0f81b 100644 --- a/distribution/src/main/scripts/interface/gen-java/org/apache/blur/thrift/generated/Selector.java +++ b/distribution/src/main/scripts/interface/gen-java/org/apache/blur/thrift/generated/Selector.java @@ -1281,7 +1281,7 @@ public class Selector implements org.apache.blur.thirdparty.thrift_0_9_0.TBase<S for (int _i20 = 0; _i20 < _map19.size; ++_i20) { String _key21; // required - Set<String> _val22; // required + Set<String> _val22; // optional _key21 = iprot.readString(); { org.apache.blur.thirdparty.thrift_0_9_0.protocol.TSet _set23 = iprot.readSetBegin(); @@ -1555,7 +1555,7 @@ public class Selector implements org.apache.blur.thirdparty.thrift_0_9_0.TBase<S for (int _i36 = 0; _i36 < _map35.size; ++_i36) { String _key37; // required - Set<String> _val38; // required + Set<String> _val38; // optional _key37 = iprot.readString(); { org.apache.blur.thirdparty.thrift_0_9_0.protocol.TSet _set39 = new org.apache.blur.thirdparty.thrift_0_9_0.protocol.TSet(org.apache.blur.thirdparty.thrift_0_9_0.protocol.TType.STRING, iprot.readI32());
