Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Datahub]: Change related datasets suggestions to be more relevant #1082

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -619,7 +619,18 @@ describe('dataset pages', () => {
cy.get('#related-records')
.find('datahub-record-related-records')
.find('gn-ui-related-record-card')
.should('have.length.gt', 0)
.should('have.length', 3)
})
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',
` SCoT (Schéma de cohérence territoriale) en région Hauts-de-France `
)
})
it('goes to dataset on click', () => {
let targetLink
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 @@ -262,11 +262,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
Loading