Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Enhance search feature to support path #2145

Merged
merged 8 commits into from
Sep 6, 2022
Merged
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