Allofterms vs eq

I’m reading through some of the interactive tour.
Source: Query Variables in another query block II | Blocksvars | Dgraph Tour
Why not do: func: eq(name@en, "Taraji Henson")

Hey @gorillastanley,

eq() is a function which is used for exact matching. While alloftherms() looks if all the terms are present in the target predicate in any order.

For example: If you have a mutation like

_:a <name> "peter parker" .


q(func: eq(name, "parker peter")){

it will return blank response while the following will return node with name "peter parker,

q(func: allofterms(name, "parker peter")){

Hope it clarifies your doubt. Feel free to bring up followup questions.

1 Like

Thanks for your response! I guess in that specific example though, it’d be better style to use eq with the exact name of the director?

Yes, eq could have been used but that’s somewhat debatable :slight_smile:. I guess allofterms() was used for two purposes:

  • The director’s name could have contained middle name, or could have been in “lastname firstname” format, so we do not want exact matching.
  • Demonstrate the allofterms() function, so the user can quickly go to the docs and learn about it.
1 Like

Thanks again! That makes sense.

1 Like