Verified Commit 53ccb7c4 authored by Camil Staps's avatar Camil Staps 🚀

Filter on library

parent 51a3da44
......@@ -185,6 +185,7 @@ JSON request with at least one of the following fields:
* `name`, the name of the function to search for.
* `className`, the name of the class to search for.
* `typeName`, the name of the type to search for.
* `libraries`, a list of names of libraries to search in.
* `modules`, a list of names of modules to search in.
* `page`: 0 for the first *n* results, 1 for the next *n*, etc.
......
......@@ -33,6 +33,7 @@ import Levenshtein
, className :: Maybe String
, typeName :: Maybe String
, modules :: Maybe [String]
, libraries :: Maybe [String]
, page :: Maybe Int
}
......@@ -99,6 +100,7 @@ where
, className = Nothing
, typeName = Nothing
, modules = Nothing
, libraries = Nothing
, page = Nothing
}
......@@ -152,7 +154,7 @@ where
handle :: !TypeDB !(Maybe Request) !*World -> *(!Response, !*World)
handle _ Nothing w = (err E_INVALIDINPUT "Couldn't parse input", w)
handle db (Just request=:{unify,name,modules,page}) w
handle db (Just request=:{unify,name,page}) w
| isJust name && size (fromJust name) > 40
= (err E_INVALIDNAME "function name too long", w)
| isJust name && any isSpace (fromString $ fromJust name)
......@@ -190,7 +192,10 @@ where
suggs _ _ _ = Nothing
search :: !Request !TypeDB -> [Result]
search {unify,name,className,typeName,modules,page} db
search {unify,name,className,typeName,modules,libraries,page} db
# db = case libraries of
(Just ls) = filterLocations (isLibMatch ls) db
Nothing = db
# db = case modules of
(Just ms) = filterLocations (isModMatch ms) db
Nothing = db
......@@ -375,6 +380,10 @@ where
isModMatch mods (Location _ mod _ _) = isMember mod mods
isModMatch _ (Builtin _) = False
isLibMatch :: ![String] Location -> Bool
isLibMatch libs (Location lib _ _ _) = isMember lib libs
isLibMatch _ (Builtin _) = False
log :: (LogMessage (Maybe Request) Response) IPAddress *World
-> *(IPAddress, *World)
log msg s w
......
......@@ -34,6 +34,9 @@ if($_SERVER['REQUEST_METHOD'] !== 'GET'){
$command['unify'] = $unify;
}
if (isset($_GET['lib'])) {
$command['libraries'] = explode(',', $_GET['lib']);
}
if (isset($_GET['mod'])) {
$command['modules'] = explode(',', $_GET['mod']);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment