This PR adds sort features to Neo4j's Fulltext indexes.
Overview of changes:
Updates the Fulltext procedures to include optional parameters for sorting (backwards compatible.)
Adds sorting integration to Fulltext's underlying classes. Lucene operations, as well as the Lucene documents themselves, are updated for sorting.
Updates SchemaDescriptor and its subclasses to have access to sortIds and sortTypes. Primarily relies on changes in the MultiTokenSchemaDescriptor to actuate event-based updates of sort properties.
Updates procedure 'db.indexes' to include a sortProperties column.
Sorting is persisted over restarts like other neo4j indexes. Updates how Fulltext indexes are internally stored on disk through SchemaRuleSerialization, updates the neo store format. Adds space for sortIds and sortTypes into the neo store format.
Notes:
The internal storage of Fulltext indexes changed. Neo4j cannot automatically migrate older Fulltext indexes to this newer Fulltext index format. The old Fulltext index will need to be deleted and a new Fulltext index will need to be created. Currently there is no way to migrate to or from this changed store format.
The feature is available for both Node and Relationship Fulltext indexes.
Implemented sort types are "LONG", "DOUBLE", and "STRING".
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:
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:
The index's name is sortIndex.
All queries are done across the Person index.
Querying sortIndex searches on the name property.
Sorting queries can be performed on name, born, and height.
Once the index is created and populated, one can run a query with sorting:
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:
This PR adds sort features to Neo4j's Fulltext indexes.
Overview of changes:
sortProperties
column.SchemaRuleSerialization
, updates the neo store format. Adds space for sortIds and sortTypes into the neo store format.Notes:
The internal storage of Fulltext indexes changed. Neo4j cannot automatically migrate older Fulltext indexes to this newer Fulltext index format. The old Fulltext index will need to be deleted and a new Fulltext index will need to be created. Currently there is no way to migrate to or from this changed store format.
The feature is available for both Node and Relationship Fulltext indexes.
Implemented sort types are "LONG", "DOUBLE", and "STRING".
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:
This call creates a Fulltext node index called
sortIndex
on thePerson
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:
sortIndex
.Person
index.sortIndex
searches on thename
property.name
,born
, andheight
.Once the index is created and populated, one can run a query with sorting:
This runs a Fulltext
john*
query oversortIndex
and then sorts the matching documents on theirborn
property. Any documents (nodes) without aborn
property will be returned last in the list.We can reverse the order of the sort by including an optional parameter
DESC
:The usage is identical for Fulltext relationship indexes.