Skip to content

Commit

Permalink
Merge branch 'main' into fix/text-locator-heatmap
Browse files Browse the repository at this point in the history
  • Loading branch information
dopenguin authored Oct 25, 2024
2 parents 0e0817b + 7afd7e5 commit c943c19
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 33 deletions.
7 changes: 3 additions & 4 deletions packages/clients/textLocator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# CHANGELOG

## unreleased

- BREAKING: Adapt client to new backend API. Previous versions are no longer runnable due the backend API change.
- Feature: Implemented document search, that is, the AddressSearch bar now also offers results for documents, and clicking on one will retrieve a list of toponyms from the backend and resolve them against the gazetteer. Previously, we had a "get all documents regarding place" functionality. Now, a "get all places regarding document" feature is implemented. Additionally to the AddressSearch, this can be triggered on documents found in the previously implemented way; the "get all places regarding document" functionality is available from within the GeoSearch result display.
## unpublished

- Breaking: Adapt client to new backend API. Previous versions are no longer runnable due the backend API change.
- Feature: Implement document search, that is, the AddressSearch bar now also offers results for documents and clicking on one will retrieve a list of toponyms from the backend and resolve them against the gazetteer. Previously, we had a "get all documents regarding place" functionality. Now, a "get all places regarding document" feature is implemented. Additionally to the AddressSearch, this can be triggered on documents found in the previously implemented way; the "get all places regarding document" functionality is available from within the GeoSearch result display.

## 1.0.0-alpha.0

