Function to query a single node by name takes time


(Avinash Jain) #1

Dgraph version :- v1.0.8 and using Windows - 16GB RAM

schema :- name: string @index(term, trigram) .

suppose there are 2 nodes :- “abc” and “abc 123”.

Now i want to get a node “abc” by name.

query1 :- {node (func: eq(name, “abc”) {uid name}}
query2 :- {node (func: allofterms(name, “abc”) {uid name}}

query1 is giving the exact node but takes time and it’s case sensitive.
query2 is giving both the nodes.

I want to use “term” type, as i will need it for searching and other things so i can’t use “exact” type. and also due to it’s case sensitive so that’s not recommended.

There must be a way to get a node by name and name can be case insensitive and should give the node exact matching the name.


(Michel Conrado (Support Engineer)) #2

Exact and hash are by logic, sensitive. It makes no sense to allow case-insensitive when the function was made for exact things. But this could be discussed.

Term is case insensitive https://docs.dgraph.io/query-language/#term-matching

Regular Expressions you can control the sensitiveness of the consult using “/i”
i case-insensitive (default false)
https://docs.dgraph.io/query-language/#regular-expressions

Syntax Examples: regexp(predicate, /regular-expression/) or case insensitive regexp(predicate, /regular-expression/i)

Could you describe how slow it is? or rather, could fill up an issue in detail (you can use the template for Bugs) in Dgraph’s Repo?

Cheers.


(Avinash Jain) #3

But if i am having two nodes say >> “abc” and “abc 123”
and if i will try to search by name >> “abc”
It gives me both the nodes. I don’t want that. because it may happen in some cases that the graph is having thousands of nodes starting from “abc”… how will i manage to get the exact node.

I know this, but regexp function doesn’t allow me to get the nodes having space in between their names.