mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-15 18:57:08 +00:00
Apply "and" to server list & content search terms (#15365)
This commit is contained in:
parent
e952a0807b
commit
0e06590ffd
2 changed files with 28 additions and 36 deletions
|
@ -563,30 +563,32 @@ function contentdb.filter_packages(query, by_type)
|
|||
end
|
||||
|
||||
local keywords = {}
|
||||
for word in query:lower():gmatch("%S+") do
|
||||
table.insert(keywords, word)
|
||||
for word in query:gmatch("%S+") do
|
||||
table.insert(keywords, word:lower())
|
||||
end
|
||||
|
||||
local function contains_all_keywords(str)
|
||||
str = str:lower()
|
||||
for _, keyword in ipairs(keywords) do
|
||||
if not str:find(keyword, 1, true) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function matches_keywords(package)
|
||||
for k = 1, #keywords do
|
||||
local keyword = keywords[k]
|
||||
|
||||
if string.find(package.name:lower(), keyword, 1, true) or
|
||||
string.find(package.title:lower(), keyword, 1, true) or
|
||||
string.find(package.author:lower(), keyword, 1, true) or
|
||||
string.find(package.short_description:lower(), keyword, 1, true) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
return contains_all_keywords(package.name) or
|
||||
contains_all_keywords(package.title) or
|
||||
contains_all_keywords(package.author) or
|
||||
contains_all_keywords(package.short_description)
|
||||
end
|
||||
|
||||
contentdb.packages = {}
|
||||
for _, package in pairs(contentdb.packages_full) do
|
||||
if (query == "" or matches_keywords(package)) and
|
||||
(by_type == nil or package.type == by_type) then
|
||||
contentdb.packages[#contentdb.packages + 1] = package
|
||||
table.insert(contentdb.packages, package)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue