Add unit test and fix
This commit is contained in:
parent
3451a1817d
commit
4e7e067eef
|
@ -145,7 +145,7 @@ class QueryBuilder {
|
||||||
* @param options The preprocess options
|
* @param options The preprocess options
|
||||||
* @returns {string|*}
|
* @returns {string|*}
|
||||||
*/
|
*/
|
||||||
preprocess(value, { escape, lowercase, wrap } = {}) {
|
preprocess(value, { escape, lowercase, wrap, type } = {}) {
|
||||||
const hasVersion = !!this.version
|
const hasVersion = !!this.version
|
||||||
// Determine if type needs wrapped
|
// Determine if type needs wrapped
|
||||||
const originalType = typeof value
|
const originalType = typeof value
|
||||||
|
@ -159,7 +159,7 @@ class QueryBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrap in quotes
|
// Wrap in quotes
|
||||||
if (originalType === "string" && !isNaN(value) && !escape) {
|
if (originalType === "string" && !isNaN(value) && !type) {
|
||||||
value = `"${value}"`
|
value = `"${value}"`
|
||||||
} else if (hasVersion && wrap) {
|
} else if (hasVersion && wrap) {
|
||||||
value = originalType === "number" ? value : `"${value}"`
|
value = originalType === "number" ? value : `"${value}"`
|
||||||
|
@ -256,6 +256,7 @@ class QueryBuilder {
|
||||||
value = builder.preprocess(value, {
|
value = builder.preprocess(value, {
|
||||||
escape: true,
|
escape: true,
|
||||||
lowercase: true,
|
lowercase: true,
|
||||||
|
type: "string",
|
||||||
})
|
})
|
||||||
return `${key}:${value}*`
|
return `${key}:${value}*`
|
||||||
})
|
})
|
||||||
|
@ -284,6 +285,7 @@ class QueryBuilder {
|
||||||
value = builder.preprocess(value, {
|
value = builder.preprocess(value, {
|
||||||
escape: true,
|
escape: true,
|
||||||
lowercase: true,
|
lowercase: true,
|
||||||
|
type: "fuzzy",
|
||||||
})
|
})
|
||||||
return `${key}:${value}~`
|
return `${key}:${value}~`
|
||||||
})
|
})
|
||||||
|
|
|
@ -173,4 +173,24 @@ describe("internal search", () => {
|
||||||
}, PARAMS)
|
}, PARAMS)
|
||||||
checkLucene(response, `*:* AND NOT column:(a AND b AND c)`, PARAMS)
|
checkLucene(response, `*:* AND NOT column:(a AND b AND c)`, PARAMS)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("test equal without version query", async () => {
|
||||||
|
PARAMS.version = null
|
||||||
|
const response = await search.paginatedSearch({
|
||||||
|
equal: {
|
||||||
|
"column": "1",
|
||||||
|
}
|
||||||
|
}, PARAMS)
|
||||||
|
|
||||||
|
const query = response.rows[0].query
|
||||||
|
const json = JSON.parse(query)
|
||||||
|
if (PARAMS.sort) {
|
||||||
|
expect(json.sort).toBe(`${PARAMS.sort}<${PARAMS.sortType}>`)
|
||||||
|
}
|
||||||
|
if (PARAMS.bookmark) {
|
||||||
|
expect(json.bookmark).toBe(PARAMS.bookmark)
|
||||||
|
}
|
||||||
|
expect(json.include_docs).toBe(true)
|
||||||
|
expect(json.q).toBe(`(*:* AND column:"1") AND tableId:${PARAMS.tableId}`)
|
||||||
|
})
|
||||||
})
|
})
|
Loading…
Reference in New Issue