forked from geolba/tethys.frontend
- better facet filtering
This commit is contained in:
parent
156bf0ae26
commit
1660bc6830
11
package-lock.json
generated
11
package-lock.json
generated
|
@ -10,6 +10,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@openfonts/open-sans_all": "^1.44.2",
|
"@openfonts/open-sans_all": "^1.44.2",
|
||||||
"axios": "^0.24.0",
|
"axios": "^0.24.0",
|
||||||
|
"class-transformer": "^0.4.0",
|
||||||
"core-js": "^3.6.5",
|
"core-js": "^3.6.5",
|
||||||
"qs": "^6.10.1",
|
"qs": "^6.10.1",
|
||||||
"rxjs": "^6.6.0",
|
"rxjs": "^6.6.0",
|
||||||
|
@ -4716,6 +4717,11 @@
|
||||||
"safe-buffer": "^5.0.1"
|
"safe-buffer": "^5.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/class-transformer": {
|
||||||
|
"version": "0.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.4.0.tgz",
|
||||||
|
"integrity": "sha512-ETWD/H2TbWbKEi7m9N4Km5+cw1hNcqJSxlSYhsLsNjQzWWiZIYA1zafxpK9PwVfaZ6AqR5rrjPVUBGESm5tQUA=="
|
||||||
|
},
|
||||||
"node_modules/class-utils": {
|
"node_modules/class-utils": {
|
||||||
"version": "0.3.6",
|
"version": "0.3.6",
|
||||||
"resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz",
|
"resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz",
|
||||||
|
@ -20774,6 +20780,11 @@
|
||||||
"safe-buffer": "^5.0.1"
|
"safe-buffer": "^5.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"class-transformer": {
|
||||||
|
"version": "0.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.4.0.tgz",
|
||||||
|
"integrity": "sha512-ETWD/H2TbWbKEi7m9N4Km5+cw1hNcqJSxlSYhsLsNjQzWWiZIYA1zafxpK9PwVfaZ6AqR5rrjPVUBGESm5tQUA=="
|
||||||
|
},
|
||||||
"class-utils": {
|
"class-utils": {
|
||||||
"version": "0.3.6",
|
"version": "0.3.6",
|
||||||
"resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz",
|
"resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz",
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@openfonts/open-sans_all": "^1.44.2",
|
"@openfonts/open-sans_all": "^1.44.2",
|
||||||
"axios": "^0.24.0",
|
"axios": "^0.24.0",
|
||||||
|
"class-transformer": "^0.4.0",
|
||||||
"core-js": "^3.6.5",
|
"core-js": "^3.6.5",
|
||||||
"qs": "^6.10.1",
|
"qs": "^6.10.1",
|
||||||
"rxjs": "^6.6.0",
|
"rxjs": "^6.6.0",
|
||||||
|
|
27
src/app.ts
27
src/app.ts
|
@ -8,6 +8,7 @@ import { DatasetService } from "./services/dataset.service";
|
||||||
import { Dataset, Suggestion } from "./models/dataset";
|
import { Dataset, Suggestion } from "./models/dataset";
|
||||||
import { SolrResponse, FacetFields, FacetItem, FacetResults } from "./models/headers";
|
import { SolrResponse, FacetFields, FacetItem, FacetResults } from "./models/headers";
|
||||||
import { ActiveFilterCategories } from "@/models/solr";
|
import { ActiveFilterCategories } from "@/models/solr";
|
||||||
|
import { deserialize } from "class-transformer";
|
||||||
|
|
||||||
@Options({
|
@Options({
|
||||||
components: {
|
components: {
|
||||||
|
@ -63,6 +64,7 @@ export default class App extends Vue {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
this.activeFilterCategories = new ActiveFilterCategories();
|
this.activeFilterCategories = new ActiveFilterCategories();
|
||||||
|
this.facets = new FacetResults();
|
||||||
|
|
||||||
// this.facets = {};
|
// this.facets = {};
|
||||||
this.searchTerm = suggestion;
|
this.searchTerm = suggestion;
|
||||||
|
@ -72,7 +74,7 @@ export default class App extends Vue {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private dataHandler(res: SolrResponse): void {
|
private dataHandler(res: SolrResponse, filterItem?: FacetItem): void {
|
||||||
// this.results = datasets;
|
// this.results = datasets;
|
||||||
this.results = res.response.docs;
|
this.results = res.response.docs;
|
||||||
this.numFound = res.response.numFound;
|
this.numFound = res.response.numFound;
|
||||||
|
@ -108,7 +110,25 @@ export default class App extends Vue {
|
||||||
const facetCategory = facet_fields[prop];
|
const facetCategory = facet_fields[prop];
|
||||||
if (facetCategory.buckets) {
|
if (facetCategory.buckets) {
|
||||||
const facetItems: Array<FacetItem> = facetCategory.buckets;
|
const facetItems: Array<FacetItem> = facetCategory.buckets;
|
||||||
const facetValues = facetItems.filter(function (el) {
|
|
||||||
|
let facetValues = facetItems.map((facetItem, index) => {
|
||||||
|
let rObj: FacetItem;
|
||||||
|
if (filterItem?.val == facetItem.val) {
|
||||||
|
rObj = filterItem;
|
||||||
|
} else if (this.facets[prop]?.some((e) => e.val === facetItem.val)) {
|
||||||
|
// console.log(facetValue + " is included")
|
||||||
|
const indexOfFacetValue = this.facets[prop].findIndex((i) => i.val === facetItem.val);
|
||||||
|
// console.log(indexOfFacetValue);
|
||||||
|
rObj = this.facets[prop][indexOfFacetValue];
|
||||||
|
rObj.count = facetItem.count;
|
||||||
|
// rObj = new FacetItem(val, count);
|
||||||
|
} else {
|
||||||
|
rObj = new FacetItem(facetItem.val, facetItem.count);
|
||||||
|
}
|
||||||
|
return rObj;
|
||||||
|
});
|
||||||
|
|
||||||
|
facetValues = facetValues.filter(function (el) {
|
||||||
return el != null && el.count > 0;
|
return el != null && el.count > 0;
|
||||||
});
|
});
|
||||||
// this.facets[prop] = facetCategory;
|
// this.facets[prop] = facetCategory;
|
||||||
|
@ -131,8 +151,9 @@ export default class App extends Vue {
|
||||||
// if (!this.activeFilterCategories[facetItem.category].some((e) => e === facetItem.val)) {
|
// if (!this.activeFilterCategories[facetItem.category].some((e) => e === facetItem.val)) {
|
||||||
if (!this.activeFilterCategories[facetItem.category].some((e) => e === facetItem.val)) {
|
if (!this.activeFilterCategories[facetItem.category].some((e) => e === facetItem.val)) {
|
||||||
this.activeFilterCategories[facetItem.category].push(facetItem.val);
|
this.activeFilterCategories[facetItem.category].push(facetItem.val);
|
||||||
|
|
||||||
this.rdrAPI.facetedSearch(this.searchTerm, this.activeFilterCategories, this.solr.core, this.solr.host, undefined).subscribe(
|
this.rdrAPI.facetedSearch(this.searchTerm, this.activeFilterCategories, this.solr.core, this.solr.host, undefined).subscribe(
|
||||||
(res: SolrResponse) => this.dataHandler(res),
|
(res: SolrResponse) => this.dataHandler(res, facetItem),
|
||||||
(error: any) => this.errorHandler(error),
|
(error: any) => this.errorHandler(error),
|
||||||
);
|
);
|
||||||
// alert(this.activeFilterCategories[filter.Category]);
|
// alert(this.activeFilterCategories[filter.Category]);
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<ul class="filter-items list-unstyled" v-bind:class="{ limited: facetItems.length > 1 && collapsed }">
|
<ul class="filter-items list-unstyled" v-bind:class="{ limited: facetItems.length > 1 && collapsed }">
|
||||||
<li v-for="(item, index) in facetItems" :key="index" class="list-group-item titlecase">
|
<li v-for="(item, index) in facetItems" :key="index" class="list-group-item titlecase">
|
||||||
<!-- <span :class="item.Active ? 'disabled' : ''" @click.prevent="activateItem(item)">{{ item.val }} ({{ item.count }}) </span> -->
|
<!-- <span :class="item.Active ? 'disabled' : ''" @click.prevent="activateItem(item)">{{ item.val }} ({{ item.count }}) </span> -->
|
||||||
<span @click.prevent="activateItem(item)">{{ item.val }} ({{ item.count }}) </span>
|
<span :class="item.active ? 'disabled' : ''" @click.prevent="activateItem(item)">{{ item.val }} ({{ item.count }}) </span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="overflowing" v-if="overflowing == true">
|
<ul class="overflowing" v-if="overflowing == true">
|
||||||
|
|
|
@ -67,9 +67,16 @@ export interface FacetInstance {
|
||||||
// buckets: Array<FacetItem>;
|
// buckets: Array<FacetItem>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FacetItem {
|
export class FacetItem {
|
||||||
val: string;
|
val: string;
|
||||||
count: number;
|
count: number;
|
||||||
category: string;
|
category: string;
|
||||||
active: boolean;
|
active: boolean;
|
||||||
|
|
||||||
|
constructor(value: string, count: number) {
|
||||||
|
this.val = value;
|
||||||
|
this.count = count;
|
||||||
|
this.active = false;
|
||||||
|
this.category = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,3 +41,5 @@ npm install --save @openfonts/open-sans_all
|
||||||
vue inspect > out.js
|
vue inspect > out.js
|
||||||
|
|
||||||
npm install --save qs
|
npm install --save qs
|
||||||
|
|
||||||
|
npm install --save class-transformer
|
Loading…
Reference in New Issue
Block a user