Store s_weights as JSON
This commit is contained in:
parent
d8e9d5dc91
commit
0f7ea69790
|
@ -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: <?php
|
||||
echo json_encode(
|
||||
$_RDATA['s_weights'],
|
||||
JSON_INVALID_UTF8_IGNORE
|
||||
);
|
||||
?>
|
||||
};
|
||||
|
||||
Object.keys(os_rdata.s_weights).forEach(key => {
|
||||
os_rdata.s_weights[key] = parseFloat(os_rdata.s_weights[key]);
|
||||
});
|
||||
|
||||
let os_odata = {
|
||||
version: '<?php echo $_ODATA['version']; ?>',
|
||||
jw_compression: <?php echo $_ODATA['jw_compression']; ?>,
|
||||
|
@ -1009,9 +999,19 @@ let os_odata = {
|
|||
preg_replace('/\s{2,}/', ' ', $_ODATA['s_result_template']),
|
||||
JSON_INVALID_UTF8_IGNORE
|
||||
);
|
||||
?>,
|
||||
s_weights: <?php
|
||||
echo json_encode(
|
||||
$_ODATA['s_weights'],
|
||||
JSON_INVALID_UTF8_IGNORE
|
||||
);
|
||||
?>
|
||||
};
|
||||
|
||||
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(
|
|||
<label class="d-flex lh-lg w-100 mb-2">
|
||||
<strong class="pe-2">Page Title:</strong>
|
||||
<span class="flex-grow-1 text-end text-nowrap">
|
||||
<input type="number" name="os_s_weight_title" value="<?php echo $_RDATA['s_weights']['title']; ?>" min="0" max="100" step="0.1" class="form-control d-inline-block"
|
||||
<input type="number" name="os_s_weight_title" value="<?php echo $_ODATA['s_weights']['title']; ?>" min="0" max="100" step="0.1" class="form-control d-inline-block"
|
||||
data-bs-toggle="tooltip" data-bs-placement="bottom" title="Search terms found in the page title.">
|
||||
</span>
|
||||
</label>
|
||||
<label class="d-flex lh-lg w-100 mb-2">
|
||||
<strong class="pe-2">Body Text:</strong>
|
||||
<span class="flex-grow-1 text-end text-nowrap">
|
||||
<input type="number" name="os_s_weight_body" value="<?php echo $_RDATA['s_weights']['body']; ?>" min="0" max="100" step="0.1" class="form-control d-inline-block"
|
||||
<input type="number" name="os_s_weight_body" value="<?php echo $_ODATA['s_weights']['body']; ?>" min="0" max="100" step="0.1" class="form-control d-inline-block"
|
||||
data-bs-toggle="tooltip" data-bs-placement="bottom" title="Search terms found in the page body text.">
|
||||
</span>
|
||||
</label>
|
||||
<label class="d-flex lh-lg w-100 mb-2">
|
||||
<strong class="pe-2">Keywords:</strong>
|
||||
<span class="flex-grow-1 text-end text-nowrap">
|
||||
<input type="number" name="os_s_weight_keywords" value="<?php echo $_RDATA['s_weights']['keywords']; ?>" min="0" max="100" step="0.1" class="form-control d-inline-block"
|
||||
<input type="number" name="os_s_weight_keywords" value="<?php echo $_ODATA['s_weights']['keywords']; ?>" min="0" max="100" step="0.1" class="form-control d-inline-block"
|
||||
data-bs-toggle="tooltip" data-bs-placement="bottom" title="Search terms found in the page keywords meta information.">
|
||||
</span>
|
||||
</label>
|
||||
<label class="d-flex lh-lg w-100 mb-2">
|
||||
<strong class="pe-2">Description:</strong>
|
||||
<span class="flex-grow-1 text-end text-nowrap">
|
||||
<input type="number" name="os_s_weight_description" value="<?php echo $_RDATA['s_weights']['description']; ?>" min="0" max="100" step="0.1" class="form-control d-inline-block"
|
||||
<input type="number" name="os_s_weight_description" value="<?php echo $_ODATA['s_weights']['description']; ?>" min="0" max="100" step="0.1" class="form-control d-inline-block"
|
||||
data-bs-toggle="tooltip" data-bs-placement="bottom" title="Search terms found in the page description meta information.">
|
||||
</span>
|
||||
</label>
|
||||
<label class="d-flex lh-lg w-100 mb-2">
|
||||
<strong class="pe-2">In URL:</strong>
|
||||
<span class="flex-grow-1 text-end text-nowrap">
|
||||
<input type="number" name="os_s_weight_url" value="<?php echo $_RDATA['s_weights']['url']; ?>" min="0" max="100" step="0.1" class="form-control d-inline-block"
|
||||
<input type="number" name="os_s_weight_url" value="<?php echo $_ODATA['s_weights']['url']; ?>" min="0" max="100" step="0.1" class="form-control d-inline-block"
|
||||
data-bs-toggle="tooltip" data-bs-placement="bottom" title="Search terms found in the page URL.">
|
||||
</span>
|
||||
</label>
|
||||
<label class="d-flex lh-lg w-100 mb-2">
|
||||
<strong class="pe-2">CSS Selector:</strong>
|
||||
<span class="flex-grow-1 text-end text-nowrap">
|
||||
<input type="number" name="os_s_weight_css_value" value="<?php echo $_RDATA['s_weights']['css_value']; ?>" min="0" max="100" step="0.1" class="form-control d-inline-block"
|
||||
<input type="number" name="os_s_weight_css_value" value="<?php echo $_ODATA['s_weights']['css_value']; ?>" min="0" max="100" step="0.1" class="form-control d-inline-block"
|
||||
data-bs-toggle="tooltip" data-bs-placement="bottom" title="An extra additive weight score will be added to content found in elements matching the CSS selectors below.">
|
||||
</span>
|
||||
</label>
|
||||
|
@ -2938,14 +2938,14 @@ document.write(mustache.render(
|
|||
<label class="d-flex lh-lg w-100 mb-2">
|
||||
<strong class="pe-2">Multi-term:</strong>
|
||||
<span class="flex-grow-1 text-end text-nowrap">
|
||||
<input type="number" name="os_s_weight_multi" value="<?php echo $_RDATA['s_weights']['multi']; ?>" min="0" max="10" step="0.1" class="form-control d-inline-block"
|
||||
<input type="number" name="os_s_weight_multi" value="<?php echo $_ODATA['s_weights']['multi']; ?>" min="0" max="10" step="0.1" class="form-control d-inline-block"
|
||||
data-bs-toggle="tooltip" data-bs-placement="bottom" title="If a result matches more than one of the given search terms; applied for every search term match beyond the first.">
|
||||
</span>
|
||||
</label>
|
||||
<label class="d-flex lh-lg w-100 mb-2">
|
||||
<strong class="pe-2">Important (+):</strong>
|
||||
<span class="flex-grow-1 text-end text-nowrap">
|
||||
<input type="number" name="os_s_weight_important" value="<?php echo $_RDATA['s_weights']['important']; ?>" min="0" max="10" step="0.1" class="form-control d-inline-block"
|
||||
<input type="number" name="os_s_weight_important" value="<?php echo $_ODATA['s_weights']['important']; ?>" min="0" max="10" step="0.1" class="form-control d-inline-block"
|
||||
data-bs-toggle="tooltip" data-bs-placement="bottom" title="Applied for search terms the user has marked as '+important'. Also applied to "phrase matches".">
|
||||
</span>
|
||||
</label>
|
||||
|
|
|
@ -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}" => '!',
|
||||
|
|
|
@ -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'];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue