]> git.openstreetmap.org Git - nominatim.git/commitdiff
add function to recalculate counts for full-word search term
authorSarah Hoffmann <lonvia@denofr.de>
Sat, 28 Oct 2017 16:34:22 +0000 (18:34 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Sun, 17 Dec 2017 15:00:28 +0000 (16:00 +0100)
sql/words_from_search_name.sql [new file with mode: 0644]
utils/update.php

diff --git a/sql/words_from_search_name.sql b/sql/words_from_search_name.sql
new file mode 100644 (file)
index 0000000..b7727dc
--- /dev/null
@@ -0,0 +1,11 @@
+DROP TABLE IF EXISTS word_frequencies;
+CREATE TABLE word_frequencies AS
+ SELECT unnest(name_vector) as id, count(*) FROM search_name GROUP BY id;
+
+CREATE INDEX idx_word_frequencies ON word_frequencies(id);
+
+UPDATE word SET search_name_count = count
+  FROM word_frequencies
+ WHERE word_token like ' %' and word_id = id;
+
+DROP TABLE word_frequencies;
index 5a5d41fff8435f2c2c9cd50d16a004704458d3ba..c5b5e4de21374f335d1bcd701a1ddeb31dcdb587 100755 (executable)
@@ -33,6 +33,7 @@ $aCMDOptions
    array('index-instances', '', 0, 1, 1, 1, 'int', 'Number of indexing instances (threads)'),
 
    array('deduplicate', '', 0, 1, 0, 0, 'bool', 'Deduplicate tokens'),
+   array('recompute-word-counts', '', 0, 1, 0, 0, 'bool', 'Compute frequency of full-word search terms'),
    array('no-npi', '', 0, 1, 0, 0, 'bool', '(obsolete)'),
   );
 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true);
@@ -237,6 +238,12 @@ if ($aResult['deduplicate']) {
     }
 }
 
+if ($aResult['recompute-word-counts']) {
+    info('Recompute frequency of full-word search terms');
+    $sTemplate = file_get_contents(CONST_BasePath.'/sql/words_from_search_name.sql');
+    runSQLScript($sTemplate, true, true);
+}
+
 if ($aResult['index']) {
     passthru(CONST_InstallPath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port'].' -t '.$aResult['index-instances'].' -r '.$aResult['index-rank']);
 }