import org.elasticsearch.search.aggregations.metrics.tophits.InternalTopHits;
import org.elasticsearch.search.aggregations.metrics.tophits.TopHitsBuilder;
import org.elasticsearch.search.highlight.HighlightBuilder;
+import org.elasticsearch.search.sort.FieldSortBuilder;
+import org.elasticsearch.search.sort.ScoreSortBuilder;
import org.sonar.server.es.EsClient;
import org.sonar.server.es.textsearch.ComponentTextSearchFeature;
import org.sonar.server.es.textsearch.ComponentTextSearchFeatureRepertoire;
.setHighlighterPostTags("</mark>")
.addHighlightedField(createHighlighter())
.setFrom(query.getSkip())
- .setSize(query.getLimit());
+ .setSize(query.getLimit())
+ .addSort(new ScoreSortBuilder())
+ .addSort(new FieldSortBuilder(ComponentIndexDefinition.FIELD_NAME));
return sub.setFetchSource(false);
}
assertExactResults("Class java", file3, file2, file1);
}
+ @Test
+ public void if_relevancy_is_equal_fall_back_to_alphabetical_ordering() {
+ assertResultOrder("sonarqube",
+ "sonarqubeA",
+ "sonarqubeB");
+ }
+
@Test
public void scoring_test_DbTester() {
features.set(ComponentTextSearchFeatureRepertoire.PARTIAL);