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

View File

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