Module that offers a variety of queries around npms
data.
$ npm install @npms/queries
For now, only queries related to search
are available. Though, the goal of this module is to provide other interesting queries in the near future, such as top ranked modules, top authors, etc.
Performs a search query.
Besides normal text, q
supports qualifiers to express filters and other modifiers.
The esClient
accepts a elasticsearch
instance or a config to instantiate it.
You may read the API docs to know which qualifiers are available.
const queries = require('@npms/queries');
// ...
queries.search('test framework', esClient)
.then((res) => {
console.log('total', res.total);
console.log('results', res.results);
});
Available options:
from
: The offset in which to start searching from, defaults to0
size
: The total number of results to return, defaults to25
throwOnInvalid
: Whether to reject the promise if the query has invalid qualifiers or not, defaults tofalse
(iffalse
, invalid qualifiers will be removed fromq
)
Fetch search suggestions to be typically displayed when doing autocomplete.
Only normal text is supported in q
but any qualifiers will be automatically discarded.
The esClient
accepts a elasticsearch
instance or a config to instantiate it.
const queries = require('@npms/queries');
// ...
queries.search.suggestions('gulp', esClient)
.then((suggestions) => console.log('suggestions', suggestions));
Available options:
boostExact
: How much should the score of exact matches be boosted? defaults to100000
.size
: The total number of results to return, defaults to25
analyzerWeight
: How much should we weight the analyzer'sscore.final
by? defaults to1.0
.scoreWeight
: How much should we weight the search_score
? defaults to0.3
.
Perform a fuzzy search for similarly named packages.
Results are ranked based on a combination of analyzer weightings (quality
, popularity
, maintenance
) and the _score
returned by the fuzzy match.
const queries = require('@npms/queries');
// ...
queries.search.similar('chaik', esClient)
.then(results => {
// perhaps we were instead looking for chalk?
});
Available options:
size
: The total number of results to return, defaults to10
.analyzerWeight
: How much should we weight the analyzer'sscore.final
by? defaults to2.2
.scoreWeight
: How much should we weight the search_score
? defaults to1.5
.minScore
: defaults to4.5
.
the above default values were based on trial and error examining the top npm modules, they will likely change over time.
$ npm test
$ npm test-cov
to get coverage report
Released under the MIT License.