Permalink
Browse files

fix wrong handling of doc ids to load when request is not serialized

  • Loading branch information...
1 parent cd08a71 commit 9549b9c2d3cd4151a03bacebea13b96b19478291 @kimchy kimchy committed Apr 9, 2010
View
@@ -66,6 +66,9 @@ task explodedDist(dependsOn: [configurations.distLib], description: 'Builds a mi
include 'README.textile'
}
+ ant.delete { fileset(dir: explodedDistLibDir, includes: "$archivesBaseName-*-javadoc.jar") }
+ ant.delete { fileset(dir: explodedDistLibDir, includes: "$archivesBaseName-*-sources.jar") }
+
ant.chmod(dir: "$explodedDistDir/bin", perm: "ugo+rx", includes: "**/*")
}
@@ -59,7 +59,6 @@
import org.elasticsearch.util.timer.TimerTask;
import java.io.IOException;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@@ -260,7 +259,7 @@ public QueryFetchSearchResult executeFetchPhase(InternalScrollSearchRequest requ
public FetchSearchResult executeFetchPhase(FetchSearchRequest request) throws ElasticSearchException {
SearchContext context = findContext(request.id());
try {
- context.docIdsToLoad(request.docIds());
+ context.docIdsToLoad(request.docIds(), 0, request.docIdsSize());
fetchPhase.execute(context);
if (context.scroll() == null) {
freeContext(request.id());
@@ -366,7 +365,7 @@ private void shortcutDocIdsToLoad(SearchContext context) {
TopDocs topDocs = context.queryResult().topDocs();
if (topDocs.scoreDocs.length < context.from()) {
// no more docs...
- context.docIdsToLoad(EMPTY_DOC_IDS);
+ context.docIdsToLoad(EMPTY_DOC_IDS, 0, 0);
return;
}
int totalSize = context.from() + context.size();
@@ -380,10 +379,7 @@ private void shortcutDocIdsToLoad(SearchContext context) {
}
counter++;
}
- if (counter < context.size()) {
- docIdsToLoad = Arrays.copyOfRange(docIdsToLoad, 0, counter);
- }
- context.docIdsToLoad(docIdsToLoad);
+ context.docIdsToLoad(docIdsToLoad, 0, counter);
}
private void processScroll(InternalScrollSearchRequest request, SearchContext context) {
@@ -139,7 +139,7 @@ public AggregatedDfs aggregateDfs(Iterable<DfsSearchResult> results) {
for (ShardDoc shardDoc : shardDocs) {
ExtTIntArrayList list = result.get(shardDoc.shardTarget());
if (list == null) {
- list = new ExtTIntArrayList();
+ list = new ExtTIntArrayList(); // can't be shared!, uses unsafe on it later on
result.put(shardDoc.shardTarget(), list);
}
list.add(shardDoc.docId());
@@ -65,9 +65,10 @@
public void execute(SearchContext context) {
FieldSelector fieldSelector = buildFieldSelectors(context);
- InternalSearchHit[] hits = new InternalSearchHit[context.docIdsToLoad().length];
+ InternalSearchHit[] hits = new InternalSearchHit[context.docIdsToLoadSize()];
int index = 0;
- for (int docId : context.docIdsToLoad()) {
+ for (int docIdIdx = context.docIdsToLoadFrom(); docIdIdx < context.docIdsToLoadSize(); docIdIdx++) {
+ int docId = context.docIdsToLoad()[docIdIdx];
Document doc = loadDocument(context, fieldSelector, docId);
Uid uid = extractUid(context, doc);
@@ -27,15 +27,15 @@
import java.io.IOException;
/**
- * @author kimchy (Shay Banon)
+ * @author kimchy (shay.banon)
*/
public class FetchSearchRequest implements Streamable {
private long id;
private int[] docIds;
- private transient int size;
+ private int size;
public FetchSearchRequest() {
}
@@ -60,11 +60,15 @@ public long id() {
return docIds;
}
+ public int docIdsSize() {
+ return size;
+ }
+
@Override public void readFrom(StreamInput in) throws IOException {
id = in.readLong();
size = in.readVInt();
docIds = new int[size];
- for (int i = 0; i < docIds.length; i++) {
+ for (int i = 0; i < size; i++) {
docIds[i] = in.readVInt();
}
}
@@ -90,6 +90,10 @@
private int[] docIdsToLoad;
+ private int docsIdsToLoadFrom;
+
+ private int docsIdsToLoadSize;
+
private SearchContextFacets facets;
private SearchContextHighlight highlight;
@@ -295,8 +299,18 @@ public SearchContext rewriteQuery() throws IOException {
return docIdsToLoad;
}
- public SearchContext docIdsToLoad(int[] docIdsToLoad) {
+ public int docIdsToLoadFrom() {
+ return docsIdsToLoadFrom;
+ }
+
+ public int docIdsToLoadSize() {
+ return docsIdsToLoadSize;
+ }
+
+ public SearchContext docIdsToLoad(int[] docIdsToLoad, int docsIdsToLoadFrom, int docsIdsToLoadSize) {
this.docIdsToLoad = docIdsToLoad;
+ this.docsIdsToLoadFrom = docsIdsToLoadFrom;
+ this.docsIdsToLoadSize = docsIdsToLoadSize;
return this;
}

0 comments on commit 9549b9c

Please sign in to comment.