@ekodb/ekodb-client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/search.js ADDED
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ /**
3
+ * Full-text and vector search support for ekoDB
4
+ *
5
+ * This module provides comprehensive search capabilities including:
6
+ * - Full-text search with fuzzy matching
7
+ * - Vector/semantic search
8
+ * - Hybrid search (text + vector)
9
+ * - Field weighting and boosting
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SearchQueryBuilder = void 0;
13
+ /**
14
+ * Builder for constructing search queries with fluent API
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const query = new SearchQueryBuilder("john")
19
+ * .fields(["name", "email"])
20
+ * .fuzzy(true)
21
+ * .minScore(0.5)
22
+ * .limit(10)
23
+ * .build();
24
+ *
25
+ * const results = await client.search("users", query);
26
+ * ```
27
+ */
28
+ class SearchQueryBuilder {
29
+ constructor(queryString) {
30
+ this.query = { query: queryString };
31
+ }
32
+ /**
33
+ * Set the language for stemming
34
+ */
35
+ language(language) {
36
+ this.query.language = language;
37
+ return this;
38
+ }
39
+ /**
40
+ * Enable case-sensitive search
41
+ */
42
+ caseSensitive(enabled = true) {
43
+ this.query.case_sensitive = enabled;
44
+ return this;
45
+ }
46
+ /**
47
+ * Enable fuzzy matching
48
+ */
49
+ fuzzy(enabled = true) {
50
+ this.query.fuzzy = enabled;
51
+ return this;
52
+ }
53
+ /**
54
+ * Set minimum score threshold
55
+ */
56
+ minScore(score) {
57
+ this.query.min_score = score;
58
+ return this;
59
+ }
60
+ /**
61
+ * Set fields to search in
62
+ */
63
+ fields(fields) {
64
+ this.query.fields = fields;
65
+ return this;
66
+ }
67
+ /**
68
+ * Set field weights
69
+ */
70
+ weights(weights) {
71
+ this.query.weights = weights;
72
+ return this;
73
+ }
74
+ /**
75
+ * Enable stemming
76
+ */
77
+ enableStemming(enabled = true) {
78
+ this.query.enable_stemming = enabled;
79
+ return this;
80
+ }
81
+ /**
82
+ * Boost exact matches
83
+ */
84
+ boostExact(enabled = true) {
85
+ this.query.boost_exact = enabled;
86
+ return this;
87
+ }
88
+ /**
89
+ * Set maximum edit distance for fuzzy matching
90
+ */
91
+ maxEditDistance(distance) {
92
+ this.query.max_edit_distance = distance;
93
+ return this;
94
+ }
95
+ /**
96
+ * Set query vector for semantic search
97
+ */
98
+ vector(vector) {
99
+ this.query.vector = vector;
100
+ return this;
101
+ }
102
+ /**
103
+ * Set vector field name
104
+ */
105
+ vectorField(field) {
106
+ this.query.vector_field = field;
107
+ return this;
108
+ }
109
+ /**
110
+ * Set vector similarity metric
111
+ */
112
+ vectorMetric(metric) {
113
+ this.query.vector_metric = metric;
114
+ return this;
115
+ }
116
+ /**
117
+ * Set number of vector results (k-nearest neighbors)
118
+ */
119
+ vectorK(k) {
120
+ this.query.vector_k = k;
121
+ return this;
122
+ }
123
+ /**
124
+ * Set minimum similarity threshold
125
+ */
126
+ vectorThreshold(threshold) {
127
+ this.query.vector_threshold = threshold;
128
+ return this;
129
+ }
130
+ /**
131
+ * Set text search weight for hybrid search
132
+ */
133
+ textWeight(weight) {
134
+ this.query.text_weight = weight;
135
+ return this;
136
+ }
137
+ /**
138
+ * Set vector search weight for hybrid search
139
+ */
140
+ vectorWeight(weight) {
141
+ this.query.vector_weight = weight;
142
+ return this;
143
+ }
144
+ /**
145
+ * Bypass ripple cache
146
+ */
147
+ bypassRipple(bypass = true) {
148
+ this.query.bypass_ripple = bypass;
149
+ return this;
150
+ }
151
+ /**
152
+ * Bypass cache
153
+ */
154
+ bypassCache(bypass = true) {
155
+ this.query.bypass_cache = bypass;
156
+ return this;
157
+ }
158
+ /**
159
+ * Set maximum number of results to return
160
+ */
161
+ limit(limit) {
162
+ this.query.limit = limit;
163
+ return this;
164
+ }
165
+ /**
166
+ * Build the final SearchQuery object
167
+ */
168
+ build() {
169
+ // Normalize fields to comma-separated string if array
170
+ if (Array.isArray(this.query.fields)) {
171
+ this.query.fields = this.query.fields.join(",");
172
+ }
173
+ // Normalize weights to string format if object
174
+ if (this.query.weights && typeof this.query.weights === "object") {
175
+ const weightEntries = Object.entries(this.query.weights)
176
+ .map(([field, weight]) => `${field}:${weight}`)
177
+ .join(",");
178
+ this.query.weights = weightEntries;
179
+ }
180
+ return this.query;
181
+ }
182
+ }
183
+ exports.SearchQueryBuilder = SearchQueryBuilder;
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@ekodb/ekodb-client",
3
+ "version": "0.1.0",
4
+ "description": "Official TypeScript/JavaScript client for ekoDB",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "prepare": "npm run build"
10
+ },
11
+ "keywords": [
12
+ "ekodb",
13
+ "database",
14
+ "client",
15
+ "typescript"
16
+ ],
17
+ "author": "ekoDB",
18
+ "license": "MIT",
19
+ "devDependencies": {
20
+ "@types/node": "^20.0.0",
21
+ "@types/ws": "^8.5.10",
22
+ "typescript": "^5.3.0"
23
+ },
24
+ "dependencies": {
25
+ "ws": "^8.16.0"
26
+ }
27
+ }