From 49e03ad304d6f095a88ef28323052e4c98e0bd0f Mon Sep 17 00:00:00 2001 From: Roman Kalyakin Date: Thu, 16 May 2024 16:18:23 +0200 Subject: [PATCH] Supporting query parameter and response changes made on the API side (#1221) * refactored search facet use after endpoint change * grouped facet requests * fixed groupby in searchFacets service * updated query parameter in text reuse clusters * text reuse passages query parameters updated * disabled `group_by` parameter in search facets query where it used to be a typo before parameter name was fixed. The "articles" value is not valid for this service call. * replace skip offset --- src/components/CollectionDetailPage.vue | 4 +-- src/components/EntitiesDetailPage.vue | 12 +++---- src/components/EntitiesExplorerPage.vue | 2 +- src/components/Explorer.vue | 7 ++-- src/components/NewspapersDetailPage.vue | 12 +++---- src/components/SelectionMonitor.vue | 4 +-- src/components/TextReuseClusterDetailPage.vue | 2 +- src/components/TextReuseClusterIdCardPage.vue | 4 +-- src/components/TextReuseClusterMonitor.vue | 4 +-- src/components/TextReuseConnectedClusters.vue | 6 ++-- src/components/TextReuseExplorerPage.vue | 2 +- src/components/TextReusePassageMonitor.vue | 4 +-- src/components/TopicDetailPage.vue | 8 ++--- src/components/modules/FilterDynamicRange.vue | 9 +++-- src/components/modules/FilterFacet.vue | 18 +++++----- .../modules/collections/AddToCollection.vue | 2 +- .../CollectionRecommendationsPanel.vue | 2 +- .../modules/textReuse/TextReuseOverview.vue | 32 ++++++++++-------- src/pages/Search.vue | 33 +++++++------------ src/pages/SearchImages.vue | 4 +-- src/pages/SearchNgrams.vue | 6 ++-- src/pages/SearchQueriesComparison.vue | 7 ++-- src/pages/TextReuse.vue | 9 +++-- src/pages/TextReuseClusters.vue | 2 +- src/services/index.js | 17 +++++++++- src/store/Collections.js | 8 ++--- src/store/Entities.js | 19 ++++++----- src/store/Search.js | 13 ++++---- src/store/SearchImages.js | 2 +- 29 files changed, 129 insertions(+), 125 deletions(-) diff --git a/src/components/CollectionDetailPage.vue b/src/components/CollectionDetailPage.vue index 365a42545..e96048efd 100644 --- a/src/components/CollectionDetailPage.vue +++ b/src/components/CollectionDetailPage.vue @@ -524,9 +524,9 @@ export default { type: 'collection', q: this.collectionUid, }], - group_by: 'articles', + // group_by: 'articles', } - }).then(([type]) => new Facet(type)); + }).then((type) => new Facet(type)); }, }, }; diff --git a/src/components/EntitiesDetailPage.vue b/src/components/EntitiesDetailPage.vue index 31af58aca..18ccc7550 100644 --- a/src/components/EntitiesDetailPage.vue +++ b/src/components/EntitiesDetailPage.vue @@ -332,18 +332,16 @@ export default { }); this.facets = []; const query = { + facets: this.facetTypes, filters: [{ type: 'entity', q: [ this.$route.params.entity_id ], }], - group_by: 'articles', + // group_by: 'articles', }; - for (let facetType of this.facetTypes) { - const results = await searchFacetsService.get(facetType, { - query, - }).then(([facetType]) => new Facet(facetType)); - this.facets = this.facets.concat(results); - } + + this.facets = await searchFacetsService.find({ query }) + .then(response => response.data.map(item => new Facet(item))) }, loadItems(page = 1) { if (this.tab.name === TAB_ARTICLES) { diff --git a/src/components/EntitiesExplorerPage.vue b/src/components/EntitiesExplorerPage.vue index 98fdb51dc..76928a96a 100644 --- a/src/components/EntitiesExplorerPage.vue +++ b/src/components/EntitiesExplorerPage.vue @@ -578,7 +578,7 @@ export default { entityId, filters, timeResolution: this.punchcardResolution, - skip: skipPerEntity[entityId] + offset: skipPerEntity[entityId] })); try { diff --git a/src/components/Explorer.vue b/src/components/Explorer.vue index ce8a9d901..16a7c7ae5 100644 --- a/src/components/Explorer.vue +++ b/src/components/Explorer.vue @@ -86,7 +86,7 @@ import { topics, newspapers, collections, - searchFacets + getSearchFacetsService } from '@/services' import FacetExplorer from './modules/FacetExplorer'; import TimeFacetExplorer from './modules/TimeFacetExplorer'; @@ -158,10 +158,9 @@ async function search({ page: currentPage, limit: pageSize, order_by: '-count', - index }; - const response = await searchFacets.get(type, { query }) - const result = response[0] + const response = await getSearchFacetsService(index).get(type, { query }) + const result = response return { totalResults: result.numBuckets, buckets: result.buckets.map(d => new Bucket({ diff --git a/src/components/NewspapersDetailPage.vue b/src/components/NewspapersDetailPage.vue index b3a08e7de..e168acb60 100644 --- a/src/components/NewspapersDetailPage.vue +++ b/src/components/NewspapersDetailPage.vue @@ -304,15 +304,13 @@ export default { async loadFacets() { this.facets = []; const query = { + facets: this.facetTypes, filters: [{ type: 'newspaper', q: [this.newspaperUid] }], - group_by: 'articles', + // group_by: 'articles', }; - for (let facetType of this.facetTypes) { - const results = await searchFacetsService.get(facetType, { - query, - }).then(([facetType]) => new Facet(facetType)); - this.facets = this.facets.concat(results); - } + + this.facets = await searchFacetsService.find({ query }) + .then(result => result.data.map(item => new Facet(item))) }, }, watch: { diff --git a/src/components/SelectionMonitor.vue b/src/components/SelectionMonitor.vue index 2865775c2..f26ffa6b3 100644 --- a/src/components/SelectionMonitor.vue +++ b/src/components/SelectionMonitor.vue @@ -397,8 +397,8 @@ export default defineComponent({ .then(response => { // eslint-disable-next-line no-console console.debug('[ItemSelector] loadTimeline success', response) - this.timelineValues = Helpers.timeline.fromBuckets(response[0].buckets) - this.total = response[0].buckets.reduce((acc, bucket) => acc + bucket.count, 0) + this.timelineValues = Helpers.timeline.fromBuckets(response.buckets) + this.total = response.buckets.reduce((acc, bucket) => acc + bucket.count, 0) }) }, }, diff --git a/src/components/TextReuseClusterDetailPage.vue b/src/components/TextReuseClusterDetailPage.vue index fd994573f..3e905b6c7 100644 --- a/src/components/TextReuseClusterDetailPage.vue +++ b/src/components/TextReuseClusterDetailPage.vue @@ -185,7 +185,7 @@ export default { [this.passageItems, this.paginationInfo] = await textReuseClusterPassages .find({ query: { clusterId: this.clusterId, - skip: this.paginationPerPage * pageNumber, + offset: this.paginationPerPage * pageNumber, limit: this.paginationPerPage, orderBy }}) diff --git a/src/components/TextReuseClusterIdCardPage.vue b/src/components/TextReuseClusterIdCardPage.vue index f04e5730f..8068f9acb 100644 --- a/src/components/TextReuseClusterIdCardPage.vue +++ b/src/components/TextReuseClusterIdCardPage.vue @@ -110,7 +110,7 @@ export default { if (id == null) return this.isLoading = true try { - const response = await textReuseClustersService.get(this.cluster.id, { query: { includeDetails: true }}) + const response = await textReuseClustersService.get(this.cluster.id, { query: { include_details: true }}) const facets = response?.details?.facets ?? [] this.resolution = response?.details?.resolution this.facets = facets.map(facet => new FacetModel(facet)) @@ -122,4 +122,4 @@ export default { } } } - \ No newline at end of file + diff --git a/src/components/TextReuseClusterMonitor.vue b/src/components/TextReuseClusterMonitor.vue index 1c69a0dfc..b9a32219e 100644 --- a/src/components/TextReuseClusterMonitor.vue +++ b/src/components/TextReuseClusterMonitor.vue @@ -185,7 +185,7 @@ export default { const query = { page: this.startPassageOffset, limit: 1, - orderBy: this.startPassageOrderBy, + order_by: this.startPassageOrderBy, filters: this.filters.length ? optimizeFilters(this.filters) : [{ type: 'textReuseCluster', q: this.item.id }], @@ -203,7 +203,7 @@ export default { const query = { page: this.endPassageOffset, limit: 1, - orderBy: this.endPassageOrderBy, + order_by: this.endPassageOrderBy, filters: this.filters.length ? optimizeFilters(this.filters) : [{ type: 'textReuseCluster', q: this.item.id }], diff --git a/src/components/TextReuseConnectedClusters.vue b/src/components/TextReuseConnectedClusters.vue index 48e610342..65c4f92ac 100644 --- a/src/components/TextReuseConnectedClusters.vue +++ b/src/components/TextReuseConnectedClusters.vue @@ -94,12 +94,12 @@ export default { }) } }, - /** @returns {{ clusterId: string, skip: number, limit: number } | undefined} */ + /** @returns {{ clusterId: string, offset: number, limit: number } | undefined} */ clustersQuery() { if (this.clusterId == null) return undefined return { clusterId: this.clusterId, - skip: (this.pageNumber - 1) * this.perPage, + offset: (this.pageNumber - 1) * this.perPage, limit: this.perPage } } @@ -128,4 +128,4 @@ export default { .connected-cluster-container { cursor: pointer; } - \ No newline at end of file + diff --git a/src/components/TextReuseExplorerPage.vue b/src/components/TextReuseExplorerPage.vue index d6a13a551..1f3344736 100644 --- a/src/components/TextReuseExplorerPage.vue +++ b/src/components/TextReuseExplorerPage.vue @@ -516,7 +516,7 @@ export default { /** @returns {{ query: any, hash: string }} */ searchApiQueryParameters() { const query = { - skip: this.paginationPerPage * (this.paginationCurrentPage - 1), + offset: this.paginationPerPage * (this.paginationCurrentPage - 1), page: this.paginationCurrentPage, limit: this.paginationPerPage, orderBy: this.orderBy, diff --git a/src/components/TextReusePassageMonitor.vue b/src/components/TextReusePassageMonitor.vue index ede0976bc..475808747 100644 --- a/src/components/TextReusePassageMonitor.vue +++ b/src/components/TextReusePassageMonitor.vue @@ -129,9 +129,9 @@ export default { : [{ type: 'textReuseCluster', q: this.item.textReuseCluster.id }] filters.push({ type: 'id', q: this.item.id, context: 'exclude' }) const query = { - skip: parseInt(this.endPassageOffset, 10), + offset: parseInt(this.endPassageOffset, 10), limit: 1, - orderBy: this.endPassageOrderBy, + order_by: this.endPassageOrderBy, filters, addons: { newspaper: 'text' }, } diff --git a/src/components/TopicDetailPage.vue b/src/components/TopicDetailPage.vue index 81c2348ee..90723ca33 100644 --- a/src/components/TopicDetailPage.vue +++ b/src/components/TopicDetailPage.vue @@ -229,13 +229,13 @@ export default { type: 'topic', q: [ this.topicUid ], }], - group_by: 'articles', + // group_by: 'articles', }; for (let facetType of this.facetTypes) { - const results = await searchFacetsService.get(facetType, { + const result = await searchFacetsService.get(facetType, { query, - }).then(([facetType]) => new Facet(facetType)); - this.facets = this.facets.concat(results); + }).then((facetType) => new Facet(facetType)); + this.facets = this.facets.concat(result); } }, async loadTimeline() { diff --git a/src/components/modules/FilterDynamicRange.vue b/src/components/modules/FilterDynamicRange.vue index 0e49f376a..bfe9aca5c 100644 --- a/src/components/modules/FilterDynamicRange.vue +++ b/src/components/modules/FilterDynamicRange.vue @@ -48,7 +48,7 @@ import BaseTitleBar from '@/components/base/BaseTitleBar' import HistogramSlider from '@/components/modules/vis/HistogramSlider' import { serializeFilters } from '@/logic/filters' -import { stats as statsService, searchFacets as searchFacetsService } from '@/services' +import { stats as statsService, getSearchFacetsService } from '@/services' import Tooltip from './tooltips/Tooltip' import FilterFactory from '@/models/FilterFactory' import InfoButton from '@/components/base/InfoButton' @@ -257,13 +257,12 @@ export default { console.error('[FilterDynamicRange] error', error) }) // when min and max have been calculated, set the range - await searchFacetsService + await getSearchFacetsService(this.index) .get(this.facet.type, { query: { - index: this.index, // searchFacets doesn't support serialized filters filters: this.facetFilters, - groupby: query.groupby, + group_by: query.groupby, rangeStart: this.start, rangeEnd: this.end + 1, rangeGap: this.gap, @@ -272,7 +271,7 @@ export default { }) .then(response => { console.debug('[FilterDynamicRange] loadFacet', response) - this.buckets = response[0].buckets + this.buckets = response.buckets }) .catch(error => { // eslint-disable-next-line diff --git a/src/components/modules/FilterFacet.vue b/src/components/modules/FilterFacet.vue index 5e1c217a1..3ef819d28 100644 --- a/src/components/modules/FilterFacet.vue +++ b/src/components/modules/FilterFacet.vue @@ -127,7 +127,7 @@ import FilterMonitor from '@/components/modules/FilterMonitor' import InfoButton from '@/components/base/InfoButton' import { toSerializedFilter } from '@/logic/filters' import Bucket from '@/models/Bucket' -import { searchFacets } from '@/services' +import { getSearchFacetsService } from '@/services' import LazyObserver from '../LazyObserver.vue' import { defineComponent } from 'vue' @@ -150,7 +150,7 @@ export default defineComponent({ selectedBucketsItems: [], // limit: 10, - skip: 0, + offset: 0, additionalBuckets: [], isMoreLoading: false, lazyIsPristine: true, @@ -336,16 +336,15 @@ export default defineComponent({ return } this.isMoreLoading = true - searchFacets + getSearchFacetsService(this.searchIndex) .get(this.facet.type, { query: { - index: this.searchIndex, filters: this.contextFilters, limit: this.limit, - skip: this.skip, + offset: this.skip, }, }) - .then(([{ numBuckets, buckets }]) => { + .then(({ numBuckets, buckets }) => { console.info('loadMoreBuckets', buckets, this.skip) this.additionalBuckets = this.additionalBuckets.concat( buckets.map( @@ -371,20 +370,19 @@ export default defineComponent({ console.debug('[FilterFacet] @onIntersect type:', this.facet.type) this.lazyIsPristine = false // load initial buckets - searchFacets + getSearchFacetsService(this.searchIndex) .get( this.facet.type, { query: { - index: this.searchIndex, filters: this.contextFilters, limit: this.limit, - skip: this.skip, + offset: this.skip, }, }, { ignoreErrors: true }, ) - .then(([{ numBuckets, buckets }]) => { + .then(({ numBuckets, buckets }) => { this.facet.numBuckets = numBuckets this.facet.setBuckets(buckets) }) diff --git a/src/components/modules/collections/AddToCollection.vue b/src/components/modules/collections/AddToCollection.vue index 593d3337c..0d06121aa 100644 --- a/src/components/modules/collections/AddToCollection.vue +++ b/src/components/modules/collections/AddToCollection.vue @@ -123,7 +123,7 @@ export default { } } const query = { - skip: this.paginationPerPage * (this.paginationCurrentPage - 1), + offset: this.paginationPerPage * (this.paginationCurrentPage - 1), page: this.paginationCurrentPage, limit: this.paginationPerPage, orderBy: this.orderBy, diff --git a/src/components/modules/collections/CollectionRecommendationsPanel.vue b/src/components/modules/collections/CollectionRecommendationsPanel.vue index 2e855c69d..84ab0edf5 100644 --- a/src/components/modules/collections/CollectionRecommendationsPanel.vue +++ b/src/components/modules/collections/CollectionRecommendationsPanel.vue @@ -272,7 +272,7 @@ export default { filters: recommenderResponseToFilters(this.response, this.recommendersSettings).concat(collectionExlusionFilter), relevanceContext: recommenderResponseToRelevanceContext(this.response, this.recommendersSettings), pagination: { - skip: (this.paginationCurrentPage - 1) * this.paginationPerPage, + offset: (this.paginationCurrentPage - 1) * this.paginationPerPage, limit: this.paginationPerPage } } diff --git a/src/components/modules/textReuse/TextReuseOverview.vue b/src/components/modules/textReuse/TextReuseOverview.vue index ff800ee53..2f19e9827 100644 --- a/src/components/modules/textReuse/TextReuseOverview.vue +++ b/src/components/modules/textReuse/TextReuseOverview.vue @@ -19,7 +19,7 @@