From 19fab7cd0e91fe85aaeea815b20de867d596027a Mon Sep 17 00:00:00 2001 From: Florian Schilling Date: Wed, 8 May 2013 12:42:30 +0200 Subject: [PATCH] Fixed parsing of `track_scores` in `RestSearchAction` Closes #2986 --- .../rest/action/search/RestSearchAction.java | 7 +++++ .../search/sort/SimpleSortTests.java | 27 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index 96aa70c668a..db348a10018 100644 --- a/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -226,6 +226,13 @@ public class RestSearchAction extends BaseRestHandler { } } + if(request.hasParam("track_scores")) { + if (searchSourceBuilder == null) { + searchSourceBuilder = new SearchSourceBuilder(); + } + searchSourceBuilder.trackScores(request.paramAsBoolean("track_scores", false)); + } + String sSorts = request.param("sort"); if (sSorts != null) { if (searchSourceBuilder == null) { diff --git a/src/test/java/org/elasticsearch/test/integration/search/sort/SimpleSortTests.java b/src/test/java/org/elasticsearch/test/integration/search/sort/SimpleSortTests.java index 880eba00743..9eedbfdf572 100644 --- a/src/test/java/org/elasticsearch/test/integration/search/sort/SimpleSortTests.java +++ b/src/test/java/org/elasticsearch/test/integration/search/sort/SimpleSortTests.java @@ -167,7 +167,32 @@ public class SimpleSortTests extends AbstractNodesTests { assertThat(searchResponse.getHits().getAt(1).getId(), equalTo("2")); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("1")); } - + + @Test + public void testIssue2986() { + try { + client.admin().indices().prepareDelete("test").execute().actionGet(); + } catch (Exception e) { + // ignore + } + + client.admin().indices().prepareCreate("test").execute().actionGet(); + + client.prepareIndex("test", "post", "1").setSource("{\"field1\":\"value1\"}").execute().actionGet(); + client.prepareIndex("test", "post", "2").setSource("{\"field1\":\"value2\"}").execute().actionGet(); + client.prepareIndex("test", "post", "3").setSource("{\"field1\":\"value3\"}").execute().actionGet(); + + client.admin().indices().prepareRefresh("test").execute().actionGet(); + + SearchResponse result = client.prepareSearch("test").setQuery(matchAllQuery()).setTrackScores(true).addSort("field1", SortOrder.ASC).execute().actionGet(); + + for (SearchHit hit : result.getHits()) { + assert !Float.isNaN(hit.getScore()); + } + + client.admin().indices().prepareDelete("test").execute().actionGet(); + } + @Test public void testIssue2991() { for (int i = 1; i < 4; i++) {