Skip to content

Commit

Permalink
Added another default class
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Kosmaczewski committed Jul 17, 2023
1 parent eff220f commit 00db2bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions spec/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ describe ('Search engine', () => {
expect(results1).to.deep.equal(results2)
})

it('the "default" version works just like "master"', () => {
const results1 = search(lunrIndex, files, 'backup', undefined, 'master')
const results2 = search(lunrIndex, files, 'backup', undefined, 'default')
expect(results1.length).to.equal(50)
expect(results2.length).to.equal(50)
expect(results1).to.deep.equal(results2)
})

it('can be filtered by version', () => {
const results = search(lunrIndex, files, 'backup', undefined, '0.1')
expect(results.length).to.equal(7)
Expand Down
4 changes: 2 additions & 2 deletions src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type FileRepository = { [ref: string]: SearchResult }

/**
* Performs the actual search against the Lunr index.
* This function takes a "version" parameter; if this parameter is "master" or "main", then all search
* This function takes a "version" parameter; if this parameter is "master", "main", or "default", then all search
* results are included in the response. If a different value is provided, only those values are returned.
* @param lunrIndex The Lunr.js index
* @param files The repository of files
Expand All @@ -25,7 +25,7 @@ export function search(lunrIndex: lunr.Index, files: FileRepository, query: stri
.filter((result: SearchResult) => {
// This "or" statement short-circuits the evaluation: if "master" or "main" are mentioned,
// the result is included; otherwise, if the version coincides, it is included.
if (version === 'master' || version === 'main' || result.version === version) {
if (version === 'master' || version === 'main' || version === 'default' || result.version === version) {
return result
}
})
Expand Down

0 comments on commit 00db2bf

Please sign in to comment.