Skip to content

Commit

Permalink
Merge pull request #2 from bpateldx/bug-fix/tokens-not-trimmed-for-se…
Browse files Browse the repository at this point in the history
…arch

Trim terms same way while indexing and querying
  • Loading branch information
bpateldx authored Sep 1, 2022
2 parents 2be56f3 + d741de8 commit 38a702a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
22 changes: 16 additions & 6 deletions e2e/integration/search.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ describe('Search', () => {
.first()
.should('contain', 'Introduction');

getSearchInput().clear().type('uploadImage', { force: true });
cy.get('[role=search] [role=menuitem]')
.should('have.length', 1)
.first()
.should('contain', 'uploads an image');

getSearchInput().type('{esc}', { force: true });
getSearchResults().should('not.exist');
});
Expand Down Expand Up @@ -65,4 +59,20 @@ describe('Search', () => {
getSearchInput().type('xzss', { force: true });
getSearchResults().should('exist').should('contain', 'No results found');
});

it('should allow search by path or keywords in path', () => {
getSearchInput().clear().type('uploadImage', { force: true });
cy.get('[role=search] [role=menuitem]')
.should('have.length', 1)
.first()
.should('contain', 'uploads an image');

getSearchInput()
.clear()
.type('/pet/{petId}/uploadImage', { force: true, parseSpecialCharSequences: false });
cy.get('[role=search] [role=menuitem]')
.should('have.length', 1)
.first()
.should('contain', 'uploads an image');
});
});
5 changes: 4 additions & 1 deletion src/services/SearchWorker.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ function initEmpty() {

initEmpty();

const expandTerm = term => '*' + lunr.stemmer(new lunr.Token(term, {})) + '*';
const expandTerm = term => {
const token = lunr.trimmer(new lunr.Token(term, {}));
return '*' + lunr.stemmer(token) + '*';
};

export function add<T>(title: string, description: string, meta?: T) {
const ref = store.push(meta) - 1;
Expand Down

0 comments on commit 38a702a

Please sign in to comment.