@@ -112,10 +112,13 @@ public function execute_query($filters, $accessinfo, $limit = 0) {
112112 $ highlightopen = self ::HIGHLIGHT_START ;
113113 $ highlightclose = self ::HIGHLIGHT_END ;
114114
115- $ title = "ts_headline(x.title, websearch_to_tsquery(?), 'StartSel= $ highlightopen, StopSel= $ highlightclose') AS title " ;
115+ // Define dictionary to be used
116+ $ dict = "'en' " ;
117+
118+ $ title = "ts_headline( " . $ dict . ", x.title, websearch_to_tsquery( " . $ dict . ", ?), 'StartSel= $ highlightopen, StopSel= $ highlightclose') AS title " ;
116119 $ fullselectparams [] = $ data ->q ;
117120
118- $ content = "ts_headline(x.content, websearch_to_tsquery(?), 'StartSel= $ highlightopen, StopSel= $ highlightclose') AS content " ;
121+ $ content = "ts_headline( " . $ dict . " , x.content, websearch_to_tsquery(" . $ dict . " , ?), 'StartSel=$ highlightopen, StopSel= $ highlightclose') AS content " ;
119122 $ fullselectparams [] = $ data ->q ;
120123
121124 // Fulltext ranking SQL fragment.
@@ -140,9 +143,9 @@ public function execute_query($filters, $accessinfo, $limit = 0) {
140143
141144 $ rank = "(
142145 GREATEST (
143- ts_rank(fulltextindex, websearch_to_tsquery(?)),
146+ ts_rank(fulltextindex, websearch_to_tsquery( " . $ dict . " , ?)),
144147 MAX(
145- ts_rank(filefulltextindex, websearch_to_tsquery(?))
148+ ts_rank(filefulltextindex, websearch_to_tsquery( " . $ dict . " , ?))
146149 )
147150 )
148151 $ courseboostsql $ contextboostsql
@@ -290,9 +293,9 @@ public function execute_query($filters, $accessinfo, $limit = 0) {
290293
291294 // And finally the main query after applying all AND filters.
292295 if (!empty ($ data ->q )) {
293- $ whereands [] = "t.fulltextindex @@ websearch_to_tsquery(?) " ;
296+ $ whereands [] = "t.fulltextindex @@ websearch_to_tsquery( " . $ dict . " , ?) " ;
294297 $ whereparams [] = $ data ->q ;
295- $ fileands [] = " f.fulltextindex @@ websearch_to_tsquery(?) " ;
298+ $ fileands [] = " f.fulltextindex @@ websearch_to_tsquery( " . $ dict . " , ?) " ;
296299 $ fileparams [] = $ data ->q ;
297300 }
298301
@@ -385,6 +388,9 @@ public function execute_query($filters, $accessinfo, $limit = 0) {
385388 public function add_document ($ document , $ fileindexing = false ) {
386389 global $ DB ;
387390
391+ // Define dictionary to be used
392+ $ dict = "'en' " ;
393+
388394 $ doc = (object )$ document ->export_for_engine ();
389395
390396 $ doc ->docid = $ doc ->id ;
@@ -400,10 +406,10 @@ public function add_document($document, $fileindexing = false) {
400406 }
401407
402408 $ sql = "UPDATE {search_postgresfulltext} SET fulltextindex =
403- setweight(to_tsvector(coalesce(title, '')), 'A') ||
404- setweight(to_tsvector(coalesce(content, '')), 'B') ||
405- setweight(to_tsvector(coalesce(description1, '')), 'C') ||
406- setweight(to_tsvector(coalesce(description2, '')), 'C')
409+ setweight(to_tsvector( " . $ dict . " , coalesce(title, '')), 'A') ||
410+ setweight(to_tsvector( " . $ dict . " , coalesce(content, '')), 'B') ||
411+ setweight(to_tsvector( " . $ dict . " , coalesce(description1, '')), 'C') ||
412+ setweight(to_tsvector( " . $ dict . " , coalesce(description2, '')), 'C')
407413 WHERE id = ? " ;
408414
409415 $ DB ->execute ($ sql , array ($ id ));
@@ -584,6 +590,9 @@ protected function delete_indexed_file($fileid) {
584590 protected function add_stored_file ($ document , $ storedfile ) {
585591 global $ DB , $ CFG ;
586592
593+ // Define dictionary to be used
594+ $ dict = "'en' " ;
595+
587596 if ($ storedfile ->get_filesize () > ($ this ->config ->maxindexfilekb * 1024 ) || $ this ->config ->maxindexfilekb == 0 ) {
588597 echo "Skipping " .$ storedfile ->get_filename ()." larger than {$ this ->config ->maxindexfilekb } KB \n" ;
589598 return true ;
@@ -602,7 +611,7 @@ protected function add_stored_file($document, $storedfile) {
602611 try {
603612 $ sql = "UPDATE {search_postgresfulltext_file}
604613 SET title = :title, fileid = :fileid, modified = :modified, filecontenthash = :filecontenthash,
605- fulltextindex = setweight(to_tsvector(:textdoc), 'B') || setweight(to_tsvector(:texttitle), 'A')
614+ fulltextindex = setweight(to_tsvector( " . $ dict . " , :textdoc), 'B') || setweight(to_tsvector(" . $ dict . " , :texttitle), 'A')
606615 WHERE id = :id " ;
607616
608617 $ params = array (
0 commit comments