-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add fulltext parser option (#5380)
* feat: add fulltext parser option * test: add missing hook * fix: revert aurora query runner * fix: synchronize parser * revert: "fix: synchronize parser" This reverts commit d37909f.
- Loading branch information
Showing
12 changed files
with
153 additions
and
7 deletions.
There are no files selected for viewing
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
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
18 changes: 18 additions & 0 deletions
18
test/functional/indices/fulltext-index-test/entity/Post.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,18 @@ | ||
import {Column, Entity, PrimaryGeneratedColumn} from "../../../../../src"; | ||
import {Index} from "../../../../../src/decorator/Index"; | ||
|
||
@Entity() | ||
export class Post { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Index({ fulltext: true }) | ||
@Column() | ||
default: string; | ||
|
||
@Index({ fulltext: true, parser: "ngram" }) | ||
@Column() | ||
ngram: string; | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
test/functional/indices/fulltext-index-test/fulltext-index-test.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,80 @@ | ||
import "reflect-metadata"; | ||
import {Connection} from "../../../../src"; | ||
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils"; | ||
import {expect} from "chai"; | ||
import { Post } from "./entity/Post"; | ||
|
||
describe("indices > fulltext index", () => { | ||
|
||
let connections: Connection[]; | ||
before(async () => { | ||
connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
enabledDrivers: ["mysql"], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
}); | ||
}); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should correctly create fulltext indices", () => Promise.all(connections.map(async connection => { | ||
|
||
const queryRunner = connection.createQueryRunner(); | ||
const table = await queryRunner.getTable("post"); | ||
|
||
table!.indices.length.should.be.equal(2); | ||
expect(table!.indices[0].isFulltext).to.be.true; | ||
expect(table!.indices[1].isFulltext).to.be.true; | ||
|
||
await queryRunner.release(); | ||
}))); | ||
|
||
it("with default parser", () => Promise.all(connections.map(async connection => { | ||
|
||
const postRepository = connection.getRepository(Post); | ||
|
||
const text = "This is text"; | ||
const post = new Post(); | ||
post.default = text; | ||
post.ngram = text; | ||
await postRepository.save(post); | ||
|
||
const loadedPost1 = await postRepository | ||
.createQueryBuilder("post") | ||
.where("MATCH(post.default) AGAINST (:token)", { token: "text" }) | ||
.getOne(); | ||
expect(loadedPost1).to.be.exist; | ||
|
||
const loadedPost2 = await postRepository | ||
.createQueryBuilder("post") | ||
.where("MATCH(post.default) AGAINST (:token)", { token: "te" }) | ||
.getOne(); | ||
expect(loadedPost2).to.be.undefined; | ||
}))); | ||
|
||
|
||
it("with ngram parser", () => Promise.all(connections.map(async connection => { | ||
|
||
const postRepository = connection.getRepository(Post); | ||
|
||
const text = "This is text"; | ||
const post = new Post(); | ||
post.default = text; | ||
post.ngram = text; | ||
await postRepository.save(post); | ||
|
||
const loadedPost1 = await postRepository | ||
.createQueryBuilder("post") | ||
.where("MATCH(post.ngram) AGAINST (:token)", { token: "text" }) | ||
.getOne(); | ||
expect(loadedPost1).to.be.exist; | ||
|
||
const loadedPost2 = await postRepository | ||
.createQueryBuilder("post") | ||
.where("MATCH(post.ngram) AGAINST (:token)", { token: "te" }) | ||
.getOne(); | ||
expect(loadedPost2).to.be.exist; | ||
}))); | ||
|
||
}); |