Skip to content

Commit

Permalink
Merge pull request #66 from aodn/smart-suggestions
Browse files Browse the repository at this point in the history
Smart suggestions
  • Loading branch information
utas-raymondng authored Apr 24, 2024
2 parents 0842ee0 + cdd9dc1 commit 6273eaa
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package au.org.aodn.esindexer.service;

import au.org.aodn.esindexer.utils.CacheArdcVocabsUtils;
import au.org.aodn.esindexer.utils.VocabsUtils;
import au.org.aodn.stac.model.ConceptModel;
import au.org.aodn.stac.model.ThemesModel;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand All @@ -15,7 +16,10 @@
@Service
public class AodnDiscoveryParameterVocabService {
@Autowired
CacheArdcVocabsUtils cacheArdcVocabsUtils;
VocabsUtils cacheArdcVocabsUtils;

@Autowired
ElasticsearchClient portalElasticsearchClient;

protected boolean themesMatchConcept(List<ThemesModel> themes, ConceptModel thatConcept) {
for (ThemesModel theme : themes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import au.org.aodn.esindexer.exception.*;
import au.org.aodn.esindexer.utils.JaxbUtils;
import au.org.aodn.metadata.iso19115_3_2018.*;
import au.org.aodn.stac.model.RecordSuggest;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch._types.ElasticsearchException;
import co.elastic.clients.elasticsearch.core.*;
Expand Down Expand Up @@ -127,14 +128,21 @@ protected StacCollectionModel getMappedMetadataValues(String metadataValues) thr

stacCollectionModel.getSummaries().setScore(score);

// TODO: in future, blah blah here
stacCollectionModel.setTitleSuggest(stacCollectionModel.getTitle());

List<String> aodnDiscoveryCategories = aodnDiscoveryParameterVocabService.getAodnDiscoveryCategories(stacCollectionModel.getThemes());
if (!aodnDiscoveryCategories.isEmpty()) {
stacCollectionModel.getSummaries().setDiscoveryCategories(aodnDiscoveryCategories);
}


// categories suggest using a different index

// extendable for other aspects of the records data. eg. title, description, etc. something that are unique to the record and currently using "text" type
RecordSuggest recordSuggest = RecordSuggest.builder()
.title(stacCollectionModel.getTitle())
.description(null) // purely for demonstrating the extendability, manage extra suggest field in RecordSuggest class, and the index JSON schema
.build();
stacCollectionModel.setRecordSuggest(recordSuggest);

return stacCollectionModel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@Component
// create and inject a stub proxy to self due to the circular reference http://bit.ly/4aFvYtt
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
public class CacheArdcVocabsUtils {
public class VocabsUtils {
@Value(AppConstants.AODN_DISCOVERY_PARAMETER_VOCAB_API)
protected String vocabApi;

Expand All @@ -41,7 +41,7 @@ public class CacheArdcVocabsUtils {

// self-injection to avoid self-invocation problems when calling the cachable method within the same bean
@Autowired
CacheArdcVocabsUtils self;
VocabsUtils self;

@Autowired
ElasticSearchIndexService elasticSearchIndexService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
{
"settings":{
"analysis":{
"analyzer":{
"custom_analyser":{
"type":"custom",
"tokenizer":"standard",
"filter":[
"lowercase",
"english_stop"
]
}
},
"filter":{
"english_stop":{
"type":"stop",
"stopwords":"_english_"
}
}
}
},
"mappings": {
"dynamic": true,
"properties": {
"label": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"label": { "type": "search_as_you_type", "analyzer": "custom_analyser" },
"definition": {
"type": "text"
},
Expand All @@ -20,15 +32,7 @@
"broader": {
"type": "nested",
"properties": {
"label": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"label": { "type": "text" },
"about": {
"type": "keyword"
}
Expand All @@ -37,30 +41,14 @@
"narrower": {
"type": "nested",
"properties": {
"label": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"label": { "type": "text" },
"about": {
"type": "keyword"
},
"narrower": {
"type": "nested",
"properties": {
"label": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"label": { "type": "text" },
"about": {
"type": "keyword"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
"stac_version": { "type": "text" },
"type": { "type": "text" },
"title": { "type": "text" },
"title_suggest": {
"type": "search_as_you_type",
"analyzer": "custom_analyser"
"record_suggest": {
"type": "nested",
"properties": {
"title": { "type": "search_as_you_type", "analyzer": "custom_analyser" },
"description": { "type": "search_as_you_type", "analyzer": "custom_analyser" }
}
},
"discovery_categories" : { "type": "keyword" },
"keywords": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package au.org.aodn.esindexer.utils;

import au.org.aodn.ardcvocabs.configuration.ArdcAutoConfiguration;
import au.org.aodn.esindexer.service.AodnDiscoveryParameterVocabService;
import au.org.aodn.stac.model.ConceptModel;
import au.org.aodn.stac.model.ThemesModel;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

Expand All @@ -23,7 +20,7 @@
@ActiveProfiles("test")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class AodnDiscoveryParameterVocabUtilsTest {
public class VocabUtilsTest {
@Autowired
AodnDiscoveryParameterVocabService aodnDiscoveryParameterVocabService;

Expand Down
4 changes: 3 additions & 1 deletion indexer/src/test/resources/canned/sample4_stac.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@
"title" : "AODN Discovery Parameter Vocabulary"
} ],
"id" : "7709f541-fc0c-4318-b5b9-9053aa474e0e",
"title_suggest" : "Ocean acidification historical reconstruction",
"record_suggest" : {
"title" : "Ocean acidification historical reconstruction"
},
"type" : "Collection",
"stac_version" : "1.0.0",
"stac_extensions" : [ "https://stac-extensions.github.io/scientific/v1.0.0/schema.json", "https://stac-extensions.github.io/contacts/v0.1.1/schema.json", "https://stac-extensions.github.io/projection/v1.1.0/schema.json", "https://stac-extensions.github.io/language/v1.0.0/schema.json", "https://stac-extensions.github.io/themes/v1.0.0/schema.json" ]
Expand Down
11 changes: 11 additions & 0 deletions stacmodel/src/main/java/au/org/aodn/stac/model/RecordSuggest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package au.org.aodn.stac.model;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class RecordSuggest {
private String title;
private String description;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class StacCollectionModel {
@JsonProperty("id")
protected String uuid;
protected String title;
@JsonProperty("title_suggest")
protected String titleSuggest;
@JsonProperty("record_suggest")
protected RecordSuggest recordSuggest;
protected String description;
protected ExtentModel extent;
protected SummariesModel summaries;
Expand Down

0 comments on commit 6273eaa

Please sign in to comment.