Remove need for 'jw_depth' value

By using the location of the search.js script file, we can determine the root URL of an offline installation as long as the online script has been installed at https://example.com/orcinus/js/search.js
This commit is contained in:
Brian Huisman 2023-06-21 15:07:57 -04:00
parent b17a68c175
commit eda57224d9
4 changed files with 29 additions and 39 deletions

View file

@ -902,11 +902,6 @@ if (!$_SESSION['admin_username']) {
OS_setValue('jw_compression', (int)$_POST['os_jw_compression']);
}
if (isset($_POST['os_jw_depth'])) {
$_POST['os_jw_depth'] = max(0, min(255, (int)$_POST['os_jw_depth']));
OS_setValue('jw_depth', (int)$_POST['os_jw_depth']);
}
if ($_POST['os_submit'] == 'os_jw_config') {
$_SESSION['message'][] = 'Offline javascript search settings have been saved.';
break;
@ -1002,7 +997,6 @@ if (!$_SESSION['admin_username']) {
's_filetypes' => json_encode($_RDATA['s_filetypes'], JSON_INVALID_UTF8_IGNORE),
's_category_list' => json_encode($_RDATA['s_category_list'], JSON_INVALID_UTF8_IGNORE),
'jw_compression' => $_ODATA['jw_compression'],
'jw_depth' => str_repeat('../', $_ODATA['jw_depth']),
's_limit_query' => $_ODATA['s_limit_query'],
's_limit_terms' => $_ODATA['s_limit_terms'],
's_limit_term_length' => $_ODATA['s_limit_term_length'],
@ -2303,15 +2297,6 @@ if (!$_SESSION['admin_username']) {
</var>
</label>
</li>
<li class="list-group-item">
<label class="d-flex lh-lg w-100">
<strong class="pe-2">Search Page Directory Depth:</strong>
<var class="text-end flex-grow-1 text-nowrap">
<input type="number" name="os_jw_depth" value="<?php echo $_ODATA['jw_depth']; ?>" min="0" max="255" step="1" class="form-control d-inline-block"
data-bs-toggle="tooltip" data-bs-placement="top" title="How many directories deep from your Home Page is your Search Page?">
</var>
</label>
</li>
<li class="list-group-item">
<label class="d-flex w-100">
<strong class="pe-2">Search Database Size</strong>

View file

@ -122,7 +122,6 @@ if (!in_array($_DDATA['tbprefix'].'config', $_DDATA['tables'], true)) {
`s_limit_query_log` TINYINT UNSIGNED NOT NULL,
`jw_hostname` TINYTEXT NOT NULL,
`jw_compression` TINYINT UNSIGNED NOT NULL,
`jw_depth` TINYINT UNSIGNED NOT NULL,
PRIMARY KEY (`version`)
) ENGINE = MyISAM, CHARACTER SET = utf8mb4, COLLATE = utf8mb4_unicode_520_ci;'
);
@ -202,8 +201,7 @@ if (!count($testConf->fetchAll())) {
`s_result_template`=\'\',
`s_limit_query_log`=14,
`jw_hostname`=\'\',
`jw_compression`=25,
`jw_depth`=0
`jw_compression`=25
;'
);
$err = $insert->errorInfo();

View file

@ -1,42 +1,50 @@
/* ***** Orcinus Site Search - Default Search Result Javascript **** */
// When offline, this script relies on being in the [root]/orcinus/js/
// directory in order for offline URLs to resolve correctly. If you
// have placed your Orcinus Site Search installation in a different
// location, you will need to edit the pathOffline value below.
let scrElem = document.currentScript;
let pathOnline = scrElem.src.replace(/\/js\/[^\/]+$/, '/search.php');
let pathOffline = scrElem.src.replace(/\/orcinus\/js\/[^\/]+$/, '');
let remoteValue;
if (typeof os_return_all !== 'function') {
function os_return_all() { return []; }
remoteValue = { url: '?q=%QUERY&json', wildcard: '%QUERY' }
remoteValue = {
url: pathOnline + '?q=%QUERY&json',
wildcard: '%QUERY'
};
}
let os_bloodhound = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('title'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 5,
remote: remoteValue,
local: os_return_all
});
$('input.os_typeahead').attr('autocomplete', 'off').typeahead({
hint: true,
highlight: true,
minLength: 3
}, {
source: os_bloodhound,
source: new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('title'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 5,
remote: remoteValue,
local: os_return_all
}),
display: 'title'
}).bind('typeahead:selected', function (obj, datum) {
// We are offline
if (typeof os_odata != 'undefined' && typeof os_odata.jw_depth == 'string') {
window.location.href = datum.url.replace(/^\//, os_odata.jw_depth);
// Else we are online
} else {
// If we are online
if (window.location.protocol != 'file:') {
// On user click of a search suggestion, add this search query to
// the query log and cache
fetch(new Request(window.location.origin + window.location.pathname), {
fetch(new Request(pathOnline), {
method: 'POST',
headers: { 'Content-type': 'application/json' },
body: JSON.stringify({ q: datum.query, log: 'log' })
})
.then((response) => response.text())
.then((data) => { window.location.href = datum.url; });
}
// Else we are offline
} else window.location.href = pathOffline + datum.url;
});

View file

@ -21,8 +21,7 @@ let os_rdata = {
};
let os_odata = {
s_weights: {{{s_weights}}},
jw_depth: '{{jw_depth}}'
s_weights: {{{s_weights}}}
};
Object.keys(os_odata.s_weights).forEach(key => {
@ -447,7 +446,7 @@ if (os_crawldata.length) {
// Highlight the terms in the title, url and matchtext
result.title = resultsPage[x].title;
result.url = resultsPage[x].url.replace(/^\//, '{{jw_depth}}');
result.url = resultsPage[x].url;
result.matchtext = resultsPage[x].matchtext;
result.description = resultsPage[x].description;
result.title_highlight = resultsPage[x].title;