Expand Down
22 changes: 10 additions & 12 deletions packages/clients/textLocator/src/components/ResultInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,14 @@ export default Vue.extend({
},
},
computed: {
// duck-typing
isLiterature(): boolean {
isLiterature() {
return Boolean(this.feature.properties.location_hits)
},
// required TS support missing in template; workaround ...
featureAsGeometry(): GeometrySearchState['featureCollection']['features'][number] {
featureAsGeometry() {
return this
.feature as GeometrySearchState['featureCollection']['features'][number]
},
featureAsLiterature(): LiteratureFeature {
featureAsLiterature() {
return this.feature as LiteratureFeature
},
},
Expand All @@ -105,6 +103,13 @@ export default Vue.extend({
.v-icon {
margin-left: 0.5em;
}
.result-info-title-display {
background: #f5f5f5;
color: #333;
max-width: 30ch;
padding: 0.5em 1em;
}
</style>

<style>
Expand All @@ -114,11 +119,4 @@ export default Vue.extend({
margin: 0 !important;
border: 0 !important;
}
.result-info-title-display {
background: #f5f5f5;
color: #333;
max-width: 30ch;
padding: 0.5em 1em;
}
</style>
4 changes: 1 addition & 3 deletions packages/clients/textLocator/src/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ const locales: LanguageOption[] = [
'Es gibt viele Ergebnisse zu der letzten Anfrage. Der Ladevorgang kann einen Moment länger dauern.',
},
error: {
searchCoastalGazetteer:
'Die Suche ist mit einem unbekannten Fehler fehlgeschlagen. Bitte versuchen Sie es später erneut.',
findLiterature:
search:
'Die Suche ist mit einem unbekannten Fehler fehlgeschlagen. Bitte versuchen Sie es später erneut.',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export const makeTreeView = (
{
id: literatureId,
name: title,
count: Object.entries(locationFrequency).reduce(
(accumulator, current) => accumulator + current[1],
count: Object.values(locationFrequency).reduce(
(acc, curr) => acc + curr,
0
),
type: 'text',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const loadErrorInfoToast: [string, object] = [
'plugin/toast/addToast',
{
type: 'error',
text: 'textLocator.error.searchCoastalGazetteer',
text: 'textLocator.error.search',
},
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function searchGeometry(
console.error('@polar/client-text-locator:', e)
this.dispatch('plugin/toast/addToast', {
type: 'error',
text: 'textLocator.error.searchCoastalGazetteer',
text: 'textLocator.error.search',
})
}
return getEmptyFeatureCollection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function searchCoastalGazetteerByToponym(
console.error('@polar/client-text-locator', e)
this.dispatch('plugin/toast/addToast', {
type: 'error',
text: 'textLocator.error.searchCoastalGazetteer',
text: 'textLocator.error.search',
})
}
return getEmptyFeatureCollection()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { CoreGetters, CoreState, PolarStore } from '@polar/lib-custom-types'
import { FeatureCollection, Point } from 'geojson'
import { FeatureCollection } from 'geojson'
import { TitleLocationFrequency } from '../../../types'
import urlSuffix from '../urlSuffix'

const mapResponseToFeatureCollection = (
titleLocationFrequency: TitleLocationFrequency
): FeatureCollection<Point, Record<string, number>> => ({
): FeatureCollection => ({
type: 'FeatureCollection',
features: Object.entries(titleLocationFrequency).map(
([literatureId, { title, location_frequency: locationFrequency }]) => ({
type: 'Feature',
// fake geom to fit APIs; ignored by custom selectLiterature
geometry: { type: 'Point', coordinates: [0, 0] },
properties: locationFrequency,
epsg: null,
id: literatureId,
title,
})
Expand All @@ -33,7 +32,7 @@ export function searchLiterature(
// eslint-disable-next-line @typescript-eslint/naming-convention
'Content-Type': 'application/json',
},
body: JSON.stringify({ search_word: inputValue }),
body: JSON.stringify({ search_word: `${inputValue}*` }),
signal,
})
.then(async (response): Promise<TitleLocationFrequency> => {
Expand All @@ -52,7 +51,7 @@ export function searchLiterature(
console.error(error)
this.dispatch('plugin/toast/addToast', {
type: 'warning',
text: 'common:textLocator.error.findLiterature',
text: 'common:textLocator.error.search',
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import { SearchResultSymbols } from '@polar/plugin-address-search'
import { FeatureCollection } from 'geojson'
import { searchCoastalGazetteerByToponym } from '../../coastalGazetteer/searchToponym'
import { sorter } from '../../coastalGazetteer/responseInterpreter'
import { GeometrySearchState } from '../../../plugins/GeometrySearch/types'
import {
GeometrySearchGetters,
GeometrySearchState,
} from '../../../plugins/GeometrySearch/types'
import { LiteratureFeature, TitleLocationFrequency } from '../../../types'

// NOTE hits (= feature.properties) and featureCollections are in sync; that is, hits[i] had findings featureCollections[i] in gazetteer
const processLiteratureToponyms = (feature: LiteratureFeature) =>
function (
this: PolarStore<GeometrySearchState, GeometrySearchState>,
this: PolarStore<GeometrySearchState, GeometrySearchGetters>,
featureCollections: FeatureCollection[]
) {
const { commit, dispatch } = this
Expand All @@ -21,10 +24,13 @@ const processLiteratureToponyms = (feature: LiteratureFeature) =>
[toponym, count],
index
) => {
// if features found for current toponym, process them
if (featureCollections[index].features.length) {
// best-fitting feature by toponym match is added as representant
const feature = featureCollections[index].features.sort(
sorter(toponym, 'title')
)[0]
// the hit frequency is accumulated
titleLocationFrequencyChild[feature.id || ''] =
(titleLocationFrequencyChild[feature.id || ''] || 0) + count
featureCollection.features.push(feature)
Expand Down Expand Up @@ -61,7 +67,7 @@ export const selectLiterature: SelectResultFunction<
GeometrySearchState,
GeometrySearchState
> = function (
this: PolarStore<GeometrySearchState, GeometrySearchState>,
this: PolarStore<GeometrySearchState, GeometrySearchGetters>,
{ commit, rootGetters },
{ feature }
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export default {
findDocumentsByTitle: '/findDocumentsByTitle',
// NOTE unused atm; POST {"id": documentId } => TitleLocationFrequency
locationsToText: '/locationsToText',
lookupLocation: '/lookup/location',
}

0 comments on commit c943c19

Please sign in to comment.