Forum Documentation Showcase Pricing Learn more

Search a list based on data in its sublists?

Is there a way to search a list based on items in a sublist?

For example: suppose we have a thing type “County” with a field Cities that’s a list of “City” things; and each City thing might have a “Name” (text).

In this scenario, how would you search for all County things whose Cities includes a City entry with Name=“Springfield”?

The best I’ve been able to come up with is to start with a list of all Countys, then use a filter to evaluate the Cities sublist of each:

Search for County [no constraints]: filtered by -> Advanced: This County’s Cities: filtered by -> Name=“Springfield” : count>0

Is this the right approach?

The alternative is for each sublist to link back to its parent… in other words, each City thing includes a field “ParentCounty,” of type County. Then you could do,

Search for City [constraint:Name = Springfield]'s ParentCounty

Both of these routes seem unnecessarily complicated for this task. Am I missing something?

Hi ali,

continuing with your example, here is what I do to solve this problem:

  1. I create a new field for Counties called City as texts (type: text)
  2. Whenever I set or add cities to a county I use: make changes to thing: counties: this counties city as texts =this counties’ list of Cities’ city names.


(that the repeating groups first item is being altered is just to make the example work and can be ignored)

  1. for the repeating group that shows the search results, as data source, I then use do a search for counties: City as texts contains search inputs value

As with any approach there are some limitations as it is not a fuzzy search (which the search autocorrect plugin allows but this plugin does not scale well with 100s of entries), and by using “text contains”: if one city is called field and another springfield you can have unwanted overlaps.

hope I understood you correctly and this helps
happy bubbling,
Julius

There’s no way to do this without storing two copies of the data?

That is the way I would do it.

Maybe Put a :unique on the end.