Skip to content
Snippets Groups Projects
Commit e15b94fc authored by Erwan Rouchet's avatar Erwan Rouchet Committed by Valentin Rigal
Browse files

Entypescripten the search API helpers

parent c977ea3f
No related branches found
No related tags found
1 merge request!1518Entypescripten the search API helpers
import axios from 'axios'
import { unique } from '.'
// Search elements, transcriptions, etc. with facets
export const searchCorpus = unique(async ({ corpus, ...params }) => (await axios.get(`/corpus/${corpus}/search/`, { params })).data)
export const startIndexation = unique(async ({ corpusId, ...body }) => (await axios.post(`/corpus/${corpusId}/index/`, body)).data)
import axios from 'axios'
import { unique } from '.'
import { UUID } from '@/types'
import { SearchQuery, SearchResponse } from '@/types/search'
export const searchCorpus = unique(async (corpusId: UUID, query: SearchQuery): Promise<SearchResponse> => (await axios.get(`/corpus/${corpusId}/search/`, { params: query })).data)
export interface SearchIndexParams {
/**
* Drop existing search index before reindexing.
*/
drop?: boolean
}
export const startIndexation = unique(async (corpusId: UUID, payload: SearchIndexParams = {}) => (await axios.post(`/corpus/${corpusId}/index/`, payload)).data)
......@@ -19,7 +19,7 @@ export const mutations = {
export const actions = {
async corpus ({ commit }, { corpus, ...payload }) {
try {
const data = await api.searchCorpus({ corpus, ...removeEmptyStrings(payload) })
const data = await api.searchCorpus(corpus, removeEmptyStrings(payload))
commit('setDocuments', data)
} catch (err) {
commit('setDocuments', null)
......@@ -28,7 +28,7 @@ export const actions = {
},
async indexCorpus (_, { corpusId, ...payload }) {
try {
await api.startIndexation({ corpusId, ...payload })
await api.startIndexation(corpusId, payload)
} finally {
useJobsStore().list()
}
......
import { METADATA_TYPES, PROCESS_STATES, PROCESS_MODES, DATASET_STATES, CLASSIFICATION_STATES } from './config'
import { S3FileStatus, GitRefType, WorkerVersionGPUUsage, WorkerVersionState, ProcessActivityState, ModelVersionState } from './enums'
import { METADATA_TYPES, PROCESS_STATES, PROCESS_MODES, DATASET_STATES, CLASSIFICATION_STATES } from '@/config'
import { S3FileStatus, GitRefType, WorkerVersionGPUUsage, WorkerVersionState, ProcessActivityState, ModelVersionState } from '@/enums'
/**
* A universally unique identifier, using the format
......
import { MetaDataType, PageNumberPagination, UUID } from '.'
interface SearchFacets {
element_type: string
element_worker: string
transcription_worker: string
classification_name: string
classification_worker: string
metadata_name: string
metadata_type: MetaDataType
metadata_worker: string
entity_type: string
entity_worker: string
}
export type SearchSort = 'relevance' | 'element_name'
export type SearchSource = 'element' | 'entity' | 'metadata' | 'transcription'
// A search query allows filtering on all facets, since that's what they are for, so we do not have to repeat them
export interface SearchQuery extends Partial<SearchFacets> {
query: string
only_facets?: boolean
sort?: SearchSort
/**
* List of sources of search results.
*
* Since this is a query parameter, this can be a single source and not an array, and will be converted to an array by the backend.
*/
sources?: SearchSource | SearchSource[]
}
/**
* Either all the properties of this type are of their defined type, or all the properties are `null`.
* There cannot be both null and non-null properties at once.
*/
type NullableProperties<T> = T | { [K in keyof T]: null }
export type SearchResult = {
id: UUID
element_id: UUID
element_text: string
element_type: string
element_worker: string | null
element_image: string | null
}
// An element's parent, when there is one, always has all its properties
& NullableProperties<{
parent_id: UUID
parent_name: string
parent_type: string
}>
& NullableProperties<{
transcription_id: UUID
transcription_text: string
/*
* The confidence and worker are still nullable even when there is a transcription,
* but they can only be set if the transcription ID and text are set.
*/
transcription_confidence: number | null
transcription_worker: string | null
}>
& NullableProperties<{
classification_id: UUID
classification_name: string
classification_confidence: number | null
classification_worker: string | null
}>
& NullableProperties<{
metadata_id: UUID
metadata_name: string
metadata_text: string
metadata_type: MetaDataType
metadata_worker: string | null
}>
& NullableProperties<{
entity_id: UUID
entity_text: string
entity_type: string
entity_worker: string | null
}>
// When only_facets is set to false, the results will be omitted.
type SearchPagination<T> = Omit<PageNumberPagination<T>, 'results'> & { results: T[] | null }
export type SearchFacetsResponse = {
// Each search facet name is always defined
[Facet in keyof SearchFacets]: {
// The keys only are of the facet's type, and no key is guaranteed to be present
[value in SearchFacets[Facet]]?: number
}
}
export interface SearchResponse extends SearchPagination<SearchResult> {
facets: SearchFacetsResponse
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment