How to not filter items in a list that dont exactly match a given search parameter?

0
In my use case I’m filtering a list of Restaurants with FoodCategories list as a member, The filter removes all restaurants that don’t contain what is entered into the search parameter. However my issue is that if the Restaurant has two FoodCategories associated to it and a user enters just one of those two FoodCategories into their search box it does not show the restaurant. For example, if a Steak House has Burgers and Steak as it’s two Food Categories and the user searches for just Burgers then the restaurant will not appear in the search results which it needs to as Steak House has Burgers and the user would want to see that. In this situation how do I filter objects in a list that don’t include at least one food category and make it so the the users search parameter has to include every FoodCategory that a restaurant has associated to it for it to appear in the search results? Screenshots Thank you
asked
2 answers
2

You can do this in Mendix, but not by filtering. If you do not want to commit your SearchParameter, you could solve it as follows:

  • Retrieve all FoodCategories from the Search helper,
  • Iterate over the FoodCategories,
  • For each FoodCategory, retrieve all its restaurants,
  • Add these restaurants to a list (which you have to create outside the loop),
  • After the loop, filter out the blacklisted restaurants.
answered
1

Hi Daniel,

I have struggled with this problem myself. The core of the issue is that there is no IN operator in XPath queries. Make sure to upvote this idea https://forum.mendix.com/link/ideas/580

 

That being said, you have several options: Rene recommends using filter or java in his answer https://forum.mendix.com/link/questions/88582

Another option that I have used with success is to make the search parameter persistent and commit it to the DB before searching.

Then you could query all restaurants that share a category with the search parameter easily using XPath

[Rest_Category/Category/Category_Search=$SearchParameter]

Hope this helps,

-Andrej

answered