mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-17 05:43:46 +03:00
Upload
This commit is contained in:
59
lua/includes/modules/search.lua
Normal file
59
lua/includes/modules/search.lua
Normal file
@@ -0,0 +1,59 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
|
||||
module( "search", package.seeall )
|
||||
|
||||
local Providers = {}
|
||||
|
||||
function AddProvider( func, id )
|
||||
|
||||
local prov = {
|
||||
func = func,
|
||||
}
|
||||
|
||||
if ( id ) then
|
||||
Providers[ id ] = prov
|
||||
else
|
||||
table.insert( Providers, prov )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function GetResults( str, types, maxResults )
|
||||
|
||||
if ( !maxResults || maxResults < 1 ) then maxResults = 1024 end
|
||||
|
||||
local str = str:lower()
|
||||
if ( str == "" ) then return {} end
|
||||
|
||||
local results = {}
|
||||
|
||||
for k, v in pairs( Providers ) do
|
||||
if ( isstring( types ) ) then
|
||||
if ( types != k ) then continue end
|
||||
elseif ( istable( types ) ) then
|
||||
if ( !table.HasValue( types, k ) ) then continue end
|
||||
end
|
||||
|
||||
local tbl = v.func( str )
|
||||
for _, e in pairs( tbl ) do
|
||||
table.insert( results, e )
|
||||
end
|
||||
|
||||
if ( #results >= maxResults ) then break end
|
||||
|
||||
end
|
||||
|
||||
-- Todo. Sort, weighted?
|
||||
|
||||
return results
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user