-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsearch-service.ts
More file actions
101 lines (92 loc) · 2.96 KB
/
Copy pathsearch-service.ts
File metadata and controls
101 lines (92 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
/**
* ISearchService - Search Service Contract
*
* Defines the interface for full-text search capabilities in ObjectStack.
* Concrete implementations (Elasticsearch, MeiliSearch, Typesense, etc.)
* should implement this interface.
*
* Follows Dependency Inversion Principle - plugins depend on this interface,
* not on concrete search engine implementations.
*
* Aligned with CoreServiceName 'search' in core-services.zod.ts.
*/
/**
* Options for search queries
*/
export interface SearchOptions {
/** Filter conditions to narrow results */
filter?: Record<string, unknown>;
/** Maximum number of results to return */
limit?: number;
/** Offset for pagination */
offset?: number;
/** Fields to sort by */
sort?: string[];
/** Fields to include in results */
select?: string[];
/** Facet fields to aggregate */
facets?: string[];
/** Enable highlighting of matching terms */
highlight?: boolean;
}
/**
* A single search result hit
*/
export interface SearchHit {
/** Document ID */
id: string;
/** Relevance score */
score: number;
/** The matched document */
document: Record<string, unknown>;
/** Highlighted fields (if requested) */
highlights?: Record<string, string[]>;
}
/**
* Search result set
*/
export interface SearchResult {
/** Matched documents */
hits: SearchHit[];
/** Total number of matching documents */
totalHits: number;
/** Query processing time in milliseconds */
processingTimeMs?: number;
/** Facet counts (if requested) */
facets?: Record<string, Record<string, number>>;
}
export interface ISearchService {
/**
* Index a document for search
* @param object - Object/collection name
* @param id - Document identifier
* @param document - Document data to index
*/
index(object: string, id: string, document: Record<string, unknown>): Promise<void>;
/**
* Remove a document from the search index
* @param object - Object/collection name
* @param id - Document identifier
*/
remove(object: string, id: string): Promise<void>;
/**
* Search for documents
* @param object - Object/collection name
* @param query - Search query string
* @param options - Search options (filters, pagination, etc.)
* @returns Search results with hits, total count, and optional facets
*/
search(object: string, query: string, options?: SearchOptions): Promise<SearchResult>;
/**
* Bulk index multiple documents at once
* @param object - Object/collection name
* @param documents - Array of documents with id and data
*/
bulkIndex?(object: string, documents: Array<{ id: string; document: Record<string, unknown> }>): Promise<void>;
/**
* Delete all documents in an index
* @param object - Object/collection name
*/
deleteIndex?(object: string): Promise<void>;
}