Skip to content

Optional to remove the lunr stopWordFilter #100

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 3 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ Responsible for defining global configuration. Look for full example here - [con

- **`isExactSearch`** set to `true` if you want to always show exact search matches. See [lunr stemmer](https://github.com/olivernn/lunr.js/issues/328) and [lunr stopWordFilter](https://github.com/olivernn/lunr.js/issues/233).

- **`removeStopWordFilter`** set to `true` if you want to remove the stopWordFilter. See https://github.com/itemsapi/itemsjs/issues/46.

- **`is_all_filtered_items`** set to `true` if you want to return the whole filtered dataset.

### itemsjs.aggregation(options)
Expand Down
8 changes: 8 additions & 0 deletions src/fulltext.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ const Fulltext = function(items, config) {
this.pipeline.remove(lunr.stemmer);
this.pipeline.remove(lunr.stopWordFilter);
}

/**
* Remove the stopWordFilter from the pipeline
* stopWordFilter: https://github.com/itemsapi/itemsjs/issues/46
*/
if (config.removeStopWordFilter) {
this.pipeline.remove(lunr.stopWordFilter);
}
});

let i = 1;
Expand Down
26 changes: 25 additions & 1 deletion tests/fulltextSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ describe('fulltext', function() {

const specialItems = [
{'name': 'elation'},
{'name': 'source'}
{'name': 'source'},
{'name': 'headless'}
];

it('checks search', function test(done) {
Expand Down Expand Up @@ -102,6 +103,29 @@ describe('fulltext', function() {
done();
});

it('makes search stepping through characters', function test(done) {
const stopwordfilter = new Fulltext(specialItems, {
searchableFields: ['name'],
});

const withoutstopwordfilter = new Fulltext(specialItems, {
searchableFields: ['name'],
removeStopWordFilter: true
});

assert.equal(stopwordfilter.search('h').length, 1);
assert.equal(stopwordfilter.search('he').length, 0); // The stopwordfilter filters out "he"
assert.equal(stopwordfilter.search('hea').length, 1);
assert.equal(stopwordfilter.search('head').length, 1);

assert.equal(withoutstopwordfilter.search('h').length, 1);
assert.equal(withoutstopwordfilter.search('he').length, 1);
assert.equal(withoutstopwordfilter.search('hea').length, 1);
assert.equal(withoutstopwordfilter.search('head').length, 1);

done();
});


xit('returns internal ids', function test(done) {

Expand Down