Minor fixes related to searching
This commit is contained in:
parent
7ff7dc4b06
commit
828e230d3b
@ -6,10 +6,11 @@ let query = (new URL(location)).searchParams.get("query")
|
||||
let orderBy, ascending; // use `setOrderBy()` to modify orderBy
|
||||
let lastOrderedValue, lastID;
|
||||
|
||||
|
||||
window.onload = function () {
|
||||
if (query !== null && query !== "") {
|
||||
orderBy = "RELEVANCE";
|
||||
} else {
|
||||
document.getElementById("query").value = query;
|
||||
}
|
||||
|
||||
const title = document.getElementsByTagName("title")[0];
|
||||
@ -19,6 +20,7 @@ window.onload = function () {
|
||||
input.setAttribute("value", query);
|
||||
|
||||
setOrderBy("RELEVANCE");
|
||||
ascending = false;
|
||||
} else {
|
||||
title.textContent = "Most recent torrents - magneticow";
|
||||
|
||||
@ -39,6 +41,10 @@ window.onload = function () {
|
||||
const ul = document.querySelector("main ul");
|
||||
|
||||
query = queryInput.value
|
||||
|
||||
const newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?query=' + query;
|
||||
window.history.pushState({path: newurl}, '', newurl);
|
||||
|
||||
switch (sortDropdown.selectedIndex) {
|
||||
case 0:
|
||||
setOrderBy("RELEVANCE")
|
||||
@ -57,7 +63,7 @@ window.onload = function () {
|
||||
break;
|
||||
}
|
||||
|
||||
ascending = sortDropdown.selectedIndex % 2 === 0
|
||||
ascending = sortDropdown.selectedIndex % 2 === 1
|
||||
|
||||
ul.innerHTML = ""
|
||||
lastID = lastOrderedValue = null
|
||||
|
@ -217,7 +217,7 @@ func (db *postgresDatabase) QueryTorrents(
|
||||
, discovered_on
|
||||
, (SELECT COUNT(*) FROM files WHERE torrents.id = files.torrent_id) AS n_files
|
||||
{{ if .QueryExists }}
|
||||
, similarity(name, '{{ .Query }}') * -1 as relevance
|
||||
, similarity(name, '{{ .Query }}') as relevance
|
||||
{{ else }}
|
||||
, 0
|
||||
{{ end }}
|
||||
@ -298,7 +298,7 @@ func (db *postgresDatabase) QueryTorrents(
|
||||
func orderOnPostgreSQL(orderBy OrderingCriteria) string {
|
||||
switch orderBy {
|
||||
case ByRelevance:
|
||||
return "similarity(name, 'twistys') * -1"
|
||||
return "similarity(name, 'twistys')"
|
||||
|
||||
case ByTotalSize:
|
||||
return "total_size"
|
||||
|
Loading…
Reference in New Issue
Block a user