Merge pull request #2 from bpateldx/bug-fix/tokens-not-trimmed-for-search

Trim terms same way while indexing and querying
This commit is contained in:
bpateldx 2022-09-01 14:14:15 -04:00 committed by GitHub
commit 38a702a0ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 7 deletions

View File

@ -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');
});
@ -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');
});
});

View File

@ -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;