How to check if a string fully matches, rather than matches a substring of, an element of an array using 'contains'?

I would like to query my database by items in the keywords field in the frontmatter, which is a list/array of strings. The problem is that the ‘contains’ operator matches substrings of items. The documentation states that operator is supposed to check ‘if any of the array elements ==equals== the given value’ when the container object is a list.

Sample data:

file1.md:

---
keywords: 
  - apple
---

file2.md:

---
keywords: 
  - ap
---

My query looks like this:

TABLE keywords AS "Keywords"
WHERE contains(keywords, "ap")=true

The desired outcome is that only file2 is shown, but it turned out that file1 also showed up.

Things I have tried

I have tried changing the keywords field into a dictionary:

file1.md:

---
keywords: 
  - apple: [anything, or null]
---

file2.md

---
keywords: 
  - ap: [anything, or null]
---

This allows me to perform the desired query, however it introduces other problems, such as the display of the keywords field in a table when it contains multiple values.

Any help would appreciated!

What I’m trying to do

Hi.
In your query replace contains() by econtains() (means something like “exact contains” → allows you to look for exact matches only rather than substrings). This function is missing in documentation.

```dataview
TABLE keywords AS "Keywords"
WHERE econtains(keywords, "ap")
```
3 Likes

Fantastic, thank you!!!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.