1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Apply "and" to server list & content search terms (#15365)

This commit is contained in:
Lars Müller 2024-11-03 15:09:47 +01:00 committed by GitHub
parent e952a0807b
commit 0e06590ffd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 36 deletions

View file

@ -195,8 +195,7 @@ local function search_server_list(input)
-- setup the keyword list
local keywords = {}
for word in input:gmatch("%S+") do
word = word:gsub("(%W)", "%%%1")
table.insert(keywords, word)
table.insert(keywords, word:lower())
end
if #keywords == 0 then
@ -207,26 +206,17 @@ local function search_server_list(input)
-- Search the serverlist
local search_result = {}
for i = 1, #serverlistmgr.servers do
local server = serverlistmgr.servers[i]
local found = 0
for k = 1, #keywords do
local keyword = keywords[k]
if server.name then
local sername = server.name:lower()
local _, count = sername:gsub(keyword, keyword)
found = found + count * 4
end
if server.description then
local desc = server.description:lower()
local _, count = desc:gsub(keyword, keyword)
found = found + count * 2
end
for i, server in ipairs(serverlistmgr.servers) do
local name_matches, description_matches = true, true
for _, keyword in ipairs(keywords) do
name_matches = name_matches and not not
(server.name or ""):lower():find(keyword, 1, true)
description_matches = description_matches and not not
(server.description or ""):lower():find(keyword, 1, true)
end
if found > 0 then
local points = (#serverlistmgr.servers - i) / 5 + found
server.points = points
if name_matches or description_matches then
server.points = #serverlistmgr.servers - i
+ (name_matches and 50 or 0)
table.insert(search_result, server)
end
end