Skip to content

Commit

Permalink
626 query should be returned in resultset (#627)
Browse files Browse the repository at this point in the history
* version bumps

* trying to appease Github Actions

* return query and options in search result
  • Loading branch information
fergiemcdowall authored Feb 12, 2025
1 parent d63d809 commit f761de6
Show file tree
Hide file tree
Showing 41 changed files with 909 additions and 941 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ on:
- push
jobs:
test:
runs-on: ubuntu-latest
runs-on: macos-latest
strategy:
matrix:
node-version: [18, 20, 22]
steps:
- uses: actions/checkout@v4
- run: npm install
- run: xvfb-run npm test
- run: npm test
timeout-minutes: 5 # If the tests fails, the browser will hang open indefinitely
2 changes: 0 additions & 2 deletions dist/search-index-5.1.3.js

This file was deleted.

2 changes: 2 additions & 0 deletions dist/search-index-5.1.4.js

Large diffs are not rendered by default.

File renamed without changes.
2 changes: 0 additions & 2 deletions dist/search-index-esm-5.1.3.js

This file was deleted.

2 changes: 2 additions & 0 deletions dist/search-index-esm-5.1.4.js

Large diffs are not rendered by default.

File renamed without changes.
4 changes: 2 additions & 2 deletions dist/search-index.js

Large diffs are not rendered by default.

1,221 changes: 428 additions & 793 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 6 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
{
"name": "search-index",
"version": "5.1.3",
"version": "5.1.4",
"description": "A network resilient, persistent full-text search library for the browser and Node.js",
"keywords": [
"search",
"elasticsearch",
"elastic",
"lunr.js",
"flexsearch",
"norch",
"solr"
"offline",
"front-end"
],
"engines": {
"node": ">=12"
Expand Down Expand Up @@ -67,9 +63,9 @@
"stream-browserify": "^3.0.0",
"tape": "5.8.1",
"tape-run": "^11.0.0",
"webpack": "5.93.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.4",
"webpack": "5.97.1",
"webpack-cli": "6.0.1",
"webpack-dev-server": "5.2.0",
"world-bank-dataset": "^1.0.0"
},
"dependencies": {
Expand Down
5 changes: 3 additions & 2 deletions src/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export class Reader {
// This function reads queries in a JSON format and then translates them to
// Promises
#parseJsonQuery = (q, options = {}) => {
// options.PAGE = { NUMBER: 0, SIZE: 10, ...options.PAGE }

const runQuery = cmd => {
// if string or object with only FIELD or VALUE, assume
// that this is a GET
Expand Down Expand Up @@ -44,9 +42,12 @@ export class Reader {
const formatResults = result =>
result.RESULT
? Object.assign(result, {
QUERY: { q, options },
RESULT_LENGTH: result.RESULT.length
})
: {
QUERY: q,
OPTIONS: options,
RESULT: result,
RESULT_LENGTH: result.length
}
Expand Down
2 changes: 1 addition & 1 deletion src/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const packageVersion = "5.1.3"
export const packageVersion = '5.1.4'
4 changes: 4 additions & 0 deletions test/src/514-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ test('simple _SEARCH with 1 clause', async t => {
t.plan(3)
await global[indexName].SEARCH(['Zeppelin']).then(res =>
t.deepEqual(res, {
QUERY: { AND: ['Zeppelin'] },
OPTIONS: { SCORE: { TYPE: 'TFIDF' }, SORT: true },
RESULT: [
{
_id: 3,
Expand All @@ -66,6 +68,8 @@ test('simple _SEARCH with 1 clause', async t => {

await global[indexName].SEARCH(['Zeppelin']).then(res =>
t.deepEqual(res, {
QUERY: { AND: ['Zeppelin'] },
OPTIONS: { SCORE: { TYPE: 'TFIDF' }, SORT: true },
RESULT: [],
RESULT_LENGTH: 0,
PAGING: { NUMBER: 0, SIZE: 20, TOTAL: 0, DOC_OFFSET: 0 }
Expand Down
232 changes: 119 additions & 113 deletions test/src/AND-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,70 +124,72 @@ test('simple _AND with 2 clauses', t => {

test('simple AND with 2 clauses (JSON)', t => {
t.plan(1)
global[indexName]
.QUERY({
AND: ['make:volvo', 'manufacturer:bmw']
})
.then(res => {
t.deepEqual(res, {
RESULT: [
{
_id: '8',
_match: [
{ FIELD: 'make', VALUE: 'volvo', SCORE: '1.00' },
{ FIELD: 'manufacturer', VALUE: 'bmw', SCORE: '1.00' }
]
}
],
RESULT_LENGTH: 1,
PAGING: { NUMBER: 0, SIZE: 20, TOTAL: 1, DOC_OFFSET: 0 }
})
const q = {
AND: ['make:volvo', 'manufacturer:bmw']
}
global[indexName].QUERY(q).then(res => {
t.deepEqual(res, {
QUERY: q,
OPTIONS: {},
RESULT: [
{
_id: '8',
_match: [
{ FIELD: 'make', VALUE: 'volvo', SCORE: '1.00' },
{ FIELD: 'manufacturer', VALUE: 'bmw', SCORE: '1.00' }
]
}
],
RESULT_LENGTH: 1,
PAGING: { NUMBER: 0, SIZE: 20, TOTAL: 1, DOC_OFFSET: 0 }
})
})
})

test('simple AND with 2 clauses (JSON)', t => {
t.plan(1)
global[indexName]
.QUERY({
AND: ['volvo', 'bmw']
})
.then(res => {
t.deepEqual(res, {
RESULT: [
{
_id: '1',
_match: [
{ FIELD: 'brand', VALUE: 'volvo', SCORE: '1.00' },
{ FIELD: 'make', VALUE: 'bmw', SCORE: '1.00' },
{ FIELD: 'manufacturer', VALUE: 'volvo', SCORE: '1.00' }
]
},
{
_id: '9',
_match: [
{ FIELD: 'brand', VALUE: 'volvo', SCORE: '1.00' },
{ FIELD: 'make', VALUE: 'bmw', SCORE: '1.00' }
]
},
{
_id: '8',
_match: [
{ FIELD: 'make', VALUE: 'volvo', SCORE: '1.00' },
{ FIELD: 'manufacturer', VALUE: 'bmw', SCORE: '1.00' }
]
},
{
_id: '3',
_match: [
{ FIELD: 'brand', VALUE: 'bmw', SCORE: '1.00' },
{ FIELD: 'manufacturer', VALUE: 'volvo', SCORE: '1.00' }
]
}
],
RESULT_LENGTH: 4,
PAGING: { NUMBER: 0, SIZE: 20, TOTAL: 1, DOC_OFFSET: 0 }
})
const q = {
AND: ['volvo', 'bmw']
}
global[indexName].QUERY(q).then(res => {
t.deepEqual(res, {
QUERY: q,
OPTIONS: {},
RESULT: [
{
_id: '1',
_match: [
{ FIELD: 'brand', VALUE: 'volvo', SCORE: '1.00' },
{ FIELD: 'make', VALUE: 'bmw', SCORE: '1.00' },
{ FIELD: 'manufacturer', VALUE: 'volvo', SCORE: '1.00' }
]
},
{
_id: '9',
_match: [
{ FIELD: 'brand', VALUE: 'volvo', SCORE: '1.00' },
{ FIELD: 'make', VALUE: 'bmw', SCORE: '1.00' }
]
},
{
_id: '8',
_match: [
{ FIELD: 'make', VALUE: 'volvo', SCORE: '1.00' },
{ FIELD: 'manufacturer', VALUE: 'bmw', SCORE: '1.00' }
]
},
{
_id: '3',
_match: [
{ FIELD: 'brand', VALUE: 'bmw', SCORE: '1.00' },
{ FIELD: 'manufacturer', VALUE: 'volvo', SCORE: '1.00' }
]
}
],
RESULT_LENGTH: 4,
PAGING: { NUMBER: 0, SIZE: 20, TOTAL: 1, DOC_OFFSET: 0 }
})
})
})

test('_AND with no VALUE', t => {
Expand Down Expand Up @@ -246,78 +248,82 @@ test('_AND with no VALUE', t => {

test('AND with no VALUE (JSON)', t => {
t.plan(1)
global[indexName]
.QUERY({
AND: [
const q = {
AND: [
{
FIELD: ['make']
}
]
}
global[indexName].QUERY(q).then(res => {
t.deepEqual(res, {
QUERY: q,
OPTIONS: {},
RESULT: [
{
_id: '1',
_match: [{ FIELD: 'make', VALUE: 'bmw', SCORE: '1.00' }]
},
{
_id: '7',
_match: [{ FIELD: 'make', VALUE: 'bmw', SCORE: '1.00' }]
},
{
_id: '9',
_match: [{ FIELD: 'make', VALUE: 'bmw', SCORE: '1.00' }]
},
{
_id: '0',
_match: [{ FIELD: 'make', VALUE: 'tesla', SCORE: '1.00' }]
},
{
_id: '2',
_match: [{ FIELD: 'make', VALUE: 'tesla', SCORE: '1.00' }]
},
{
_id: '3',
_match: [{ FIELD: 'make', VALUE: 'tesla', SCORE: '1.00' }]
},
{
_id: '6',
_match: [{ FIELD: 'make', VALUE: 'tesla', SCORE: '1.00' }]
},
{
_id: '4',
_match: [{ FIELD: 'make', VALUE: 'volvo', SCORE: '1.00' }]
},
{
FIELD: ['make']
_id: '5',
_match: [{ FIELD: 'make', VALUE: 'volvo', SCORE: '1.00' }]
},
{
_id: '8',
_match: [{ FIELD: 'make', VALUE: 'volvo', SCORE: '1.00' }]
}
]
})
.then(res => {
t.deepEqual(res, {
RESULT: [
{
_id: '1',
_match: [{ FIELD: 'make', VALUE: 'bmw', SCORE: '1.00' }]
},
{
_id: '7',
_match: [{ FIELD: 'make', VALUE: 'bmw', SCORE: '1.00' }]
},
{
_id: '9',
_match: [{ FIELD: 'make', VALUE: 'bmw', SCORE: '1.00' }]
},
{
_id: '0',
_match: [{ FIELD: 'make', VALUE: 'tesla', SCORE: '1.00' }]
},
{
_id: '2',
_match: [{ FIELD: 'make', VALUE: 'tesla', SCORE: '1.00' }]
},
{
_id: '3',
_match: [{ FIELD: 'make', VALUE: 'tesla', SCORE: '1.00' }]
},
{
_id: '6',
_match: [{ FIELD: 'make', VALUE: 'tesla', SCORE: '1.00' }]
},
{
_id: '4',
_match: [{ FIELD: 'make', VALUE: 'volvo', SCORE: '1.00' }]
},
{
_id: '5',
_match: [{ FIELD: 'make', VALUE: 'volvo', SCORE: '1.00' }]
},
{
_id: '8',
_match: [{ FIELD: 'make', VALUE: 'volvo', SCORE: '1.00' }]
}
],
RESULT_LENGTH: 10,
PAGING: { NUMBER: 0, SIZE: 20, TOTAL: 1, DOC_OFFSET: 0 }
})
],
RESULT_LENGTH: 10,
PAGING: { NUMBER: 0, SIZE: 20, TOTAL: 1, DOC_OFFSET: 0 }
})
})
})

// TODO: AND with nested OR

test('AND with no VALUE (JSON)', t => {
t.plan(1)
const { QUERY } = global[indexName]
QUERY({
const q = {
AND: [
'brand:volvo',
{
OR: ['make:bmw', 'make:volvo']
}
]
}).then(res => {
}
QUERY(q).then(res => {
t.deepEqual(res, {
QUERY: q,
OPTIONS: {},
RESULT: [
{
_id: '1',
Expand Down
Loading

0 comments on commit f761de6

Please sign in to comment.