Skip to content

Commit

Permalink
refine node.js example and describe 'suggest' option
Browse files Browse the repository at this point in the history
  • Loading branch information
bblodfon committed Nov 16, 2020
1 parent 47da0fc commit 5cd6462
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -46,6 +49,13 @@ dict.getEntryMatchesForString('dog',
```
Then, run `node test.js`

### Browsers

```html
<script src="https://unpkg.com/vsm-pubdictionaries@^1.0.0/dist/vsm-pubdictionaries.min.js"></script>
```
after which it is accessible as the global variable `VsmPubDictionaries`.

## Tests

Run `npm test`, which runs the source code tests with Mocha.
Expand Down Expand Up @@ -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`
Expand Down

0 comments on commit 5cd6462

Please sign in to comment.