Adding test case for scenario.

This commit is contained in:
mike12345567 2023-03-09 19:15:13 +00:00
parent 212b93cbe9
commit bff6a51af2
2 changed files with 27 additions and 5 deletions

View File

@ -199,6 +199,10 @@ export class QueryBuilder<T> {
return this
}
setAllOr() {
this.query.allOr = true
}
handleSpaces(input: string) {
if (this.noEscaping) {
return input

View File

@ -6,9 +6,13 @@ import { QueryBuilder, paginatedSearch, fullSearch } from "../lucene"
const INDEX_NAME = "main"
const index = `function(doc) {
let props = ["property", "number"]
let props = ["property", "number", "array"]
for (let key of props) {
if (doc[key]) {
if (Array.isArray(doc[key])) {
for (let val of doc[key]) {
index(key, val)
}
} else if (doc[key]) {
index(key, doc[key])
}
}
@ -21,9 +25,14 @@ describe("lucene", () => {
dbName = `db-${newid()}`
// create the DB for testing
db = getDB(dbName)
await db.put({ _id: newid(), property: "word" })
await db.put({ _id: newid(), property: "word2" })
await db.put({ _id: newid(), property: "word3", number: 1 })
await db.put({ _id: newid(), property: "word", array: ["1", "4"] })
await db.put({ _id: newid(), property: "word2", array: ["3", "1"] })
await db.put({
_id: newid(),
property: "word3",
number: 1,
array: ["1", "2"],
})
})
it("should be able to create a lucene index", async () => {
@ -118,6 +127,15 @@ describe("lucene", () => {
const resp = await builder.run()
expect(resp.rows.length).toBe(2)
})
it("should be able to perform an or not contains search", async () => {
const builder = new QueryBuilder(dbName, INDEX_NAME)
builder.addNotContains("array", ["1"])
builder.addNotContains("array", ["2"])
builder.setAllOr()
const resp = await builder.run()
expect(resp.rows.length).toBe(2)
})
})
describe("paginated search", () => {