From 5cd6462b2a591301cb8813fa94def385685b33c6 Mon Sep 17 00:00:00 2001 From: john Date: Mon, 16 Nov 2020 18:29:41 +0100 Subject: [PATCH] refine node.js example and describe 'suggest' option --- README.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 65262c4..05111cb 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,13 @@ Run: `npm install` ## Example use -Create a `test.js` file and include this code for example: +### Node.js + +Create a directory `test-dir` and inside run `npm install vsm-pubdictionaries`. +Then, create a `test.js` file and include this code for example: ```javascript -const PubDict = require('./DictionaryBioPortal'); +const PubDict = require('vsm-pubdictionaries'); const dict = new PubDict({log: true, suggest: 'substring'}); dict.getEntryMatchesForString('dog', @@ -46,6 +49,13 @@ dict.getEntryMatchesForString('dog', ``` Then, run `node test.js` +### Browsers + +```html + +``` +after which it is accessible as the global variable `VsmPubDictionaries`. + ## Tests Run `npm test`, which runs the source code tests with Mocha. @@ -202,6 +212,15 @@ The returned results from each respective group of dictionaries are merged and t Then the sorted results from the 2 groups are merged and trimmed based on the `options.perPage` value. The PubDictionaries API currently supports 3 endpoints that can be used for searching terms in the corresponding dictionaries. +By default, the `substring_completion` endpoint is used. +The (developer) user can specify which one of the 3 endpoints he wants to use with the global option `suggest`. +For example, to use the `prefix_completion` endpoint we initialize the `vsm-pubdictionaries` instance as: +```javascript +const PubDict = require('vsm-pubdictionaries'); +const dict = new PubDict({ suggest: 'prefix' }); // 'substring' or 'mixed' also allowed +... +``` + We use the URL example above to demonstrate and explain the differences: - `prefix_completion`: returns only entries whose label **starts with** `TP53`