Skip to content

Commit

Permalink
Search / Similar document improvement.
Browse files Browse the repository at this point in the history
When using more like this query in Elastic
(https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-mlt-query.html)
it can be sometimes useful to be able to compare the full document for
better match.

Configuration like:
```json
{
    "like": [
        {
            "_id": null
        }
    ],
    "analyzer": "english",
    "minimum_should_match": "40%"
}
```
will search for
```json
{
    "like": [
        {
            "_id": "f48b5a47-1394-4667-81fd-b2e515593d20"
        },
        "Copernicus EEA38 Boundary Layer with 250 m buffer (raster 20m), version 1, Nov. 2022"
    ],
    "analyzer": "english",
    "minimum_should_match": "40%"
}
```

Add documentation about the configuration of more like this query.
  • Loading branch information
fxprunayre committed Sep 11, 2024
1 parent 295bd17 commit c2be3a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,22 @@
scope.size
);

query.query.bool.must[0].more_like_this.like = scope.md.resourceTitle;
function setMoreLikeThisFields(fields) {
var config = query.query.bool.must[0].more_like_this.like;
if (Array.isArray(config)) {
config.forEach(function(field) {
if (typeof field === 'object' && field._id !== undefined) {
field._id = scope.md.uuid;
}
});
config.push(scope.md.resourceTitle);
} else {
config = scope.md.resourceTitle;
}
query.query.bool.must[0].more_like_this.like = config;
}

setMoreLikeThisFields();

var resourceType = scope.md.resourceType
? scope.md.resourceType[0]
Expand Down
14 changes: 4 additions & 10 deletions web-ui/src/main/resources/catalog/js/CatController.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,11 @@
moreLikeThisSameType: true,
moreLikeThisConfig: {
more_like_this: {
fields: [
"resourceTitleObject.langeng"
// "resourceAbstractObject.default",
// "tag.raw"
],
like: null,
min_term_freq: 1,
min_word_length: 3,
max_query_terms: 35,
like: [{
"_id": null
}],
analyzer: "english",
minimum_should_match: "70%"
minimum_should_match: "40%"
}
},
facetTabField: "",
Expand Down

0 comments on commit c2be3a2

Please sign in to comment.