From 0f7ea697902d4a9d01c31075559a52d66708eb18 Mon Sep 17 00:00:00 2001 From: Brian Huisman Date: Wed, 17 May 2023 09:22:00 -0400 Subject: [PATCH] Store s_weights as JSON --- orcinus/admin.php | 90 +++++++++++++++++++++++----------------------- orcinus/config.php | 15 +------- orcinus/search.php | 21 +++++------ 3 files changed, 57 insertions(+), 69 deletions(-) diff --git a/orcinus/admin.php b/orcinus/admin.php index 4e70d29..682297f 100644 --- a/orcinus/admin.php +++ b/orcinus/admin.php @@ -736,40 +736,40 @@ if (!$_SESSION['admin_username']) { OS_setValue('s_limit_term_length', (int)$_POST['os_s_limit_term_length']); } - if (!isset($_POST['os_s_weight_title'])) $_POST['os_s_weight_title'] = $_RDATA['s_weights']['title']; + if (!isset($_POST['os_s_weight_title'])) $_POST['os_s_weight_title'] = $_ODATA['s_weights']['title']; $_POST['os_s_weight_title'] = number_format(max(0, (float)$_POST['os_s_weight_title']), 1, '.', ''); - if (!isset($_POST['os_s_weight_body'])) $_POST['os_s_weight_body'] = $_RDATA['s_weights']['body']; + if (!isset($_POST['os_s_weight_body'])) $_POST['os_s_weight_body'] = $_ODATA['s_weights']['body']; $_POST['os_s_weight_body'] = number_format(max(0, (float)$_POST['os_s_weight_body']), 1, '.', ''); - if (!isset($_POST['os_s_weight_keywords'])) $_POST['os_s_weight_keywords'] = $_RDATA['s_weights']['keywords']; + if (!isset($_POST['os_s_weight_keywords'])) $_POST['os_s_weight_keywords'] = $_ODATA['s_weights']['keywords']; $_POST['os_s_weight_keywords'] = number_format(max(0, (float)$_POST['os_s_weight_keywords']), 1, '.', ''); - if (!isset($_POST['os_s_weight_description'])) $_POST['os_s_weight_description'] = $_RDATA['s_weights']['description']; + if (!isset($_POST['os_s_weight_description'])) $_POST['os_s_weight_description'] = $_ODATA['s_weights']['description']; $_POST['os_s_weight_description'] = number_format(max(0, (float)$_POST['os_s_weight_description']), 1, '.', ''); - if (!isset($_POST['os_s_weight_url'])) $_POST['os_s_weight_url'] = $_RDATA['s_weights']['url']; + if (!isset($_POST['os_s_weight_url'])) $_POST['os_s_weight_url'] = $_ODATA['s_weights']['url']; $_POST['os_s_weight_url'] = number_format(max(0, (float)$_POST['os_s_weight_url']), 1, '.', ''); - if (!isset($_POST['os_s_weight_multi'])) $_POST['os_s_weight_multi'] = $_RDATA['s_weights']['multi']; + if (!isset($_POST['os_s_weight_multi'])) $_POST['os_s_weight_multi'] = $_ODATA['s_weights']['multi']; $_POST['os_s_weight_multi'] = number_format(max(0, (float)$_POST['os_s_weight_multi']), 1, '.', ''); - if (!isset($_POST['os_s_weight_important'])) $_POST['os_s_weight_important'] = $_RDATA['s_weights']['important']; + if (!isset($_POST['os_s_weight_important'])) $_POST['os_s_weight_important'] = $_ODATA['s_weights']['important']; $_POST['os_s_weight_important'] = number_format(max(0, (float)$_POST['os_s_weight_important']), 1, '.', ''); - if (!isset($_POST['os_s_weight_css_value'])) $_POST['os_s_weight_css_value'] = $_RDATA['s_weights']['css_value']; + if (!isset($_POST['os_s_weight_css_value'])) $_POST['os_s_weight_css_value'] = $_ODATA['s_weights']['css_value']; $_POST['os_s_weight_css_value'] = number_format(max(0, (float)$_POST['os_s_weight_css_value']), 1, '.', ''); - OS_setValue('s_weights', implode('%', array( - $_POST['os_s_weight_title'], - $_POST['os_s_weight_body'], - $_POST['os_s_weight_keywords'], - $_POST['os_s_weight_description'], - $_POST['os_s_weight_css_value'], - $_POST['os_s_weight_url'], - $_POST['os_s_weight_multi'], - $_POST['os_s_weight_important'] - ))); + OS_setValue('s_weights', array( + 'title' => $_POST['os_s_weight_title'], + 'body' => $_POST['os_s_weight_body'], + 'keywords' => $_POST['os_s_weight_keywords'], + 'description' => $_POST['os_s_weight_description'], + 'css_value' => $_POST['os_s_weight_css_value'], + 'url' => $_POST['os_s_weight_url'], + 'multi' => $_POST['os_s_weight_multi'], + 'important' => $_POST['os_s_weight_important'] + )); if (isset($_POST['os_s_weight_css'])) { $_POST['os_s_weight_css'] = preg_replace( @@ -981,19 +981,9 @@ let os_rdata = { $_RDATA['s_category_list'], JSON_INVALID_UTF8_IGNORE ); - ?>, - s_weights: + ?> }; -Object.keys(os_rdata.s_weights).forEach(key => { - os_rdata.s_weights[key] = parseFloat(os_rdata.s_weights[key]); -}); - let os_odata = { version: '', jw_compression: , @@ -1009,9 +999,19 @@ let os_odata = { preg_replace('/\s{2,}/', ' ', $_ODATA['s_result_template']), JSON_INVALID_UTF8_IGNORE ); - ?> + ?>, + s_weights: }; +Object.keys(os_odata.s_weights).forEach(key => { + os_odata.s_weights[key] = parseFloat(os_odata.s_weights[key]); +}); + let os_sdata = { terms: [], formatted: [], @@ -1247,19 +1247,19 @@ if (os_crawldata.length) { os_crawldata[y].phrase++; if (os_crawldata[y].title.match(os_sdata.terms[x][2])) - addRelevance += os_rdata.s_weights.title; + addRelevance += os_odata.s_weights.title; if (os_crawldata[y].description.match(os_sdata.terms[x][2])) - addRelevance += os_rdata.s_weights.description; + addRelevance += os_odata.s_weights.description; if (os_crawldata[y].keywords.match(os_sdata.terms[x][2])) - addRelevance += os_rdata.s_weights.keywords; + addRelevance += os_odata.s_weights.keywords; if (os_crawldata[y].weighted.match(os_sdata.terms[x][2])) - addRelevance += os_rdata.s_weights.css_value; + addRelevance += os_odata.s_weights.css_value; if (os_crawldata[y].content.match(os_sdata.terms[x][2])) - addRelevance += os_rdata.s_weights.body; + addRelevance += os_odata.s_weights.body; if (addRelevance) { os_crawldata[y].multi++; @@ -1273,8 +1273,8 @@ if (os_crawldata.length) { os_crawldata[y].relevance += addRelevance; // Calculate multipliers - os_crawldata[y].relevance *= Math.pow(os_rdata.s_weights.multi, os_crawldata[y].multi); - os_crawldata[y].relevance *= Math.pow(os_rdata.s_weights.important, os_crawldata[y].phrase); + os_crawldata[y].relevance *= Math.pow(os_odata.s_weights.multi, os_crawldata[y].multi); + os_crawldata[y].relevance *= Math.pow(os_odata.s_weights.important, os_crawldata[y].phrase); os_crawldata[y].relevance *= os_crawldata[y].priority; } @@ -2883,42 +2883,42 @@ document.write(mustache.render( @@ -2938,14 +2938,14 @@ document.write(mustache.render( diff --git a/orcinus/config.php b/orcinus/config.php index e0797b8..8b27eb0 100644 --- a/orcinus/config.php +++ b/orcinus/config.php @@ -192,7 +192,7 @@ if (!count($testConf->fetchAll())) { `s_results_pagination`=10, `s_limit_matchtext`=256, `s_limit_cache`=256, - `s_weights`=\'1.3%0.5%2.1%0.4%1.9%0.2%2.5%1.5\', + `s_weights`=\'{"title":"1.3","body":"0.5","keywords":"2.1","description":"0.4","css_value":"1.9","url":"0.2","multi":"2.5","important":"1.5"}\', `s_weight_css`=\'.important dt h1 h2 h3\', `s_show_orphans`=0, `s_show_filetype_html`=0, @@ -719,19 +719,6 @@ if (count($_ODATA['sp_domains']) == 1 && $_ODATA['jw_hostname'] != key($_ODATA[' OS_setValue('jw_hostname', key($_ODATA['sp_domains'])); -// Match Weighting Values -$weights = explode('%', $_ODATA['s_weights']); -$_RDATA['s_weights'] = array( - 'title' => $weights[0], - 'body' => $weights[1], - 'keywords' => $weights[2], - 'description' => $weights[3], - 'css_value' => $weights[4], - 'url' => $weights[5], - 'multi' => $weights[6], - 'important' => $weights[7] -); - $_RDATA['sp_punct'] = array( "\u{00AB}" => '"', "\u{00AD}" => '-', "\u{00B4}" => '\'', "\u{00B7}" => '•', "\u{00BB}" => '"', "\u{00F7}" => '/', "\u{01C0}" => '|', "\u{01C3}" => '!', diff --git a/orcinus/search.php b/orcinus/search.php index 66b4c00..ff8b98b 100644 --- a/orcinus/search.php +++ b/orcinus/search.php @@ -20,8 +20,9 @@ $_SDATA = array( ); -foreach ($_RDATA['s_weights'] as $key => $weight) - $_RDATA['s_weights'][$key] = (float)$weight; +foreach ($_ODATA['s_weights'] as $key => $weight) + $_ODATA['s_weights'][$key] = (float)$weight; + // Prepare regexp translation array for accented / ligature characters $_RDATA['s_latin_pcre'] = array(); @@ -376,19 +377,19 @@ if ($_RDATA['s_searchable_pages']) { $e = $m + min(substr_count($row['lc_keywords'], $term), 3); $f = $n + min(substr_count($row['lc_weighted'], $term), 3); - $searchQuery[$key]['relevance'] += $a * $_RDATA['s_weights']['body']; - $searchQuery[$key]['relevance'] += $b * $_RDATA['s_weights']['url']; - $searchQuery[$key]['relevance'] += $c * $_RDATA['s_weights']['title']; - $searchQuery[$key]['relevance'] += $d * $_RDATA['s_weights']['description']; - $searchQuery[$key]['relevance'] += $e * $_RDATA['s_weights']['keywords']; - $searchQuery[$key]['relevance'] += $f * $_RDATA['s_weights']['css_value']; + $searchQuery[$key]['relevance'] += $a * $_ODATA['s_weights']['body']; + $searchQuery[$key]['relevance'] += $b * $_ODATA['s_weights']['url']; + $searchQuery[$key]['relevance'] += $c * $_ODATA['s_weights']['title']; + $searchQuery[$key]['relevance'] += $d * $_ODATA['s_weights']['description']; + $searchQuery[$key]['relevance'] += $e * $_ODATA['s_weights']['keywords']; + $searchQuery[$key]['relevance'] += $f * $_ODATA['s_weights']['css_value']; } } // Calculate multipliers - $searchQuery[$key]['relevance'] *= $_RDATA['s_weights']['multi'] ** $searchQuery[$key]['multi']; - $searchQuery[$key]['relevance'] *= $_RDATA['s_weights']['important'] ** $searchQuery[$key]['phrase']; + $searchQuery[$key]['relevance'] *= $_ODATA['s_weights']['multi'] ** $searchQuery[$key]['multi']; + $searchQuery[$key]['relevance'] *= $_ODATA['s_weights']['important'] ** $searchQuery[$key]['phrase']; $searchQuery[$key]['relevance'] *= $row['priority']; }