Remove lucene from search tests

This commit is contained in:
Adria Navarro 2024-10-21 13:50:03 +02:00
parent 655cd353e7
commit 08a9488194
2 changed files with 442 additions and 479 deletions

View File

@ -49,7 +49,6 @@ import { cloneDeep } from "lodash/fp"
describe.each([
["in-memory", undefined],
["lucene", undefined],
["sqs", undefined],
[DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)],
[DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)],
@ -57,14 +56,11 @@ describe.each([
[DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
[DatabaseName.ORACLE, getDatasource(DatabaseName.ORACLE)],
])("search (%s)", (name, dsProvider) => {
const isSqs = name === "sqs"
const isLucene = name === "lucene"
const isInMemory = name === "in-memory"
const isInternal = isSqs || isLucene || isInMemory
const isSql = !isInMemory && !isLucene
const isInternal = !dsProvider
const isSql = !isInMemory
const config = setup.getConfig()
let envCleanup: (() => void) | undefined
let datasource: Datasource | undefined
let client: Knex | undefined
let tableOrViewId: string
@ -98,9 +94,6 @@ describe.each([
await features.testutils.withFeatureFlags("*", { SQS: true }, () =>
config.init()
)
envCleanup = features.testutils.setFeatureFlags("*", {
SQS: isSqs,
})
if (config.app?.appId) {
config.app = await config.api.application.update(config.app?.appId, {
@ -124,9 +117,6 @@ describe.each([
afterAll(async () => {
setup.afterAll()
if (envCleanup) {
envCleanup()
}
})
async function createTable(schema: TableSchema) {
@ -176,11 +166,6 @@ describe.each([
])("from %s", (sourceType, createTableOrView) => {
const isView = sourceType === "view"
if (isView && isLucene) {
// Some tests don't have the expected result in views via lucene, and given that it is getting deprecated, we exclude them from the tests
return
}
class SearchAssertion {
constructor(private readonly query: SearchRowRequest) {}
@ -553,7 +538,6 @@ describe.each([
])
})
!isLucene &&
it("should return all rows matching the session user firstname when logical operator used", async () => {
await expectQuery({
$and: {
@ -988,7 +972,6 @@ describe.each([
}).toFindNothing()
})
!isLucene &&
it("ignores low if it's an empty object", async () => {
await expectQuery({
// @ts-ignore
@ -996,7 +979,6 @@ describe.each([
}).toContainExactly([{ name: "foo" }, { name: "bar" }])
})
!isLucene &&
it("ignores high if it's an empty object", async () => {
await expectQuery({
// @ts-ignore
@ -1156,10 +1138,6 @@ describe.each([
await expectQuery({ oneOf: { age: [2] } }).toFindNothing()
})
// I couldn't find a way to make this work in Lucene and given that
// we're getting rid of Lucene soon I wasn't inclined to spend time on
// it.
!isLucene &&
it("can convert from a string", async () => {
await expectQuery({
oneOf: {
@ -1169,10 +1147,6 @@ describe.each([
}).toContainExactly([{ age: 1 }])
})
// I couldn't find a way to make this work in Lucene and given that
// we're getting rid of Lucene soon I wasn't inclined to spend time on
// it.
!isLucene &&
it("can find multiple values for same column", async () => {
await expectQuery({
oneOf: {
@ -1760,10 +1734,6 @@ describe.each([
})
})
// Range searches against bigints don't seem to work at all in Lucene, and I
// couldn't figure out why. Given that we're replacing Lucene with SQS,
// we've decided not to spend time on it.
!isLucene &&
describe("range", () => {
it("successfully finds a row", async () => {
await expectQuery({
@ -1897,14 +1867,12 @@ describe.each([
}).toFindNothing()
})
isSqs &&
it("can search using just a low value", async () => {
await expectQuery({
range: { auto: { low: 9 } },
}).toContainExactly([{ auto: 9 }, { auto: 10 }])
})
isSqs &&
it("can search using just a high value", async () => {
await expectQuery({
range: { auto: { high: 2 } },
@ -1912,13 +1880,13 @@ describe.each([
})
})
isSqs &&
describe("sort", () => {
it("sorts ascending", async () => {
await expectSearch({
query: {},
sort: "auto",
sortOrder: SortOrder.ASCENDING,
sortType: SortType.NUMBER,
}).toMatchExactly([
{ auto: 1 },
{ auto: 2 },
@ -1938,6 +1906,7 @@ describe.each([
query: {},
sort: "auto",
sortOrder: SortOrder.DESCENDING,
sortType: SortType.NUMBER,
}).toMatchExactly([
{ auto: 10 },
{ auto: 9 },
@ -2273,8 +2242,6 @@ describe.each([
})
})
// This will never work for Lucene.
!isLucene &&
// It also can't work for in-memory searching because the related table name
// isn't available.
!isInMemory &&
@ -2728,8 +2695,6 @@ describe.each([
})
})
// lucene can't count the total rows
!isLucene &&
describe("row counting", () => {
beforeAll(async () => {
tableOrViewId = await createTableOrView({
@ -2946,9 +2911,7 @@ describe.each([
})
})
// This was never actually supported in Lucene but SQS does support it, so may
// as well have a test for it.
;(isSqs || isInMemory) &&
isInternal &&
describe("space at start of column name", () => {
beforeAll(async () => {
tableOrViewId = await createTableOrView({
@ -2981,7 +2944,7 @@ describe.each([
})
})
isSqs &&
isInternal &&
!isView &&
describe("duplicate columns", () => {
beforeAll(async () => {
@ -3143,7 +3106,6 @@ describe.each([
})
})
!isLucene &&
describe("$and", () => {
beforeAll(async () => {
tableOrViewId = await createTableOrView({
@ -3221,10 +3183,7 @@ describe.each([
await expect(
expectQuery({
$and: {
conditions: [
{ equal: { age: 10 } },
"invalidCondition" as any,
],
conditions: [{ equal: { age: 10 } }, "invalidCondition" as any],
},
}).toFindNothing()
).rejects.toThrow(
@ -3277,7 +3236,6 @@ describe.each([
})
})
!isLucene &&
describe("$or", () => {
beforeAll(async () => {
tableOrViewId = await createTableOrView({

View File

@ -645,7 +645,12 @@ export function search<T extends Record<string, any>>(
): SearchResponse<T> {
let result = runQuery(docs, query.query)
if (query.sort) {
result = sort(result, query.sort, query.sortOrder || SortOrder.ASCENDING)
result = sort(
result,
query.sort,
query.sortOrder || SortOrder.ASCENDING,
query.sortType
)
}
const totalRows = result.length
if (query.limit) {