-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/return-filename-with-text-snippets (#7373)
* index filename with fulltext object * return filename on eleasticsearch query * add migrations to apply reindex
- Loading branch information
Showing
9 changed files
with
97 additions
and
7 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
app/api/migrations/migrations/169-reindex_persist_filename_with_fullText_object/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Db } from 'mongodb'; | ||
|
||
export default { | ||
delta: 169, | ||
|
||
name: 'reindex_persist_filename_with_fullText_object', | ||
|
||
description: | ||
"We're now indexing document.filename within the fullText object on elasticsearch, this is usefull because on search/v2 endpoint we need to return which filename each text snippet belongs to.", | ||
|
||
reindex: true, | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
async up(db: Db) { | ||
process.stdout.write(`${this.name}...\r\n`); | ||
}, | ||
}; |
37 changes: 37 additions & 0 deletions
37
...name_with_fullText_object/specs/169-reindex_persist_filename_with_fullText_object.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Db } from 'mongodb'; | ||
|
||
import testingDB from 'api/utils/testing_db'; | ||
import migration from '../index'; | ||
import { Fixture } from '../types'; | ||
import { fixtures } from './fixtures'; | ||
|
||
let db: Db | null; | ||
|
||
const initTest = async (fixture: Fixture) => { | ||
await testingDB.setupFixturesAndContext(fixture); | ||
db = testingDB.mongodb!; | ||
await migration.up(db); | ||
}; | ||
|
||
beforeAll(async () => { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
jest.spyOn(process.stdout, 'write').mockImplementation((str: string | Uint8Array) => true); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testingDB.tearDown(); | ||
}); | ||
|
||
describe('migration test', () => { | ||
beforeAll(async () => { | ||
await initTest(fixtures); | ||
}); | ||
|
||
it('should have a delta number', () => { | ||
expect(migration.delta).toBe(169); | ||
}); | ||
|
||
it('should check if a reindex is needed', async () => { | ||
expect(migration.reindex).toBe(true); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
...migrations/migrations/169-reindex_persist_filename_with_fullText_object/specs/fixtures.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ObjectId } from 'mongodb'; | ||
import { Fixture } from '../types'; | ||
|
||
const fixtures: Fixture = { | ||
entities: [ | ||
{ | ||
_id: new ObjectId(), | ||
title: 'test_doc', | ||
}, | ||
], | ||
}; | ||
|
||
export { fixtures }; |
13 changes: 13 additions & 0 deletions
13
app/api/migrations/migrations/169-reindex_persist_filename_with_fullText_object/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ObjectId } from 'mongodb'; | ||
|
||
interface Entity { | ||
_id: ObjectId; | ||
title: string; | ||
[k: string]: unknown | undefined; | ||
} | ||
|
||
interface Fixture { | ||
entities: Entity[]; | ||
} | ||
|
||
export type { Entity, Fixture }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters