I can't make Dataview discriminate between similar values - Is there syntax I can use to make it more explicit?

Things I have tried

I’ve tried googling how to make values and queries more exclusive, I’ve tried enclosing queries and values in random brackets, all I get are errors or empty returns…

What I’m trying to do

I’m trying to query for files that contain a certain value in a metadata field. However, the issue is that some values are similar. In this case, I have two values: “a-” and “pha-” and the dataview query counts “pha-” as being the same as “a-” because the ending is the same (I verified this by removing the “pha-” from the field and the query removed that specific file). Is there a way for me to make sure the query can distinguish?

So here’s my example. The field of interest is “roots”, the dataview query is on the last line of the left panel, and the visual representation of that dataview query is in the callout named “Derivations”. You can see that “tachyphasia” (also shown in the right pane) is included in the table because one of the values in the roots field, “pha-” is similar to the query’s target, “a-”.

Sorry if this is a stupid question, I only started learning dataview this afternoon and have no background with coding. (Well, I did learn how to draw a shape and make it move around in Khan Academy but that was when I was like 8 lol)

I think this might be a case where a regular expression (aka regex) to indicate that the a- should be at the start of the string could help you. Pinging @I-d-as, one of the local regex fans, for additional help!

1 Like

I guess you don’t need regex here…
Try WHERE econtains(roots, "a-"), using econtains() instead of contains().
econtains() means “exact contains”.


Thank you, I didn’t know econtains.

I also found another possible solution that may work even better as it allows for multiple roots (in this case, a- and an-).

I adapted this from some other piece of code + that econtains thing you taught me, so I don’t 100% understand what it’s saying but I was able to reverse-engineer this sort of thing and it appears to work…

TABLE definition AS Definition 
FROM #medterm 
WHERE length(filter(roots, (word) => econtains([[]].roots, word))) > 0
1 Like

if you want to explore multiple roots you can use
WHERE econtains(roots, "a-") OR econtains(roots, "an-")
(if you want, as condition, both values, then replace OR by AND).

About your suggested query, I don’t see the advantage because it makes a filter based on the roots of the current note.

I just want it to be automated. I have it baked into a template and am making a personal dictionary so it would be a pain to manually input each root into the query.

Does the query I frankensteined not filter for the “roots” of the current note and then source other files that report a matching" roots" value? It appears to work at least for now.

Here’s a photo of what I made, and it seems to be working: notice how now “anhydrous” was detected while “tachyphasia” was ignored.

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