Skip to content

Commit

Permalink
feet: search feature to support path (#2145)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpateldx authored Sep 6, 2022
1 parent ddde105 commit c52ee83
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
16 changes: 16 additions & 0 deletions e2e/integration/search.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,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');
});
});
2 changes: 1 addition & 1 deletion src/services/SearchStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class SearchStore<T> {
const recurse = items => {
items.forEach(group => {
if (group.type !== 'group') {
this.add(group.name, group.description || '', group.id);
this.add(group.name, (group.description || '').concat(' ', group.path || ''), group.id);
}
recurse(group.items);
});
Expand Down
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 c52ee83

Please sign in to comment.