AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
fix(console): reject incomplete range comparisons
Rashen Anupama0e109f1301c7
diff --git a/xerj-ux/src/data/search-body.js b/xerj-ux/src/data/search-body.jsindex f119d2c95..b5e7bf96e 100644--- a/xerj-ux/src/data/search-body.js+++ b/xerj-ux/src/data/search-body.js@@ -105,6 +105,13 @@ function fieldClause(kind, f, text, roles) {return clause;}+// Capture the complete operator before checking the value: requiring a value+// in the regex lets `page>=` backtrack into `page > "="`.+function rangeMatch(text) {+ const m = text.match(/^([\w.]+)\s*(>=|<=|>|<)\s*(.*)$/);+ return m && m[3].trim() ? m : null;+}+/*** Why a (q, type) pair cannot run, or null. TERM and RANGE need* `field=value` / `field>=value`; free text used to fall through to@@ -116,7 +123,7 @@ export function queryProblem(q, type) {const text = (q || '').trim();if (!text) return null;if (type === 'term' && !/^([\w.]+)\s*=\s*(.+)$/.test(text)) return 'TERM needs field=value — for example ax_format=eml. Nothing was searched.';- if (type === 'range' && !/^([\w.]+)\s*(>=|<=|>|<)\s*(.+)$/.test(text)) return 'RANGE needs field>=value (or >, <=, <) — for example page>=2. Nothing was searched.';+ if (type === 'range' && !rangeMatch(text)) return 'RANGE needs field>=value (or >, <=, <) — for example page>=2. Nothing was searched.';return null;}@@ -140,7 +147,7 @@ export function buildQueryClause(q, type, roles) {return m ? { term: { [m[1]]: m[2].trim() } } : { match_all: {} };}case 'range': {- const m = text.match(/^([\w.]+)\s*(>=|<=|>|<)\s*(.+)$/);+ const m = rangeMatch(text);if (!m) return { match_all: {} };const [, f, op, raw] = m;const k = op === '>=' ? 'gte' : op === '<=' ? 'lte' : op === '>' ? 'gt' : 'lt';diff --git a/xerj-ux/test/search-body.test.mjs b/xerj-ux/test/search-body.test.mjsnew file mode 100644index 000000000..36cddefb9--- /dev/null+++ b/xerj-ux/test/search-body.test.mjs@@ -0,0 +1,48 @@+import test from 'node:test';+import assert from 'node:assert/strict';+import { buildQueryClause, queryProblem } from '../src/data/search-body.js';+import { makeReaderApi } from '../src/data/reader-api.js';++test('RANGE requires a value after the complete comparison operator', () => {+ for (const op of ['>=', '<=', '>', '<']) {+ for (const q of [`page${op}`, ` page ${op} `]) {+ assert.match(queryProblem(q, 'range') || '', /RANGE needs field>=value/, q);+ assert.deepEqual(buildQueryClause(q, 'range', {}), { match_all: {} }, q);+ }+ }+});++test('Reader refuses incomplete ranges before mapping or search requests', async () => {+ const sent = [];+ const api = makeReaderApi({+ guest: false,+ async mapping() { sent.push('mapping'); return {}; },+ async search() { sent.push('search'); return { hits: { total: { value: 0 }, hits: [] } }; },+ });+ for (const q of ['page>=', 'page<=', 'page>', 'page<', 'page >= ']) {+ const result = await api.search('ax-docs', { q, type: 'range' });+ assert.match(result.hint || '', /RANGE needs field>=value/, q);+ assert.deepEqual(result.hits, [], q);+ assert.equal(result.total, 0, q);+ }+ assert.deepEqual(sent, [], 'invalid filters must not reach the transport');+});++test('RANGE preserves comparison operators, numeric and date values, and empty browsing', () => {+ for (const [q, field, op, value] of [+ ['page>=2', 'page', 'gte', 2],+ ['page <= 3', 'page', 'lte', 3],+ ['page>0', 'page', 'gt', 0],+ ['score<-1.5', 'score', 'lt', -1.5],+ ['email_date>=2026-01-01', 'email_date', 'gte', '2026-01-01'],+ ['email_date <= now-1d/d', 'email_date', 'lte', 'now-1d/d'],+ ['version.name>beta', 'version.name', 'gt', 'beta'],+ ]) {+ assert.equal(queryProblem(q, 'range'), null, q);+ assert.deepEqual(buildQueryClause(q, 'range', {}), { range: { [field]: { [op]: value } } }, q);+ }+ for (const q of ['', ' ']) {+ assert.equal(queryProblem(q, 'range'), null);+ assert.deepEqual(buildQueryClause(q, 'range', {}), { match_all: {} });+ }+});