Skip to content

Commit

Permalink
Small mapping update and response parsing fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmrsulja committed Jun 10, 2024
1 parent f20881e commit fb50d63
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,57 +65,79 @@ git clone -b feature/elasticsearchExperiments https://github.com/j2blake/Vitro.g
```
curl -X PUT "localhost:9200/vivo?pretty" -H 'Content-Type: application/json' -d'
{
"mappings": {
"_doc": {
"properties": {
"ALLTEXT": {
"type": "text",
"analyzer": "english"
},
"ALLTEXTUNSTEMMED": {
"type": "text",
"analyzer": "standard"
},
"DocId": {
"type": "keyword"
},
"classgroup": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
"mostSpecificTypeURIs": {
"type": "keyword"
},
"indexedTime": {
"type": "long"
},
"nameRaw": {
"type": "keyword"
},
"URI": {
"type": "keyword"
},
"THUMBNAIL": {
"type": "integer"
},
"THUMBNAIL_URL": {
"type": "keyword"
},
"nameLowercaseSingleValued": {
"type": "text",
"analyzer": "standard",
"fielddata": "true"
},
"BETA" : {
"type" : "float"
"settings": {
"index": {
"analysis": {
"analyzer": {
"default": {
"type": "english"
}
}
}
}
},
"query": {
"default_field": "ALLTEXT"
"mappings": {
"dynamic_templates": [
{
"field_sort_template": {
"match": "*_label_sort",
"mapping": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
},
"fielddata": true
}
}
}
],
"properties": {
"ALLTEXT": {
"type": "text",
"analyzer": "english"
},
"ALLTEXTUNSTEMMED": {
"type": "text",
"analyzer": "standard"
},
"DocId": {
"type": "keyword"
},
"classgroup": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
"mostSpecificTypeURIs": {
"type": "keyword"
},
"indexedTime": {
"type": "long"
},
"nameRaw": {
"type": "keyword"
},
"URI": {
"type": "keyword"
},
"THUMBNAIL": {
"type": "integer"
},
"THUMBNAIL_URL": {
"type": "keyword"
},
"nameLowercaseSingleValued": {
"type": "text",
"analyzer": "standard",
"fielddata": true
},
"BETA" : {
"type" : "float"
}
}
}
}
'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,33 +98,37 @@ private void parseDocumentList() {
highlightingMap = new HashMap<>();

@SuppressWarnings("unchecked")
Map<String, Object> uberHits = (Map<String, Object>) responseMap
.get("hits");
Map<String, Object> uberHits = (Map<String, Object>) responseMap.get("hits");
if (uberHits == null) {
log.warn("Didn't find a 'hits' field " + "in the query response: "
+ responseMap);
log.warn("Didn't find a 'hits' field in the query response: " + responseMap);
return;
}

Integer total = (Integer) uberHits.get("total");
// Updated handling of the 'total' field
@SuppressWarnings("unchecked")
Map<String, Object> totalMap = (Map<String, Object>) uberHits.get("total");
if (totalMap == null) {
log.warn("Didn't find a 'hits.total' field in the query response: " + responseMap);
return;
}
Integer total = ((Number) totalMap.get("value")).intValue(); // Extract the integer value

if (total == null) {
log.warn("Didn't find a 'hits.total' field "
+ "in the query response: " + responseMap);
log.warn("Didn't find a 'hits.total.value' field in the query response: " + responseMap);
return;
}

@SuppressWarnings("unchecked")
List<Map<String, Object>> hits = (List<Map<String, Object>>) uberHits
.get("hits");
List<Map<String, Object>> hits = (List<Map<String, Object>>) uberHits.get("hits");
if (hits == null) {
log.warn("Didn't find a 'hits.hits' field "
+ "in the query response: " + responseMap);
log.warn("Didn't find a 'hits.hits' field in the query response: " + responseMap);
return;
}

parseDocuments(hits);
}


private void parseDocuments(List<Map<String, Object>> hits) {
for (Map<String, Object> hit : hits) {
SearchResultDocument doc = parseDocument(hit);
Expand Down
15 changes: 12 additions & 3 deletions home/src/main/resources/config/example.applicationSetup.n3
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,22 @@
# and more rigorous life-cycle checking.
#

#:instrumentedSearchEngineWrapper
# a vitroWebapp:searchengine.InstrumentedSearchEngineWrapper ,
# vitroWebapp:modules.searchEngine.SearchEngine ;
# :wraps :solrSearchEngine .

#:solrSearchEngine
# a vitroWebapp:searchengine.solr.SolrSearchEngine ,
# vitroWebapp:modules.searchEngine.SearchEngine .

:instrumentedSearchEngineWrapper
a vitroWebapp:searchengine.InstrumentedSearchEngineWrapper ,
vitroWebapp:modules.searchEngine.SearchEngine ;
:wraps :solrSearchEngine .
:wraps :elasticSearchEngine .

:solrSearchEngine
a vitroWebapp:searchengine.solr.SolrSearchEngine ,
:elasticSearchEngine
a vitroWebapp:searchengine.elasticsearch.ElasticSearchEngine ,
vitroWebapp:modules.searchEngine.SearchEngine .

# ----------------------------
Expand Down

0 comments on commit fb50d63

Please sign in to comment.