The minimalistic document archiving platform.
import type { Database } from '../../../app/database/database.types';
import type { DocumentSearchServices } from '../document-search.types';
import { DATABASE_FTS5_DOCUMENT_SEARCH_PROVIDER_NAME } from './database-fts5.document-search-provider.constants';
import { createDocumentSearchRepository } from './database-fts5.repository';
export function createDatabaseFts5DocumentSearchServices({
db,
}: {
db: Database;
}): DocumentSearchServices {
const documentsSearchRepository = createDocumentSearchRepository({ db });
return {
name: DATABASE_FTS5_DOCUMENT_SEARCH_PROVIDER_NAME,
searchDocuments: async ({ searchQuery, organizationId, pageIndex, pageSize, sort }) => {
const { documents, documentsCount } =
await documentsSearchRepository.searchOrganizationDocuments({
organizationId,
searchQuery,
pageIndex,
pageSize,
sort,
});
return {
documents,
documentsCount,
};
},
getDocumentIdsMatchingQuery: async ({ searchQuery, organizationId }) => {
return documentsSearchRepository.getDocumentIdsMatchingQuery({ organizationId, searchQuery });
},
indexDocuments: async ({ documents }) => {
await documentsSearchRepository.indexDocuments({ documents });
},
updateDocuments: async ({ updates }) => {
await documentsSearchRepository.updateDocuments({ updates });
},
deleteDocuments: async ({ documentIds }) => {
await documentsSearchRepository.deleteDocuments({ documentIds });
},
};
}