cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

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

1 ACCEPTED SOLUTION

krisgeus
Node Clone

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

View solution in original post

3 REPLIES 3

krisgeus
Node Clone

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

krisgeus
Node Clone

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.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online