What is the best practice for implementing tags with Neo4j and rails? -
have neo4j based rails app , want implement tags. not sure how go it. thinking of creating new model nodes "tag" label, seemed kind of overkill. there approach https://github.com/mbleigh/acts-as-taggable-on neo4j based app?
it depends on want on performance considerations ;)
creating tag
model isn't overkill, make sure merge
tags whenever create them make sure don't create duplicates. can use neo4j's graph traversal abilities jump tags other objects , vice versa, more complicated queries making recommendations between objects according how many tags share / don't share.
if want have basic list of strings, neo4j supports having array properties on nodes , relationships. can use declaring property on model this:
class modelclass include neo4j::activenode property :tags end
the issue can't index based on arrays (i think that's planned future). if performance big concern rather showing list of tags, tag
nodes might best bet.
also, best performance in case lot of tags, you'll want index tag name/text/whatever-you-call-that-property. there few ways that:
class tag include neo4j::activenode property :name, index: :exact end
or can use neo4j constraint ensure no 2 nodes have same name:
class tag include neo4j::activenode property :name, constraint: :unique end
constraints automatically create indexes under cover performance.
lastly, if you'd rather tag
model not use default uuid
column uniquely identifying tags , instead use name do:
class tag include neo4j::activenode id_property :name end
that creates constraint name
property.
Comments
Post a Comment