Skip to content

Commit

Permalink
Merge pull request #1082 from geonetwork/DH-relevant-similar-datasets…
Browse files Browse the repository at this point in the history
…-suggestions

[Datahub]: Change related datasets suggestions to be more relevant
  • Loading branch information
ronitjadhav authored Feb 25, 2025
2 parents 97ab0d3 + 6d1db07 commit 6d78023
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 21 deletions.
13 changes: 12 additions & 1 deletion apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,25 @@ describe('dataset pages', () => {
})
describe('related records', () => {
beforeEach(() => {
cy.visit('/dataset/6d0bfdf4-4e94-48c6-9740-3f9facfd453c')
cy.visit('/dataset/a3774ef6-809d-4dd1-984f-9254f49cbd0a')
})
it('should display the related records', () => {
cy.get('#related-records')
.find('datahub-record-related-records')
.find('gn-ui-related-record-card')
.should('have.length.gt', 0)
})
it('should display a similar related record', () => {
cy.get('#related-records')
.find('datahub-record-related-records')
.find('gn-ui-related-record-card')
.first()
.find('h4')
.should(
'have.text',
` Metadata for E2E testing purpose. (this title is too long and should be cut, this title is too long and should be cut, this title is too long and should be cut, this title is too long and should be cut, this title is too long and should be cut) `
)
})
it('goes to dataset on click', () => {
let targetLink
cy.get('#related-records')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ElasticsearchService } from './elasticsearch.service'
import { elasticAggsResponseFixture } from '@geonetwork-ui/common/fixtures'
import {
datasetRecordsFixture,
elasticAggsResponseFixture,
} from '@geonetwork-ui/common/fixtures'
import { LangService } from '@geonetwork-ui/util/i18n'
import { EsSearchParams } from '@geonetwork-ui/api/metadata-converter'
import { TestBed } from '@angular/core/testing'
Expand Down Expand Up @@ -678,9 +681,10 @@ describe('ElasticsearchService', () => {
})

describe('#getRelatedRecordPayload', () => {
const record = datasetRecordsFixture()[0]
let payload
beforeEach(() => {
payload = service.getRelatedRecordPayload('record title', 'some-uuid', 4)
payload = service.getRelatedRecordPayload(record, 4)
})
it('returns ES payload', () => {
expect(payload).toEqual({
Expand Down Expand Up @@ -716,9 +720,33 @@ describe('ElasticsearchService', () => {
fields: [
'resourceTitleObject.default',
'resourceAbstractObject.default',
'tag.raw',
'allKeywords',
],
like: [
{
doc: {
resourceTitleObject: {
default:
'A very interesting dataset (un jeu de données très intéressant)',
},
resourceAbstractObject: {
default: `# Introduction
This dataset has been established for testing purposes.
## Details
This is a section about details. Here is an HTML tag: <img src="http://google.com" />. And [a link](https://google.com).
## Informations intéressantes
Cette section contient des *caractères internationaux* (ainsi que des "caractères spéciaux"). 'çàü^@/~^&`,
},
allKeywords: [
'international',
'test',
'_another_keyword_',
],
},
},
],
like: 'record title',
max_query_terms: 12,
min_term_freq: 1,
},
Expand All @@ -734,7 +762,7 @@ describe('ElasticsearchService', () => {
},
},
],
must_not: [{ wildcard: { uuid: 'some-uuid' } }],
must_not: [{ wildcard: { uuid: 'my-dataset-001' } }],
},
},
size: 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from '@geonetwork-ui/api/metadata-converter'
import { LangService } from '@geonetwork-ui/util/i18n'
import { formatDate, isDateRange } from './date-range.utils'
import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record'

export type DateRange = { start?: Date; end?: Date }

Expand Down Expand Up @@ -134,8 +135,7 @@ export class ElasticsearchService {
}

getRelatedRecordPayload(
title: string,
uuid: string,
record: CatalogRecord,
size = 6,
_source = [...ES_SOURCE_SUMMARY, 'allKeywords', 'createDate']
): EsSearchParams {
Expand All @@ -148,9 +148,23 @@ export class ElasticsearchService {
fields: [
'resourceTitleObject.default',
'resourceAbstractObject.default',
'tag.raw',
'allKeywords',
],
like: [
{
doc: {
resourceTitleObject: {
default: record.title,
},
resourceAbstractObject: {
default: record.abstract,
},
allKeywords: record.keywords.map(
(keyword) => keyword.label
),
},
},
],
like: title,
min_term_freq: 1,
max_query_terms: 12,
},
Expand All @@ -166,7 +180,7 @@ export class ElasticsearchService {
},
},
],
must_not: [{ wildcard: { uuid: uuid } }],
must_not: [{ wildcard: { uuid: record.uniqueIdentifier } }],
},
},
size,
Expand Down
7 changes: 2 additions & 5 deletions libs/api/repository/src/lib/gn4/gn4-repository.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,8 @@ describe('Gn4Repository', () => {
)
})
it('uses a related record ES payload', () => {
expect(gn4Helper.getRelatedRecordPayload).toHaveBeenCalledWith(
'A very interesting dataset (un jeu de données très intéressant)',
'my-dataset-001',
3
)
const record = datasetRecordsFixture()[0]
expect(gn4Helper.getRelatedRecordPayload).toHaveBeenCalledWith(record, 3)
})
it('returns the given results as records', () => {
expect(results).toStrictEqual(datasetRecordsFixture())
Expand Down
6 changes: 1 addition & 5 deletions libs/api/repository/src/lib/gn4/gn4-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,7 @@ export class Gn4Repository implements RecordsRepositoryInterface {
'bucket',
null,
JSON.stringify(
this.gn4SearchHelper.getRelatedRecordPayload(
similarTo.title,
similarTo.uniqueIdentifier,
3
)
this.gn4SearchHelper.getRelatedRecordPayload(similarTo, 3)
)
)
.pipe(
Expand Down

0 comments on commit 6d78023

Please sign in to comment.