Skip to content

Commit

Permalink
Merge pull request #306 from projectEndings/iss267_minNameLengthFeat
Browse files Browse the repository at this point in the history
Iss267 min name length feat
  • Loading branch information
joeytakeda committed Jun 4, 2024
2 parents 20706cb + cb972f5 commit c547fc0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
11 changes: 7 additions & 4 deletions js/SSTypeAhead.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@
* as JSON by the StaticSearch instance which is
* creating this control.
* @param {!string} filterName the textual descriptive name of the
* filter.
* filter.*
* @param {!number} minNameLength the minimum length of textual input that
* will trigger a typeahead search. Normally equal to the
* shortest length of item in the typeahead data list.
*
*/
constructor(rootEl, filterData, filterName, minWordLength){
constructor(rootEl, filterData, filterName, minNameLength){
this.rootEl = rootEl;
this.filterData = filterData;
this.filterName = filterName;
this.minWordLength = minWordLength;
this.minNameLength = minNameLength;
this.reId = /^ssFeat\d+_\d+$/;
//Because so much staticSearch filter handling is based on
//the string values of items rather than ids, we create a map
Expand Down Expand Up @@ -106,7 +109,7 @@
* matches.
*/
populate(){
if ((this.populating)||(this.input.value.length < this.minWordLength)){
if ((this.populating)||(this.input.value.length < this.minNameLength)){
return;
}
this.populating = true;
Expand Down
9 changes: 6 additions & 3 deletions js/StaticSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,15 +451,18 @@ class StaticSearch{
* control and assigns functionality events to it.
* @param {!string} filterId the id of the filter to set up.
* @param {!string} filterName the string name of the filter.
* @param {!number} minNameLength the minimum length for the string
* a user types into the control at which a search
* of the filter values will be initiated.
* @return {boolean} true if a filter is found and set up, else false.
*/
setupFeatFilter(filterId, filterName){
setupFeatFilter(filterId, filterName, minNameLength){
let featFilter = document.getElementById(filterId);
if (featFilter !== null){
try{
//Now we set up the control as a typeahead.
let filterData = this.mapFilterData.get(filterName);
this.mapFeatFilters.set(filterName, new SSTypeAhead(featFilter, filterData, filterName, this.minWordLength));
this.mapFeatFilters.set(filterName, new SSTypeAhead(featFilter, filterData, filterName, minNameLength));
//Re-enable it.
let inp = featFilter.querySelector('input');
inp.disabled = false;
Expand Down Expand Up @@ -540,7 +543,7 @@ class StaticSearch{
let fch = await fetch(this.jsonDirectory + 'filters/' + filterId + this.versionString + '.json');
let json = await fch.json();
this.mapFilterData.set(json.filterName, json);
this.setupFeatFilter(json.filterId, json.filterName);
this.setupFeatFilter(json.filterId, json.filterName, json.minNameLength);
}
//Then set its checkboxes appropriately.
this.mapFeatFilters.get(key).setCheckboxes(searchParams.getAll(key));
Expand Down
23 changes: 12 additions & 11 deletions test/apostrophes.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@
<meta name="Worth reading" class="staticSearch_bool" content="true" />
<meta name="docSortKey" class="staticSearch_docSortKey" content="ddd"/>
<meta name="docTitle" class="staticSearch_docTitle myMeta" content="Porter, 'Apostrophe'"/>
<meta name="People involved" class="staticSearch_feat" content="Martin Holmes"/>
<meta name="People involved" class="staticSearch_feat" content="Joey Takeda"/>
<meta name="People involved" class="staticSearch_feat" content="Captain Janeway"/>
<meta name="People involved" class="staticSearch_feat" content="Ada Lovelace"/>
<meta name="People involved" class="staticSearch_feat" content="John Stow"/>
<meta name="People involved" class="staticSearch_feat" content="Joan Clarke"/>
<meta name="People involved" class="staticSearch_feat" content="Émilie du Châtelet"/>
<meta name="People involved" class="staticSearch_feat" content="Moribund the Burgermeister"/>
<meta name="People involved" class="staticSearch_feat" content="Alfred Lord Tennyson"/>
<meta name="People involved" class="staticSearch_feat" content="Grace Hopper"/>
<meta name="People involved" class="staticSearch_feat" content="Sir James Douglas"/>
<meta name="People involved" class="staticSearch_feat" content="Martin Holmes"/>
<meta name="People involved" class="staticSearch_feat" content="Joey Takeda"/>
<meta name="People involved" class="staticSearch_feat" content="Captain Janeway"/>
<meta name="People involved" class="staticSearch_feat" content="Ada Lovelace"/>
<meta name="People involved" class="staticSearch_feat" content="John Stow"/>
<meta name="People involved" class="staticSearch_feat" content="Joan Clarke"/>
<meta name="People involved" class="staticSearch_feat" content="Émilie du Châtelet"/>
<meta name="People involved" class="staticSearch_feat" content="Moribund the Burgermeister"/>
<meta name="People involved" class="staticSearch_feat" content="Alfred Lord Tennyson"/>
<meta name="People involved" class="staticSearch_feat" content="Grace Hopper"/>
<meta name="People involved" class="staticSearch_feat" content="Sir James Douglas"/>
<meta name="People involved" class="staticSearch_feat" content="X"/>
<style>
body{
max-width: 45rem;
Expand Down
1 change: 1 addition & 0 deletions test/clues.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<meta name="People involved" class="staticSearch_feat" content="John Stow"/>
<meta name="People involved" class="staticSearch_feat" content="Joan Clarke"/>
<meta name="People involved" class="staticSearch_feat" content="Émilie du Châtelet"/>
<meta name="People involved" class="staticSearch_feat" content="X"/>

<style>
div.text{
Expand Down
7 changes: 4 additions & 3 deletions test/tables/booze.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
<meta name="Random numeric value" class="staticSearch_desc" content="21" />
<meta name="Number of animal names" class="staticSearch_num" content="1"/>
<meta name="docImage" class="staticSearch_docImage" content="../images/booze.png" />
<meta name="People involved" class="staticSearch_feat" content="Martin Holmes"/>
<meta name="People involved" class="staticSearch_feat" content="Joey Takeda"/>
<meta name="People involved" class="staticSearch_feat" content="Sir James Douglas"/>
<meta name="People involved" class="staticSearch_feat" content="Martin Holmes"/>
<meta name="People involved" class="staticSearch_feat" content="Joey Takeda"/>
<meta name="People involved" class="staticSearch_feat" content="Sir James Douglas"/>
<meta name="People involved" class="staticSearch_feat" content="X"/>
<script src="../ssTest/ssHighlight.js"> </script>
</head>
<body>
Expand Down
6 changes: 6 additions & 0 deletions xsl/json.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,12 @@
<!--Now fork on filter types and call the respective functions-->
<xsl:choose>
<xsl:when test="$thisFilterType = ('desc', 'feat')">
<xsl:if test="$thisFilterType = 'feat'">
<number key="minNameLength">
<xsl:sequence
select="min(($minWordLength, ($thisFilterMetas ! string-length(@content))))"/>
</number>
</xsl:if>
<xsl:sequence select="hcmc:createDescFeatFilterMap($thisFilterMetas, $thisFilterId)"/>
</xsl:when>
<xsl:when test="$thisFilterType = 'date'">
Expand Down

0 comments on commit c547fc0

Please sign in to comment.