Skip to content

Commit

Permalink
feat: exact match and migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanyawat-Arsaga committed Nov 25, 2023
1 parent 0da2db3 commit c115988
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/modules/aibou/entities/Topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export class AibouTopicItem {
@Column()
word: string;
@Column({ nullable: true })
reading: string;
@Column({ nullable: true })
notes?: string;
@Column()
tags: string;
Expand Down
7 changes: 6 additions & 1 deletion src/modules/jisho/jisho.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class JishoController {
@Get('/search')
async query(
@Query('q') query: string,
@Query('exact') exact: boolean,
@Query('dictionary') dictionaryId: number,
@Req() req: FastifyRequest,
@Res() res: FastifyReply,
Expand All @@ -48,7 +49,11 @@ export class JishoController {
`SELECT id, temp.word_id, dictionary_id, kanji, reading, entry."text" FROM (
SELECT DISTINCT word_id FROM entry WHERE ${
dictionaryId ? 'dictionary_id = $dictionary and' : ''
} instr(kanji, $term) OR instr(reading, $term) ORDER BY length(entry.kanji) ASC, length(entry.reading) ASC LIMIT $limit
} ${
exact
? `kanji == $term OR reading == $term`
: `instr(kanji, $term) OR instr(reading, $term)`
} ORDER BY length(entry.kanji) ASC, length(entry.reading) ASC LIMIT $limit
) as temp
LEFT JOIN entry ON entry.word_id = temp.word_id
ORDER BY length(entry.kanji) ASC, length(entry.reading) ASC`,
Expand Down

0 comments on commit c115988

Please sign in to comment.