Make Bases 'contain' catch properties even if not exactly that value

Use case or problem

I want to be able to use bases to find notes that contain a certain text value in a property, but without having to be that exact value. It just needs to contain that text value.

A use case. I’m a farmer and have organized crops according to the time I sow them, time I plant them etc. One crop can have in its “sowing-time” property the values “1 ultimo january”, “2 february” and “3 medio march” (as a list property)

I want to be able to pull up a base with all the crops I can sow in March. If I put ‘sowing-time contains march’ then nothing comes up. If I put ‘sowing-time contains 3 march’ then all the crops come up with exactly “3 march” as one of the values in that property, but it doesn’t catch any crops with the value “3 medio march” or “3 ultimo march” etc.

Proposed solution

When using ‘contains’ bases takes that literally.

If I have notes that have a property with values like “Favourite book” and “Worst book ever” and “Unread book” and “Great movie” and I make a filter that contains “book” then I should get notes with the first three values, but not the fourth.

Current workaround (optional)

Base cannot currently do this (other users provided a workaround in this help thread). Dataview can do it, so I assume it should be simple to integrate into bases.

Related feature requests (optional)

This is not fully correct. There is a difference between using .contains() on a list or a string. List items have to fully match the term while for strings the term must only correctly appear within the string.

With lists you can always do something like list.filter(value.contains("term")) to use the string .contains() function.

I don’t understand. Are you saying that base can do what I want it to do? In that case, I’m curious how.

Bases can do what you want, but not in the way you are currently doing it.

You can have a look at the .contains() function for lists (Functions - Obsidian Help) and strings (Functions - Obsidian Help).

Then have a look at the .map() and .filter() function which allow you to use the string .contains() on lists. ( See the example in my last post)

That’s great new. I’m looking at the help section for base and don’t understand all the code. I don’t know what ‘strings’ or ‘map’ means. Admidetly, most of the text on the help page you link to is impossible for me to understand.

I tried your suggestion to use list.filter(value.contains("term")) but couldn’t get it working.

Value is that what I call property and term is what I call value?

Assumptions:

  • sowing-time is the property name
  • sowing-time is a list property
  • you want to filter for 3 march in sowing-time in every possible combination

Then you can add as an advanced filter to your base:
sowing-time.filter(value.contains("march") && value.contains("3"))

This will return 3 march, 3 medio march, 3 ultimo march and more.

1 Like

Yes, this works too as a workaround. I have used the filter note["sowing-time"].filter(value.contains("jan")) (as linked to in the thread above) and that works in the same way.

The workaround doesn’t work in all cases though. Let me give an example:

  • direct-sown is a property name (list)
  • Possible values in that property are all in a date format (2024.03.12 or 2026.05.12, for example)
  • I want to exclude all notes that have a value containing “2026”, ie. all crops that have been direct-sown this year.

If I make a group filter and say “None of the below applies” and then put direct-sown.filter(value.contains("2026") it doesn’t work. I’m not sure what happens but I think it excludes even all notes that contain 2, 0 and 6 somewhere in the value (like 2025.06.02 - even though that is strictly not “2026”).

I cannot reproduce this result for me.

A few things:

  1. I think you will also need note["direct-sown"] here, because of the hyphen.

  2. Dates can sometimes break formulas. You can try note["direct-sown"].filter(value.toString().contains("2026")) to ensure that the value is a string type and no date type. Possibly this results in the issue you observed, because when a filter can not be evaluated for a file, it will not be excluded by your None of the below applies filter.

For me the above formula only returns values that contain 2026, so maybe give it a try.

For some reason, this doesn’t work for me. I’m copy pasting what I have in my base now so you can see exactly what it is. My language is Danish, so I’ve translated the values to English here in the thread. I’ve tried using ‘aa’ instead of ‘å’ so the problem doesn’t stem from that character either.

I hope I did translate everything correctly. For me it still seems to work. Can you give me some examples where the filter fails for you?

Filter:

Before filter:

After filter: