From 8285ffe22175bf4592e79bb881a6451741ccdac8 Mon Sep 17 00:00:00 2001 From: kimchy Date: Sun, 28 Nov 2010 02:23:38 +0200 Subject: [PATCH] encode scroll id with base64 in url safe manner --- .../type/TransportSearchDfsQueryAndFetchAction.java | 2 +- .../type/TransportSearchDfsQueryThenFetchAction.java | 2 +- .../action/search/type/TransportSearchHelper.java | 8 ++++---- .../search/type/TransportSearchQueryAndFetchAction.java | 2 +- .../search/type/TransportSearchQueryThenFetchAction.java | 2 +- .../action/search/type/TransportSearchTypeAction.java | 2 +- .../main/java/org/elasticsearch/common/lucene/Lucene.java | 4 +++- 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryAndFetchAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryAndFetchAction.java index 28b54618155..8ce4ff9f520 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryAndFetchAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryAndFetchAction.java @@ -163,7 +163,7 @@ public class TransportSearchDfsQueryAndFetchAction extends TransportSearchTypeAc } } - private void innerFinishHim() { + private void innerFinishHim() throws Exception { sortedShardList = searchPhaseController.sortDocs(queryFetchResults.values()); final InternalSearchResponse internalResponse = searchPhaseController.merge(sortedShardList, queryFetchResults, queryFetchResults); String scrollId = null; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java index 6e906e9bab4..2d22196e128 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java @@ -258,7 +258,7 @@ public class TransportSearchDfsQueryThenFetchAction extends TransportSearchTypeA } } - private void innerFinishHim() { + private void innerFinishHim() throws Exception { final InternalSearchResponse internalResponse = searchPhaseController.merge(sortedShardList, queryResults, fetchResults); String scrollId = null; if (request.scroll() != null) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchHelper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchHelper.java index 6f800e9aa36..8c9007e0989 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchHelper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchHelper.java @@ -79,7 +79,7 @@ public abstract class TransportSearchHelper { return internalRequest; } - public static String buildScrollId(SearchType searchType, Iterable searchPhaseResults) { + public static String buildScrollId(SearchType searchType, Iterable searchPhaseResults) throws IOException { if (searchType == SearchType.DFS_QUERY_THEN_FETCH || searchType == SearchType.QUERY_THEN_FETCH) { return buildScrollId(ParsedScrollId.QUERY_THEN_FETCH_TYPE, searchPhaseResults); } else if (searchType == SearchType.QUERY_AND_FETCH || searchType == SearchType.DFS_QUERY_AND_FETCH) { @@ -89,17 +89,17 @@ public abstract class TransportSearchHelper { } } - public static String buildScrollId(String type, Iterable searchPhaseResults) { + public static String buildScrollId(String type, Iterable searchPhaseResults) throws IOException { StringBuilder sb = new StringBuilder().append(type).append(';'); for (SearchPhaseResult searchPhaseResult : searchPhaseResults) { sb.append(searchPhaseResult.id()).append(':').append(searchPhaseResult.shardTarget().nodeId()).append(';'); } - return Base64.encodeBytes(Unicode.fromStringAsBytes(sb.toString())); + return Base64.encodeBytes(Unicode.fromStringAsBytes(sb.toString()), Base64.URL_SAFE); } public static ParsedScrollId parseScrollId(String scrollId) { try { - scrollId = Unicode.fromBytes(Base64.decode(scrollId)); + scrollId = Unicode.fromBytes(Base64.decode(scrollId, Base64.URL_SAFE)); } catch (IOException e) { throw new ElasticSearchIllegalArgumentException("Failed to decode scrollId", e); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryAndFetchAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryAndFetchAction.java index 565eda4db00..23ab0526fa0 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryAndFetchAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryAndFetchAction.java @@ -75,7 +75,7 @@ public class TransportSearchQueryAndFetchAction extends TransportSearchTypeActio queryFetchResults.put(result.shardTarget(), result); } - @Override protected void moveToSecondPhase() { + @Override protected void moveToSecondPhase() throws Exception { sortedShardList = searchPhaseController.sortDocs(queryFetchResults.values()); final InternalSearchResponse internalResponse = searchPhaseController.merge(sortedShardList, queryFetchResults, queryFetchResults); String scrollId = null; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryThenFetchAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryThenFetchAction.java index 9f3681ac383..6011c1211aa 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryThenFetchAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryThenFetchAction.java @@ -171,7 +171,7 @@ public class TransportSearchQueryThenFetchAction extends TransportSearchTypeActi } } - private void innerFinishHim() { + private void innerFinishHim() throws Exception { InternalSearchResponse internalResponse = searchPhaseController.merge(sortedShardList, queryResults, fetchResults); String scrollId = null; if (request.scroll() != null) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java index 761c2fe639d..4a495a1acad 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java @@ -353,7 +353,7 @@ public abstract class TransportSearchTypeAction extends BaseAction