Fulltext search boosting search results that start with 'search'

Hi,
I am trying to return the order of my search based on the where the search input is in relation to the text field.
Example:
If I have 3 nodes whereby the title properties are as follows:

  1. Teen Wolf Book
  2. Wolf Killer Book
  3. Book about Wolf
CALL db.index.fulltext.queryNodes('testsearch', '*wolf*')

Thus when I search for wolf it will return based on the id created (1,2,3) as the score is the same for all 3 nodes. However I wish for it to returned based on where the search ('wolf') is located in the title (i.e. 2,1,3). Having the search ('wolf') being first returned when found at the beginning of the title. This should also apply to fuzzy search.

Note: I tried using ORDER BY however this would arrange the result alphabetically

Hi,

You could try this:

CALL db.index.fulltext.queryNodes('testsearch', '*wolf*') yield node, score
WITH node, score
RETURN node, score, apoc.text.indexOf(upper(node.name), 'WOLF') as txt_index
ORDER BY txt_index ASC
1 Like

Of course you need to have apoc library installed and inside the upper finction you need to provide the fieldname used in the fulltext index

@krisgeus Thank you. The solution above worked for me. :slight_smile: