Skip to content

Commit

Permalink
Merge pull request #90 from aodn/bugs/5907-search-after-split-char
Browse files Browse the repository at this point in the history
Change to use a different splitter char
  • Loading branch information
HavierD authored Sep 30, 2024
2 parents eee1d0c + 7b80513 commit 251146a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public class ElasticSearch extends ElasticSearchBase implements Search {
@Value("${elasticsearch.vocabs_index.name}")
protected String vocabsIndexName;

@Value("${elasticsearch.search_after.split_regex:\\|\\|}")
protected String searchAfterSplitRegex;

public ElasticSearch(ElasticsearchClient client,
ObjectMapper mapper,
String indexName,
Expand Down Expand Up @@ -300,10 +303,11 @@ public ElasticSearchBase.SearchResult searchByParameters(List<String> keywords,
List<FieldValue> searchAfter = null;
if (setting.get(CQLElasticSetting.search_after) != null &&
!setting.get(CQLElasticSetting.search_after).isBlank()) {
// Convert the comma separate string to List<FieldValue>
// Convert the regex separate string to List<FieldValue>
searchAfter = Arrays.stream(setting.get(CQLElasticSetting.search_after)
.split(","))
.split(searchAfterSplitRegex))
.filter(v -> !v.isBlank())
.map(String::trim)
.map(ElasticSearch::toFieldValue)
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void verifyCorrectPageSizeDataReturn() throws IOException {
// Now if we provided the search after we should get the next batch
collections = testRestTemplate.exchange(
getBasePath() + "/collections?filter=page_size=3 AND search_after=" +
String.format("'%s,%s,%s'",
String.format("'%s||%s||%s'",
collections.getBody().getSearchAfter().get(0),
collections.getBody().getSearchAfter().get(1),
collections.getBody().getSearchAfter().get(2)),
Expand Down Expand Up @@ -224,7 +224,7 @@ public void verifyCorrectPageSizeDataReturnWithQuery() throws IOException {
// intended to give space after comma for negative test
collections = testRestTemplate.exchange(
getBasePath() + "/collections?q=dataset&filter=page_size=1 AND search_after=" +
String.format("'%s,%s,%s'",
String.format("'%s||%s||%s'",
collections.getBody().getSearchAfter().get(0),
collections.getBody().getSearchAfter().get(1),
"bc55eff4-7596-3565-e044-00144fdd4fa6"),
Expand Down Expand Up @@ -253,7 +253,7 @@ public void verifyCorrectPageSizeDataReturnWithQuery() throws IOException {
// set a bigger page size which exceed more than record hit as negative test
collections = testRestTemplate.exchange(
getBasePath() + "/collections?q=dataset&filter=page_size=3 AND search_after=" +
String.format("'%s,%s,%s'",
String.format("'%s||%s ||%s'",
collections.getBody().getSearchAfter().get(0),
collections.getBody().getSearchAfter().get(1),
"5c418118-2581-4936-b6fd-d6bedfe74f62"),
Expand Down Expand Up @@ -330,7 +330,7 @@ public void verifyCorrectPageSizeAndScoreWithQuery() throws IOException {
// intended to give space after comma for negative test
collections = testRestTemplate.exchange(
getBasePath() + "/collections?q=dataset&filter=page_size=6 AND score>=1.3 AND search_after=" +
String.format("'%s, %s , %s'",
String.format("'%s|| %s || %s'",
collections.getBody().getSearchAfter().get(0),
collections.getBody().getSearchAfter().get(1),
"bc55eff4-7596-3565-e044-00144fdd4fa6"),
Expand Down

0 comments on commit 251146a

Please sign in to comment.