Skip to content

Commit

Permalink
Supporting query parameter and response changes made on the API side (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
theorm authored May 16, 2024
1 parent 66f7da0 commit 49e03ad
Show file tree
Hide file tree
Showing 29 changed files with 129 additions and 125 deletions.
4 changes: 2 additions & 2 deletions src/components/CollectionDetailPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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));
},
},
};
Expand Down
12 changes: 5 additions & 7 deletions src/components/EntitiesDetailPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/EntitiesExplorerPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ export default {
entityId,
filters,
timeResolution: this.punchcardResolution,
skip: skipPerEntity[entityId]
offset: skipPerEntity[entityId]
}));
try {
Expand Down
7 changes: 3 additions & 4 deletions src/components/Explorer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ import {
topics,
newspapers,
collections,
searchFacets
getSearchFacetsService
} from '@/services'
import FacetExplorer from './modules/FacetExplorer';
import TimeFacetExplorer from './modules/TimeFacetExplorer';
Expand Down Expand Up @@ -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({
Expand Down
12 changes: 5 additions & 7 deletions src/components/NewspapersDetailPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions src/components/SelectionMonitor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextReuseClusterDetailPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
}})
Expand Down
4 changes: 2 additions & 2 deletions src/components/TextReuseClusterIdCardPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -122,4 +122,4 @@ export default {
}
}
}
</script>
</script>
4 changes: 2 additions & 2 deletions src/components/TextReuseClusterMonitor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 }],
Expand All @@ -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 }],
Expand Down
6 changes: 3 additions & 3 deletions src/components/TextReuseConnectedClusters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -128,4 +128,4 @@ export default {
.connected-cluster-container {
cursor: pointer;
}
</style>
</style>
2 changes: 1 addition & 1 deletion src/components/TextReuseExplorerPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/components/TextReusePassageMonitor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
}
Expand Down
8 changes: 4 additions & 4 deletions src/components/TopicDetailPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
9 changes: 4 additions & 5 deletions src/components/modules/FilterDynamicRange.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
18 changes: 8 additions & 10 deletions src/components/modules/FilterFacet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -150,7 +150,7 @@ export default defineComponent({
selectedBucketsItems: [],
//
limit: 10,
skip: 0,
offset: 0,
additionalBuckets: [],
isMoreLoading: false,
lazyIsPristine: true,
Expand Down Expand Up @@ -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(
Expand All @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/collections/AddToCollection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
32 changes: 18 additions & 14 deletions src/components/modules/textReuse/TextReuseOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<script>
import Facet from '@/models/Facet'
import { searchFacets } from '@/services'
import { getSearchFacetsService } from '@/services'
export default {
name: 'TextReuseOverview',
Expand All @@ -46,7 +46,6 @@ export default {
/** @returns {{ query: any, hash: string }} */
searchFacetApiQueryParams() {
const query = {
index: this.searchIndex,
limit: 10,
order_by: '-count',
page: 1,
Expand All @@ -64,23 +63,24 @@ export default {
},
},
methods: {
loadFacet(type, opts = {}) {
loadFacets(types, opts = {}) {
// eslint-disable-next-line
console.debug(
'[TextReuseOverview] loadFacet',
type,
'[TextReuseOverview] loadFacets',
types,
'query',
this.searchFacetApiQueryParams.query,
)
searchFacets
.get(type, {
getSearchFacetsService(this.searchIndex)
.find({
query: {
facets: types,
...this.searchFacetApiQueryParams.query,
...opts,
},
})
.then(response => {
response.forEach(result => {
.then(result => {
result.data.forEach(result => {
const facet = this.facets.find(facet => result.type === facet.type)
if (facet) {
facet.numBuckets = result.numBuckets
Expand All @@ -98,11 +98,15 @@ export default {
}
// eslint-disable-next-line
console.debug('[TextReuse] @searchApiQueryParameters \n query:', query)
await this.loadFacet('newspaper')
await this.loadFacet('type,country')
await this.loadFacet('language')
await this.loadFacet('person,location')
await this.loadFacet('topic')
await this.loadFacets([
'newspaper',
'type',
'country',
'language',
'person',
'location',
'topic'
])
},
immediate: true,
deep: false,
Expand Down
Loading

0 comments on commit 49e03ad

Please sign in to comment.