sinequa / sba-angular

Sinequa's Angular-based Search Based Application (SBA) Framework
https://sinequa.github.io/sba-angular/
MIT License
30 stars 23 forks source link

Heatmap: clear all filters not possible anymore #113

Closed Guillaume-Developer closed 9 months ago

Guillaume-Developer commented 9 months ago

Context

We are currently upgrading an application from v11.9.0 to v11.10.0 and we are using the FacetHeatmapComponent.

Description

In previous versions, we had the possibility to clear the filters of a specific facet by using its name, using the Query method removeSelect. In the newest version, it seems that the filter syntax only uses the fields to distinguish between filters and the use of the facet name to clear filters is not longer feasible. This change makes us unable to clear filters from the Facet Heatmap like we would be able to do on any other facets. It also makes us unable to fetch the specific Heatmap filters and differentiate them from other facets. Do you have an idea how we could implement it in the newest version?

Previous implementation

this.clearFilters.action = () => {
      const fieldsX: string[] = this.fieldsX || [this.fieldXPref];
      const fieldsY: string[] = this.fieldsY || [this.fieldYPref];

      for (const x of fieldsX) {
        for (const y of fieldsY)
          this.searchService.query.removeSelect(`${this._name} - ${this.intl.formatMessage(this.appService.getPluralLabel(x))}/${this.intl.formatMessage(this.appService.getPluralLabel(y))}`, true);
      }
      this.searchService.search();
    };
Guillaume-Developer commented 9 months ago

Sorry, it was actually a non-issue. It is possible to do what I wanted by modifying the display of the filtered item to include the name of the Heatmap in it and then use the code below.

this.clearFilters = new Action({
            text:"Clear Filters",
            action: () => {
                if (!this.searchService.query.filters) return;
                for (const filter of this.getHeatmapFilters(this.searchService.query.filters)) this.searchService.query.removeSameFilters(filter);
                this.searchService.search();
            }
        })

private getHeatmapFilters(filters: Filter) {
        const heatmapFilters: Filter[] = [];
        if (isExprFilter(filters) && !filters.display) {
            for (const filter of filters.filters) {
                const heatmapFilter = this.getHeatmapFilters(filter);
                heatmapFilters.push(...heatmapFilter);
            }
        }
        else if (isExprFilter(filters) && filters.display?.startsWith(this._name)) heatmapFilters.push(filters);
        return heatmapFilters; 
    }