Skip to content

Commit

Permalink
Merge pull request #101 from alan-wu/facet-case-fix
Browse files Browse the repository at this point in the history
Support addFilter with non-matching case.
  • Loading branch information
alan-wu authored Jan 7, 2025
2 parents 913a28e + 26e8925 commit 4a27432
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
<div class="options-container">
<div>Click arrow to open sidebar</div>
<el-button @click="openSearch">search Uberon from refs</el-button>
<el-button @click="singleFacets">Add heart to Filter</el-button>
<el-button @click="singleFacets">Add heart to Filter (facet2 set)</el-button>
<el-button @click="addStomach">Add stomach to Filter</el-button>
<el-button @click="addInferiorVagus">Add inferior vagus to Filter (incorrect case)</el-button>
<el-button @click="addInvalidTerm">Add invalid term to Filter</el-button>
<el-button @click="multiFacets">multiple facets</el-button>
<el-button @click="neuronSearch">open neuron search</el-button>
Expand Down Expand Up @@ -187,6 +188,14 @@ export default {
AND: true,
})
},
addInferiorVagus: function () {
this.$refs.sideBar.addFilter({
facet: 'Inferior vagus X ganglion',
term: 'Anatomical structure',
facetPropPath: 'anatomy.organ.category.name',
AND: true,
})
},
addInvalidTerm: function () {
this.$refs.sideBar.addFilter({
facet: 'Invalid',
Expand Down
12 changes: 9 additions & 3 deletions src/components/SearchFilters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -734,21 +734,27 @@ export default {
/*
* Given a filter, the function below returns the filter in the format of the cascader, returns false if facet is not found
*/
validateAndConvertFilterToHierarchical: function (filter) {
validateAndConvertFilterToHierarchical: function (filter) {
if (filter && filter.facet && filter.term) {
// Convert terms to lower case.
// Flatmap gives us Inferior vagus X ganglion but the term in Algolia
// is Inferior vagus x ganglion (there are other cases as well)
const lowercase = filter.facet.toLowerCase()
if (filter.facet2) {
return filter // if it has a second term we will assume it is hierarchical and return it as is
} else {
for (const firstLayer of this.options) {
if (firstLayer.value === filter.facetPropPath) {
for (const secondLayer of firstLayer.children) {
if (secondLayer.label === filter.facet) {
if (secondLayer.label?.toLowerCase() === lowercase) {
// if we find a match on the second level, the filter will already be correct
// Make sure the case matches the one from Algolia
filter.facet = secondLayer.label
return filter
} else {
if (secondLayer.children && secondLayer.children.length > 0) {
for (const thirdLayer of secondLayer.children) {
if (thirdLayer.label === filter.facet) {
if (thirdLayer.label?.toLowerCase() === lowercase) {
// If we find a match on the third level, we need to switch facet1 to facet2
// and populate facet1 with its parents label.
filter.facet2 = thirdLayer.label
Expand Down

0 comments on commit 4a27432

Please sign in to comment.