Просмотр исходного кода

Merge branch 'master' of https://github.com/visuddhinanda/mint

visuddhinanda 4 лет назад
Родитель
Сommit
f76473a925

+ 4 - 2
app/fts/example.php

@@ -37,11 +37,13 @@
       <input type="submit">
     </form>
     <?php
+    require_once '../path.php';
+
     if (empty($q)) {
       echo "Query is empty";
     } else {
       // Connecting, selecting database
-      $dbconn = pg_connect("host=localhost dbname=pali user=postgres password=123456")
+      $dbconn = pg_connect("host="._DB_HOST_." dbname="._DB_NAME_." user="._DB_USERNAME_." password="._DB_PASSWORD_)
       or die('Could not connect: ' . pg_last_error());
 
       // Performing SQL query
@@ -58,7 +60,7 @@
                               'StartSel = <span>, StopSel = </span>')
                  AS highlight,
                  *
-                 FROM fts
+                 FROM fts_texts
                  WHERE
                      full_text_search_weighted
                      @@ websearch_to_tsquery('pali', '$q') OR

+ 9 - 2
app/search/paliword.js

@@ -96,9 +96,16 @@ function render_word_result(worddata) {
 		"&direction=col' target='_blank'>";
 	html += worddata.title + "</a></div>";
 
-	let newStr = highlightWords(worddata.palitext, keyword);
+	let highlightStr;
 
-	html += "<div class='wizard_par_div'>" + newStr + "</div>";
+	if(typeof worddata.highlight=="undefined"){
+		highlightStr= highlightWords(worddata.palitext, keyword);
+	}else{
+		highlightStr= worddata.highlight;
+	}
+	
+
+	html += "<div class='wizard_par_div'>" + highlightStr + "</div>";
 	html += "<div class='path'>" + worddata.path + "</div>";
 	html += "<div class='path'>" + worddata.book + "-" + worddata.para + "-" + worddata.wt + "</div>";
 	html += "</div>";

+ 25 - 4
app/search/paliword_sc.php

@@ -55,17 +55,38 @@ if (count($arrWordList) > 1) {
     PDO_Connect(_FILE_DB_PALITEXT_,_DB_USERNAME_,_DB_PASSWORD_);
 
 
-    $query = "SELECT ts_rank('{0.1, 0.2, 0.4, 1}', full_text_search_weighted, websearch_to_tsquery('pali', ?)) AS rank, book,paragraph,content as text FROM fts WHERE full_text_search_weighted @@ websearch_to_tsquery('pali', ?) ORDER BY rank DESC LIMIT 20";
-    $Fetch1 = PDO_FetchAll($query, array($word, $word));    
+    $query = "SELECT
+    ts_rank('{0.1, 0.2, 0.4, 1}',
+        full_text_search_weighted,
+        websearch_to_tsquery('pali', ?)) +
+    ts_rank('{0.1, 0.2, 0.4, 1}',
+        full_text_search_weighted_unaccent,
+        websearch_to_tsquery('pali_unaccent', ?))
+    AS rank,
+    ts_headline('pali', content,
+                 websearch_to_tsquery('pali', ?),
+                 'StartSel = <highlight>, StopSel = </highlight>')
+    AS highlight,
+    book,paragraph,content 
+    FROM fts_texts
+    WHERE
+        full_text_search_weighted
+        @@ websearch_to_tsquery('pali', ?) OR
+        full_text_search_weighted_unaccent
+        @@ websearch_to_tsquery('pali_unaccent', ?)
+    ORDER BY rank DESC
+    LIMIT 20;";
+    $Fetch1 = PDO_FetchAll($query, array($word, $word, $word, $word, $word));    
     foreach ($Fetch1 as $key => $value) {
         # code...
         $newRecode["title"] = $_dbPaliText->getTitle($value["book"], $value["paragraph"]);
         $newRecode["path"] = _get_para_path($value["book"], $value["paragraph"]);
         $newRecode["book"] = $value["book"];
         $newRecode["para"] = $value["paragraph"];
-        $newRecode["palitext"] = $value["text"];
+        $newRecode["palitext"] = $value["content"];
+        $newRecode["highlight"] = $value["highlight"];
         $newRecode["keyword"] = $arrWordList;
-        $newRecode["wt"] = 0;
+        $newRecode["wt"] = $value["rank"];;
         $out_data[] = $newRecode;
     }
 	$result["time"][] = array("event" => "fts精确匹配结束", "time" => microtime(true)-$_start);

+ 6 - 0
db/postgresql/migrations/2021-12-09-120136_fts_texts_add_id/down.sql

@@ -0,0 +1,6 @@
+-- This file should undo anything in `up.sql`
+
+ALTER TABLE fts_texts DROP COLUMN updated_at;
+ALTER TABLE fts_texts DROP COLUMN created_at;
+ALTER TABLE fts_texts DROP CONSTRAINT fts_texts_pkey;
+ALTER TABLE fts_texts DROP COLUMN id;

+ 5 - 0
db/postgresql/migrations/2021-12-09-120136_fts_texts_add_id/up.sql

@@ -0,0 +1,5 @@
+-- Your SQL goes here
+
+ALTER TABLE fts_texts ADD id SERIAL PRIMARY KEY;
+ALTER TABLE fts_texts ADD created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
+ALTER TABLE fts_texts ADD updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;