@@ -11,13 +11,15 @@ export class PostgresFts implements IFullTextSearch {
1111 /** The content table is stored during createIndex for use by other methods. */
1212 private _contentTable = '' ;
1313 private _columns : string [ ] = [ ] ;
14+ private _lang = 'english' ;
1415
1516 createIndex ( config : { table : string ; columns : string [ ] ; contentTable ?: string ; tokenizer ?: string } ) : string {
1617 const ct = config . contentTable ?? config . table ;
1718 this . _contentTable = ct ;
1819 this . _columns = config . columns ;
1920 const colConcat = config . columns . map ( ( c ) => `COALESCE(${ c } , '')` ) . join ( " || ' ' || " ) ;
2021 const lang = this . _tokenizerToLang ( config . tokenizer ) ;
22+ this . _lang = lang ;
2123
2224 return [
2325 `ALTER TABLE ${ ct } ADD COLUMN IF NOT EXISTS _tsv tsvector` ,
@@ -27,24 +29,26 @@ export class PostgresFts implements IFullTextSearch {
2729 }
2830
2931 matchClause ( _indexName : string , queryPlaceholder : string ) : string {
30- return `_tsv @@ plainto_tsquery('english ', ${ queryPlaceholder } )` ;
32+ return `_tsv @@ plainto_tsquery('${ this . _lang } ', ${ queryPlaceholder } )` ;
3133 }
3234
3335 rankExpression ( _indexName : string , queryPlaceholder ?: string ) : string {
3436 const qp = queryPlaceholder ?? '$1' ;
35- return `ts_rank(_tsv, plainto_tsquery('english ', ${ qp } ))` ;
37+ return `ts_rank(_tsv, plainto_tsquery('${ this . _lang } ', ${ qp } ))` ;
3638 }
3739
3840 rebuildCommand ( _indexName : string ) : string {
3941 const ct = this . _contentTable ;
4042 const colConcat = this . _columns . map ( ( c ) => `COALESCE(${ c } , '')` ) . join ( " || ' ' || " ) ;
41- return `UPDATE ${ ct } SET _tsv = to_tsvector('english ', ${ colConcat } )` ;
43+ return `UPDATE ${ ct } SET _tsv = to_tsvector('${ this . _lang } ', ${ colConcat } )` ;
4244 }
4345
44- syncInsert ( _indexName : string , rowIdExpr : string , columns : string [ ] ) : string {
46+ syncInsert ( _indexName : string , _rowIdExpr : string , columns : string [ ] ) : string {
4547 const ct = this . _contentTable ;
46- const colConcat = columns . map ( ( c ) => `COALESCE(${ c } , '')` ) . join ( " || ' ' || " ) ;
47- return `UPDATE ${ ct } SET _tsv = to_tsvector('english', ${ colConcat } ) WHERE rowid = ${ rowIdExpr } ` ;
48+ const colConcat = columns
49+ . map ( ( _ , index ) => `COALESCE($${ index + 2 } , '')` )
50+ . join ( " || ' ' || " ) ;
51+ return `UPDATE ${ ct } SET _tsv = to_tsvector('${ this . _lang } ', ${ colConcat } ) WHERE id = $1` ;
4852 }
4953
5054 sanitizeQuery ( input : string ) : string {
0 commit comments