graphfoundation / ongdb

ONgDB is an independent fork of Neo4j® Enterprise Edition version 3.4.0.rc02 licensed under AGPLv3 and/or Community Edition licensed under GPLv3
https://www.graphfoundation.org/projects/ongdb/
391 stars 58 forks source link

3.6 - Single Property Sort on Multi-Property Sorted Node Indexes #17

Closed alexiudice closed 4 years ago

alexiudice commented 4 years ago

This PR adds sort features to Neo4j's Fulltext indexes.

Overview of changes:

Notes:

Usage:

Creating an index with sorts is very similar to creating a regular Fulltext index. Adding sorts is achieved by including a map defining the sorts:

CALL db.index.fulltext.createNodeIndex("sortIndex",["Person"],["name"], {}, {born: "LONG", height: "DOUBLE", name: "STRING"})

This call creates a Fulltext node index called sortIndex on the Person label. The empty map {} is an empty configuration map. The map {born: "LONG", height: "DOUBLE", name: "STRING"} configures which properties we can sort on. The keys (born, height, name) correspond to the property's name and the values (LONG, DOUBLE, STRING) correspond to the property's type on the Neo4j nodes we are indexing.

This will create an index with the following properties:

Once the index is created and populated, one can run a query with sorting:

CALL db.index.fulltext.queryNodes("sortIndex", "john*", "born") YIELD node, score RETURN *

This runs a Fulltext john* query over sortIndex and then sorts the matching documents on their born property. Any documents (nodes) without a born property will be returned last in the list.

We can reverse the order of the sort by including an optional parameter DESC:

CALL db.index.fulltext.queryNodes("sortIndex", "john*", "born", "DESC") YIELD node, score RETURN *

The usage is identical for Fulltext relationship indexes.

alexiudice commented 4 years ago

New branch