0

Think about a simple scenario :

Every post posted by a user will have 5 tags. Now I can handle it in two ways:

  1. Make separate vertex for each tag and attach it with post vertex

     postVertex -------- [hastag] ------------> tagNameVertex
    
  2. Add a property to postVertex say 'hasTag'

     postVertex[hasTag:tagName]
    

Which approach is good in case of searching a post by tag. What I was thinking that if 1000 users use 5 different tag then there will be 5000 tag vertex only but in second case no new tag vertex, just post vertex will handle it using property hasTag.

We can use has() to search based on tag so I think second approach will be good. right?

Manish Kumar
  • 10,214
  • 25
  • 77
  • 147

1 Answers1

1

I did it differently.

Let's say I have a blog with tag1, tag2 and tag4.

tag1 = 1 = pow(2, 0);
tag2 = 2 = pow(2, 1);
tag3 = 4 = pow(2, 2);
tag4 = 8 = pow(2, 3);

I will created a vertex with property tags with value: 11(=1+2+8)

When I filter tag2(value=2), I just need do binary operation (2 & blog-vertex.tags).

But there is a limitation: the tags number should less than 1024(in most systems).

According to your solution, I think has() might not be very efficient when you have a large graph.

Joshua
  • 689
  • 7
  • 16
  • Your solution might be good for limited & small graph cos ur limitation is 1024.It will cross with just 1000 user if each user use 5 tag. – Manish Kumar Mar 10 '14 at 15:22
  • @Manish, the limitation is not in the size of the graph. It rely on how many tags you are going to use. If the tag number is less than 1024, even you have 5,000,000 vertices, it still work. – Joshua Mar 11 '14 at 12:01