Kavya Puranik
Kavya Puranik

Reputation: 29

Neo4j - How to give more weightage to recent timestamp in Fulltext-indexing?

I have created a fulltext index named messageText on property text of node Message.

CALL db.index.fulltext.createNodeIndex('messageText', ['Message'], ['text'])

In the same node(Message), I have another property named created, that contains the timestamp at which the node was created. Is it possible to alter the index to give more weightage to the recently created messages? That is, if there are 2 identical text values, give a higher score to a node having latest timestamp value.

Upvotes: 0

Views: 84

Answers (1)

cybersam
cybersam

Reputation: 66999

You could adjust the score yourself.

For example, you can increase the raw score by adding the inverse of the difference between the current time and created:

WITH timestamp() AS now
CALL db.index.fulltext.queryNodes('messageText', 'Hello') YIELD node, score
RETURN node, score + 1.0/(now - node.created) AS adjustedScore

The more distant the created time, the smaller the adjustment.

Upvotes: 1

Related Questions