Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Filter Snapshot]: Unable to read the 'value' value from the filter snapshot. #76

Open
Patrick386 opened this issue May 18, 2023 · 2 comments
Assignees

Comments

@Patrick386
Copy link

Unable to read the 'value' value from the filter snapshot.

 final FilterState _filterState = FilterState();
   Filters filterList = _filterState.snapshot();
   Set<Filter> fs = filterList.getFilters();
logger.info('filter>>>>:${fs.toString()}');

value: product
INFO: filter>>>>:{FilterFacet{attribute: type, isNegated: false, value: product, score: null}}

I want to display the selected filter value list in the UI, but I am unable to read the 'value'.

@VladislavFitz
Copy link
Contributor

VladislavFitz commented May 26, 2023

Hi @Patrick386 ,

Thank you for bringing up the issue you're facing with reading the value from the Filter class. I'd be happy to assist you with this.

The reason you're unable to access the value is because Filter is an abstract class. As such, it serves as a base class for other concrete filter implementations, namely FilterFacet, FilterNumeric, and FilterTag. Each of these implementations provides a different type of value.

To resolve this issue, you need to explicitly cast your Filter object to the appropriate concrete filter type. By doing so, you will gain access to the specific value associated with that particular filter implementation.

For example, if you have a Filter object and you know that it is an instance of FacetFilter, you can cast it as follows:

Filter filter = ... // Your Filter object
if (filter is FilterFacet) {
  FilterFacet facetFilter = filter as FilterFacet;
  // Now you can access facetFilter.value
}

Similarly, you can perform the cast for NumericFilter or TagFilter based on the specific implementation you are working with.
I hope this helps! If you have any further questions or need additional assistance, please let me know.

@VladislavFitz VladislavFitz self-assigned this May 26, 2023
@Patrick386
Copy link
Author

Hi @Patrick386 ,

Thank you for bringing up the issue you're facing with reading the value from the Filter class. I'd be happy to assist you with this.

The reason you're unable to access the value is because Filter is an abstract class. As such, it serves as a base class for other concrete filter implementations, namely FilterFacet, FilterNumeric, and FilterTag. Each of these implementations provides a different type of value.

To resolve this issue, you need to explicitly cast your Filter object to the appropriate concrete filter type. By doing so, you will gain access to the specific value associated with that particular filter implementation.

For example, if you have a Filter object and you know that it is an instance of FacetFilter, you can cast it as follows:

Filter filter = ... // Your Filter object
if (filter is FilterFacet) {
  FilterFacet facetFilter = filter as FilterFacet;
  // Now you can access facetFilter.value
}

Similarly, you can perform the cast for NumericFilter or TagFilter based on the specific implementation you are working with. I hope this helps! If you have any further questions or need additional assistance, please let me know.

I need a page with a fixed menu order. My question was about creating a menu selector. For example, I have the following menu items: 'All, Music, News, Interior, Nature'. If there is no data available for a selected menu, it should display an empty page. Each menu item is implemented as a single toggle, and for 'All', I have implemented it using the method '_filterState.clear();'. I have already implemented it, but if there are any recommended approaches, please let me know.

I also needed a menu selector with a multi-toggle approach that required the 'filter value' of the searched data. I have implemented it by reading the manual.

Thank you in advance.

스크린샷 2023-06-10 오후 5 47 47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants