Skip to content

Commit

Permalink
NEW: Advanced Search: Source Gloss (#182)
Browse files Browse the repository at this point in the history
closes #182
  • Loading branch information
dwhieb committed Jul 31, 2024
1 parent 78b2c1d commit 9770308
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions data/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function createMatchers(query, normalize) {

const {
caseSensitive,
gloss,
regex,
sourceForm,
sourceUR,
Expand Down Expand Up @@ -49,6 +50,17 @@ function createMatchers(query, normalize) {
return createStringTester(`form`)
},

gloss() {

const q = normalize(cleanSearch(gloss))
const test = createSearchRegExp(q, { caseSensitive, regex })

return function testSourceForm(component) {
return component.tokens?.some(token => test(normalize(token.gloss)))
}

},

/**
* NB: This function only runs when the "Language" setting is not `all`.
*/
Expand Down
15 changes: 15 additions & 0 deletions pages/Search/Search.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,21 @@
value='{{ query.sourceUR }}'
>

<label for=gloss-box>Gloss</label>
<input
autocomplete=on
autocorrect=off
class=text-box
enterkeyhint=search
id=gloss-box
inputmode=search
name=gloss
placeholder='e.g. “-e3ee”'
spellcheck=true
type=search
value='{{ query.gloss }}'
>

</div>

</fieldset><!-- Source Fields -->
Expand Down
8 changes: 8 additions & 0 deletions pages/Search/Search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ describe(`Search`, function() {
cy.get(`.num-results`).should(`include.text`, `of 2.`)
})

it(`Sources: Glosses`, function() {
cy.visit(`/search`)
cy.contains(`label`, `Advanced Search`).click()
cy.get(`#gloss-box`).type(`by heat`)
cy.get(`#advanced-search-button`).click()
cy.get(`.num-results`).should(`include.text`, `of 62.`)
})

it(`Option: Case Sensitive`, function() {
cy.visit(`/search`)
cy.contains(`label`, `Advanced Search`).click()
Expand Down

0 comments on commit 9770308

Please sign in to comment.