|
4 | 4 | import au.org.aodn.ogcapi.server.core.model.EsFeatureCollectionModel; |
5 | 5 | import au.org.aodn.ogcapi.server.core.model.EsFeatureModel; |
6 | 6 | import au.org.aodn.ogcapi.server.core.model.EsPolygonModel; |
| 7 | +import au.org.aodn.ogcapi.server.core.model.enumeration.CQLFields; |
7 | 8 | import au.org.aodn.ogcapi.server.core.model.ogc.FeatureRequest; |
8 | 9 | import au.org.aodn.ogcapi.server.core.service.ElasticSearch; |
9 | 10 | import au.org.aodn.ogcapi.server.core.service.ElasticSearchBase; |
|
13 | 14 | import co.elastic.clients.elasticsearch.core.search.Hit; |
14 | 15 | import co.elastic.clients.elasticsearch.core.search.HitsMetadata; |
15 | 16 | import co.elastic.clients.elasticsearch.core.search.TotalHits; |
| 17 | +import co.elastic.clients.elasticsearch._types.query_dsl.*; |
16 | 18 | import com.fasterxml.jackson.databind.ObjectMapper; |
17 | 19 | import org.junit.jupiter.api.BeforeEach; |
18 | 20 | import org.junit.jupiter.api.Test; |
@@ -116,5 +118,56 @@ public void searchFeatureSummaryTest() throws IOException { |
116 | 118 | featureProps.get("key")); |
117 | 119 | } |
118 | 120 |
|
| 121 | + @Test |
| 122 | + public void searchByParametersWithDoubleQuote() throws Exception { |
| 123 | + String keyword = "\"ocean temperature\""; |
| 124 | + List<String> keywords = List.of(keyword); |
| 125 | + List<Query> should = new ArrayList<>(); |
| 126 | + for (String t : keywords) { |
| 127 | + boolean isExact = t.startsWith("\"") && t.endsWith("\"") && t.length() > 2; |
| 128 | + String term = isExact ? t.substring(1, t.length() - 1) : t; |
| 129 | + if (isExact) { |
| 130 | + should.add(CQLFields.title.getPropertyEqualToQuery(term)); |
| 131 | + should.add(CQLFields.description.getPropertyEqualToQuery(term)); |
| 132 | + } else { |
| 133 | + should.add(CQLFields.fuzzy_title.getPropertyEqualToQuery(term)); |
| 134 | + should.add(CQLFields.fuzzy_desc.getPropertyEqualToQuery(term)); |
| 135 | + } |
| 136 | + should.add(CQLFields.parameter_vocabs.getPropertyEqualToQuery(term)); |
| 137 | + should.add(CQLFields.organisation_vocabs.getPropertyEqualToQuery(term)); |
| 138 | + should.add(CQLFields.platform_vocabs.getPropertyEqualToQuery(term)); |
| 139 | + should.add(CQLFields.id.getPropertyEqualToQuery(term)); |
| 140 | + should.add(CQLFields.links_title_contains.getPropertyEqualToQuery(term)); |
| 141 | + should.add(CQLFields.credit_contains.getPropertyEqualToQuery(term)); |
| 142 | + } |
| 143 | + assertEquals(8, should.size(), "Exact match should produce 8 queries (title + description + other fields)"); |
| 144 | + assertTrue(should.get(0).isMatchPhrase(), "Title query should be MatchPhraseQuery"); |
| 145 | + assertTrue(should.get(1).isMatchPhrase(), "Description query should be MatchPhraseQuery"); |
| 146 | + } |
119 | 147 |
|
| 148 | + @Test |
| 149 | + public void searchByParametersWithoutDoubleQuote() throws Exception { |
| 150 | + String keyword = "ocean temperature"; |
| 151 | + List<String> keywords = List.of(keyword); |
| 152 | + List<Query> should = new ArrayList<>(); |
| 153 | + for (String t : keywords) { |
| 154 | + boolean isExact = t.startsWith("\"") && t.endsWith("\"") && t.length() > 2; |
| 155 | + String term = isExact ? t.substring(1, t.length() - 1) : t; |
| 156 | + if (isExact) { |
| 157 | + should.add(CQLFields.title.getPropertyEqualToQuery(term)); |
| 158 | + should.add(CQLFields.description.getPropertyEqualToQuery(term)); |
| 159 | + } else { |
| 160 | + should.add(CQLFields.fuzzy_title.getPropertyEqualToQuery(term)); |
| 161 | + should.add(CQLFields.fuzzy_desc.getPropertyEqualToQuery(term)); |
| 162 | + } |
| 163 | + should.add(CQLFields.parameter_vocabs.getPropertyEqualToQuery(term)); |
| 164 | + should.add(CQLFields.organisation_vocabs.getPropertyEqualToQuery(term)); |
| 165 | + should.add(CQLFields.platform_vocabs.getPropertyEqualToQuery(term)); |
| 166 | + should.add(CQLFields.id.getPropertyEqualToQuery(term)); |
| 167 | + should.add(CQLFields.links_title_contains.getPropertyEqualToQuery(term)); |
| 168 | + should.add(CQLFields.credit_contains.getPropertyEqualToQuery(term)); |
| 169 | + } |
| 170 | + assertEquals(8, should.size(), "Fuzzy match should produce 8 queries"); |
| 171 | + assertTrue(should.get(0).isMatch(), "fuzzy_title should be MatchQuery"); |
| 172 | + } |
120 | 173 | } |
0 commit comments