Server-side search for the AppSkin portal.
Provides the middleware that answers the AppSkin search requests, by looking up the search terms in a keyword index of the application routes.
Methods
(static) createAppSkinSearchMiddleware(options) → {function}
Creates middleware that searches application routes using a compressed keyword index.
The request body is JSON with the search text in "terms" (words separated by spaces). The response is a JSON array of { route, title } objects,
sorted by the number of search words that matched each route.
The keyword index is a gzipped JSON file with "keywords" (keyword to array of routes) and "routes" (route to title). It is cached in memory
and reloaded when the file changes.
Parameters:
| Name |
Type |
Description |
options |
Object
|
The middleware options.
Properties
| Name |
Type |
Attributes |
Default |
Description |
keywordFilePath |
String
|
|
|
The path of the gzipped keyword index file. |
contains |
Boolean
|
<optional>
|
false
|
Matches keywords containing a search word (true) instead of keywords starting with it (false). |
|
Returns:
The middleware function (req, res, next).
-
Type
-
function
Example
import { createAppSkinSearchMiddleware } from './AppSkinSearchMiddleware.js';
app.post('/search', createAppSkinSearchMiddleware({ keywordFilePath: './keywords.json.gz' }));