How might I set a condition on a fulltext index?

I have an index that indexes all of my videos, but I am running AWS rekognition on this videos after they are uploaded and then appending another property "status" which determines if its porn or not.

How might I set a condition on the index that only tracks records with a condition of something like if a.property == 'good'

CALL db.index.fulltext.createNodeIndex(\"videos\",[\"Video\"],[\"title\", \"description\", \"author\", \"tags\", \"mpd\", \"thumbnailUrl\", \"views\", \"publishDate\"])"

One solution is to give a Node a second Label. (Yes, you put zero, one, or more Labels on a node!)

For all "good" videos, you can add a second Label:

So, to set a video's label that is good like this:

MATCH (n:Videos)
WHERE // some condition
CALL apoc.create.addLabels( v, ["GoodVideo" ] ) // Add GoodVideo label
YIELD node

Then node will have two labels: Videos and GoodVideo

Then you can create index restricted to just GoodVideo

CALL db.index.fulltext.createNodeIndex(
"videoIndex", // name of index
["GoodVideo"], //  List of Labels for Nodes to be indexed
// List of Properties to be indexed
["title", "description", "author", "tags", "mpd", "thumbnailUrl", "views", "publishDate"])

You can then match for either Video or GoodVideo (or both.). It might make sense to make Video and GoodVideo mutually exclusive or keep Video label for GoodVideo nodes. That's a design choice which depends on how you think you'll want to access your videos. (You can always change your mind later.)

E.g.

  • MATCH(v:Video)
  • MATCH(v:GoodVideo)
  • MATCH(v:Video:GoodVideo) // Video AND GoodVideo
  • MATCH(v:Video|GoodVideo) // Video OR GoodVideo

(I'm not sure why you used backslashes...). I would reconsider adding publishDate to the index.

Note: there are lots of options for index creation. See: Indexes for full-text search - Neo4j Cypher Manual

honestly wasn't expecting a response this quick or nearly half as detailed. Im going to implement this tomorrow morning, appreciate the insight deeply.

Im thinking as I make that operation to change property status to "good" I will just update the label as youve shown here and then only index the "goodVideo" labels. Pretty simple solution but after typing so much code the brain functions a little slower. Thanks so much for the thought and the references.

The backslashes are only used in javascript code. I think for node.js it throws an error if you dont put backslashes.

I would reconsider adding publishData to the index.

Also why? Its the date of it being published, it does not change and helps when users query videos to show the date. Not bothered by the question, just genuinely curious.

As for publishDate (I fixed my typo), I don't think the search by Date using the full text search will work the way you think.

E.g. you might get back a node that matches a year, another node matching a month, and a third node matching a Day.

Plus you cannot use the fulltext search to search for a range, e.g. between 2015-01-15 to 2017-07-22.

I actually wasn't even thinking of that as I didnt really intend for users to be able to search by date. Im new to using indexes I thought you have to include the property to return that data when you run a search on it. So in this case Im literally just including date there because the search page videos should have dates beside them.

Can you get any property from results returned from a fulltext search even if you dont include it in the index definition?

Depending which call, but either you get back Nodes or Relationships. Then you can get the properties from the Nodes or Relationships.