Skip to main content

Interface: ISearchEngine

Defined in: src/types/interfaces/search.interface.ts:273

Search engine interface for Elasticsearch.

Remarks

Provides full-text search, faceted search, and autocomplete for eprints.

Implementation notes:

  • Uses Elasticsearch 8+
  • Indices prefixed with chive-eprints-
  • Ingest pipeline for PDF text extraction
  • Custom analyzers for academic text

Methods

autocomplete()

autocomplete(prefix, limit?): Promise<readonly string[]>

Defined in: src/types/interfaces/search.interface.ts:381

Provides autocomplete suggestions.

Parameters

prefix

string

Partial query string

limit?

number

Maximum number of suggestions

Returns

Promise<readonly string[]>

Suggested completions

Remarks

Uses Elasticsearch completion suggester for fast autocomplete. Suggestions are based on indexed titles and keywords.

Example

const suggestions = await searchEngine.autocomplete('neura', 5);
// ['neural', 'neural networks', 'neuromorphic', ...]

deleteDocument()

deleteDocument(uri): Promise<void>

Defined in: src/types/interfaces/search.interface.ts:401

Removes a document from the index.

Parameters

uri

AtUri

Document URI

Returns

Promise<void>

Promise resolving when deleted

Remarks

Use when an eprint is deleted from the user's PDS.

Example

await searchEngine.deleteDocument(
toAtUri('at://did:plc:abc/pub.chive.eprint.submission/xyz')!
);

facetedSearch()

facetedSearch(query): Promise<FacetedSearchResults>

Defined in: src/types/interfaces/search.interface.ts:360

Performs faceted search with aggregations.

Parameters

query

FacetedSearchQuery

Faceted search query

Returns

Promise<FacetedSearchResults>

Results with facet counts

Remarks

Extends regular search with aggregation results for each facet dimension. Use for browse interfaces with faceted navigation.

Example

const results = await searchEngine.facetedSearch({
q: 'neural networks',
facets: ['subjects', 'year'],
limit: 20
});

console.log('Subjects:', results.facets.subjects);
// [{ value: "Computer Science", count: 150 }, ...]

findSimilarByText()

findSimilarByText(documentUri, options?): Promise<readonly MLTResult[]>

Defined in: src/types/interfaces/search.interface.ts:429

Finds documents similar to a given document using text content.

Parameters

documentUri

AtUri

AT-URI of the source document

options?

MLTOptions

Options controlling the More Like This query

Returns

Promise<readonly MLTResult[]>

Matching documents sorted by similarity score

Remarks

Uses Elasticsearch More Like This query on title, abstract, and keywords to find content-similar documents. Serves as a fallback when embedding-based similarity (SPECTER2) is unavailable.

Example

const similar = await searchEngine.findSimilarByText(
toAtUri('at://did:plc:abc/pub.chive.eprint.submission/xyz')!,
{ limit: 10, minimumShouldMatch: '30%' }
);

for (const result of similar) {
console.log(`${result.uri} (score: ${result.score})`);
}

indexEprint()

indexEprint(eprint): Promise<void>

Defined in: src/types/interfaces/search.interface.ts:304

Indexes an eprint document.

Parameters

eprint

IndexableEprintDocument

Eprint to index

Returns

Promise<void>

Promise resolving when indexed

Remarks

Indexes or updates the eprint in Elasticsearch. If full-text extraction is enabled, triggers PDF processing via ingest pipeline.

Example

await searchEngine.indexEprint({
uri: toAtUri('at://did:plc:abc/pub.chive.eprint.submission/xyz')!,
author: toDID('did:plc:abc')!,
authorName: 'Dr. Jane Smith',
title: 'Neural Networks in Biology',
abstract: 'This paper explores...',
keywords: ['neural networks', 'biology'],
fieldNodes: [
{ id: 'cs-uuid', label: 'Computer Science' },
{ id: 'bio-uuid', label: 'Biology' }
],
createdAt: new Date(),
indexedAt: new Date()
});

search(query): Promise<SearchResults>

Defined in: src/types/interfaces/search.interface.ts:334

Searches eprints.

Parameters

query

SearchQuery

Search query

Returns

Promise<SearchResults>

Search results

Remarks

Performs full-text search across title, abstract, and full-text (if available). Returns results sorted by relevance score.

Example

const results = await searchEngine.search({
q: 'neural networks biology',
filters: {
subjects: ['Computer Science'],
dateFrom: new Date('2024-01-01')
},
limit: 20
});

results.hits.forEach(hit => {
console.log(`${hit.uri} (score: ${hit.score})`);
});