# solr-synonyms

> Parse Solr/ElasticSearch synonyms files into JavaScript objects.

Latest version **0.0.2** (published 2013-10-09) · 0 weekly downloads

## Install

```sh
npm install solr-synonyms
pnpm add solr-synonyms
yarn add solr-synonyms
bun add solr-synonyms
```

Provides the command `synonyms`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2013-10-09 |
| First published | 2013-09-17 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | 0.10.x |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Alexander Prinzhorn |
| Maintainers | prinzhorn |
| Keywords | synonyms, fulltext, solr, elasticsearch |

## Links

- npm: https://www.npmjs.com/package/solr-synonyms
- Repository: https://github.com/Prinzhorn/node-solr-synonyms
- Issues: https://github.com/Prinzhorn/node-solr-synonyms/issues
- npm.io page: https://npm.io/package/solr-synonyms

## Dependencies (2)

- [commander](https://npm.io/package/commander.md) 2.0.x
- [diacritics](https://npm.io/package/diacritics.md) 1.0.x

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.0.2 (latest) — 2013-10-09
- 0.0.1 — 2013-09-17

## README

node-solr-synonyms
==================

Parse Solr/ElasticSearch synonyms files into JavaScript objects. You can then replace tokens with their synonyms easily.

Info on synonyms file format http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters#solr.SynonymFilterFactory


Installation
------------

> npm install solr-synonyms


Usage
-----

```js
var synonyms = require('solr-synonyms');
```

Now you have access to the api.


API
---

### synonyms.parse(inputString[, ignoreCase = true, expand = false])

* `inputString`: The string in solr format (see http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters#solr.SynonymFilterFactory)
* `ignoreCase`: Ignore the case. Duh.
* `expand`: See http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters#solr.SynonymFilterFactory

Returns an object which maps the keys to arrays of strings.


### synonyms.replace(tokens, synonyms)

* `tokens`: An array of strings.
* `synonyms`: An object which maps words to synonyms, e.g. the output of `synonyms.parse`.

Returns a new array where `tokens` have been replaced by their `synonyms`.


Example output
--------------

### Given this input

```
# blank lines and lines starting with pound are comments.

#Explicit mappings match any token sequence on the LHS of "=>"
#and replace with all alternatives on the RHS.  These types of mappings
#ignore the expand parameter in the schema.
#Examples:
i-pod, i pod => ipod,
sea biscuit, sea biscit => seabiscuit

#Equivalent synonyms may be separated with commas and give
#no explicit mapping.  In this case the mapping behavior will
#be taken from the expand parameter in the schema.  This allows
#the same synonym file to be used in different synonym handling strategies.
#Examples:
ipod, i-pod, i pod
foozball , foosball
universe , cosmos

# If expand==true, "ipod, i-pod, i pod" is equivalent to the explicit mapping:
ipod, i-pod, i pod => ipod, i-pod, i pod
# If expand==false, "ipod, i-pod, i pod" is equivalent to the explicit mapping:
ipod, i-pod, i pod => ipod

#multiple synonym mapping entries are merged.
foo => foo bar
foo => baz
#is equivalent to
foo => foo bar, baz
```


### with `expand = false`

```js
{
	'i-pod': ['ipod', 'i-pod', 'i pod'],
	'i pod': ['ipod', 'i-pod', 'i pod'],
	'ipod': ['ipod', 'i-pod', 'i pod'],
	'sea biscuit': ['seabiscuit'],
	'sea biscit': ['seabiscuit'],
	'foosball': ['foozball'],
	'foozball': ['foozball'],
	'universe': ['universe'],
	'cosmos': ['universe'],
	'foo': ['foo bar', 'baz']
}
```


### with `expand = true`

```js
{
	'i-pod': ['ipod', 'i-pod', 'i pod'],
	'i pod': ['ipod', 'i-pod', 'i pod'],
	'ipod': ['ipod', 'i-pod', 'i pod'],
	'sea biscuit': ['seabiscuit'],
	'sea biscit': ['seabiscuit'],
	'foozball': ['foozball', 'foosball'],
	'foosball': ['foozball', 'foosball'],
	'universe': ['universe', 'cosmos'],
	'cosmos': ['universe', 'cosmos'],
	'foo': ['foo bar', 'baz']
}
```

---
_Source: https://npm.io/package/solr-synonyms · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
