Skip to content

Commit

Permalink
Merge pull request #637 from dchiller/issue-631-volpiano-search
Browse files Browse the repository at this point in the history
Make improvements to volpiano search
  • Loading branch information
dchiller authored Oct 8, 2022
2 parents 34308d7 + bc05e32 commit 206dbd1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ export default Marionette.Object.extend({

getSearchMetadata: function ()
{
// Don't present a field name
return {
field: null,
fieldName: this.searchParameters.get('field'),
query: this.searchParameters.get('query'),
numFound: this.collection.metadata.numFound
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export default Marionette.ItemView.extend({
_.bindAll(this, 'setQuery');

this.setQueryDebounced = _.debounce(this.setQuery, 250);

// Create a regex that will match all invalid volpiano
// characters
this.invalidVolpianoRegex = /[^1-9a-sw-zA-SW-Z-\(\)]/i
},

/** We don't need to do anything real on a submit because the query is set on each change. */
Expand All @@ -43,11 +47,23 @@ export default Marionette.ItemView.extend({
if (query)
this.ui.searchInput.val(query);

// For volpiano searches, remove the clef from the search before execution
var searchField = this.model.get('field');
var searchInput = this.ui.searchInput.val();
if (searchField === 'volpiano' || searchField === 'volpiano_literal'){
if (searchInput == "" || searchInput == "1"){
this.ui.searchInput.val("1-");
searchInput = "1-";
}
searchInput = searchInput.replaceAll(this.invalidVolpianoRegex, "")
this.ui.searchInput.val(searchInput)
searchInput = searchInput.replaceAll("1-","");
}
// FIXME(wabain): While this class needs to take a SearchInput model so it can initially
// be rendered, we're not actually updating that model here - we're just triggering
// an event which will cause the appropriate changes to propagate. That's kind of
// confusing.
this.trigger('search', this.ui.searchInput.val());
this.trigger('search', searchInput);
this.updateQueryInput();
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
<option>R, Responsory (special)</option>
<option>T, Chant in Transposition</option>
</select>
<% } else { %>
<% } else if (field === 'volpiano' || field === 'volpiano_literal') { %>
<input type="text" class="form-control search-input field-<%= field %>"
placeholder="1-" value="1-<%= query %>">
<% } else { %>
<input type="text" class="form-control search-input field-<%= field %>"
placeholder="Search" value="<%= query %>">
<% } %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<% if (fieldName) { %>
<h3><%- fieldName %> search</h3>
<p class="h4"><i><%- numFound %> <%- numFound === 1 ? 'result' : 'results' %> for query
<% if (fieldName == "volpiano" || fieldName == "volpiano_literal") { %>
</i><span class = "volpiano">1-<%- query %></span>
<% } else { %>
"<%- query %>"</i>
<% } %>
<p class="h4"><i><%- numFound %> <%- numFound === 1 ? 'result' : 'results' %> for query "<%- query %>"</i></p>
</p>

0 comments on commit 206dbd1

Please sign in to comment.