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 orderBy, ascending; // use `setOrderBy()` to modify orderBy
|
||||||
let lastOrderedValue, lastID;
|
let lastOrderedValue, lastID;
|
||||||
|
|
||||||
|
|
||||||
window.onload = function () {
|
window.onload = function () {
|
||||||
if (query !== null && query !== "") {
|
if (query !== null && query !== "") {
|
||||||
orderBy = "RELEVANCE";
|
orderBy = "RELEVANCE";
|
||||||
|
} else {
|
||||||
|
document.getElementById("query").value = query;
|
||||||
}
|
}
|
||||||
|
|
||||||
const title = document.getElementsByTagName("title")[0];
|
const title = document.getElementsByTagName("title")[0];
|
||||||
@ -19,6 +20,7 @@ window.onload = function () {
|
|||||||
input.setAttribute("value", query);
|
input.setAttribute("value", query);
|
||||||
|
|
||||||
setOrderBy("RELEVANCE");
|
setOrderBy("RELEVANCE");
|
||||||
|
ascending = false;
|
||||||
} else {
|
} else {
|
||||||
title.textContent = "Most recent torrents - magneticow";
|
title.textContent = "Most recent torrents - magneticow";
|
||||||
|
|
||||||
@ -39,6 +41,10 @@ window.onload = function () {
|
|||||||
const ul = document.querySelector("main ul");
|
const ul = document.querySelector("main ul");
|
||||||
|
|
||||||
query = queryInput.value
|
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) {
|
switch (sortDropdown.selectedIndex) {
|
||||||
case 0:
|
case 0:
|
||||||
setOrderBy("RELEVANCE")
|
setOrderBy("RELEVANCE")
|
||||||
@ -57,7 +63,7 @@ window.onload = function () {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ascending = sortDropdown.selectedIndex % 2 === 0
|
ascending = sortDropdown.selectedIndex % 2 === 1
|
||||||
|
|
||||||
ul.innerHTML = ""
|
ul.innerHTML = ""
|
||||||
lastID = lastOrderedValue = null
|
lastID = lastOrderedValue = null
|
||||||
|
@ -217,7 +217,7 @@ func (db *postgresDatabase) QueryTorrents(
|
|||||||
, discovered_on
|
, discovered_on
|
||||||
, (SELECT COUNT(*) FROM files WHERE torrents.id = files.torrent_id) AS n_files
|
, (SELECT COUNT(*) FROM files WHERE torrents.id = files.torrent_id) AS n_files
|
||||||
{{ if .QueryExists }}
|
{{ if .QueryExists }}
|
||||||
, similarity(name, '{{ .Query }}') * -1 as relevance
|
, similarity(name, '{{ .Query }}') as relevance
|
||||||
{{ else }}
|
{{ else }}
|
||||||
, 0
|
, 0
|
||||||
{{ end }}
|
{{ end }}
|
||||||
@ -298,7 +298,7 @@ func (db *postgresDatabase) QueryTorrents(
|
|||||||
func orderOnPostgreSQL(orderBy OrderingCriteria) string {
|
func orderOnPostgreSQL(orderBy OrderingCriteria) string {
|
||||||
switch orderBy {
|
switch orderBy {
|
||||||
case ByRelevance:
|
case ByRelevance:
|
||||||
return "similarity(name, 'twistys') * -1"
|
return "similarity(name, 'twistys')"
|
||||||
|
|
||||||
case ByTotalSize:
|
case ByTotalSize:
|
||||||
return "total_size"
|
return "total_size"
|
||||||
|
Loading…
Reference in New Issue
Block a user