-
Notifications
You must be signed in to change notification settings - Fork 276
Neo4j::Wrapper Lucene
THIS PAGE IS OUT OF DATE. IT IS ONLY FOR VERSIONS OF THE NEO4J GEM BEFORE VERSION 3.0
In the neo4j-core
gem you declare an index using the Neo4j::Node.index
method, see Neo4j::Core-Lucene
When using Neo4j::NodeMixin
, Neo4j::RelationshipMixin
, Neo4j::Rails::Model
and Neo4j::Rails::Relationships
you declare index at the same time as you declare properties.
The neo4j-wrapper
and neo4j
gem lucene integration also automatically configure the index so that each class (and its subclasses) will share the same index configuration and lucene files.
Notice You declare index in the same way using the Neo4j::Rails::Model
as in using the Neo4j::NodeMixin
. However, the finder methods for the Neo4j::Rails::Model
is different since it is more similar to how ActiveRecord finders work (it will generate finder methods).
In order to perform a query you must declare an index on the property.
A Lucene index can be declared on nodes and relationships.
Example:
class Person
include Neo4j::NodeMixin
property :name, :index => :exact
end
After each transaction finishes the Person will be indexed.
Neo4j::Transaction.run do
Person.new :name => 'andreas'
end
Person.find('name: andreas').first #=> andreas
See Neo4j::Core-Lucene how the find method works.
Notice that only properties that have been set are added to the index. Thus a property with no set value and no default value will NOT be matched by a wildcard query (*)!
Works as indexing on Neo4j::NodeMixin
By default indexes are of type :exact
which is great for indexing keywords etc.
To index each word in a text you should use a fulltext index. Fulltext uses white-space tokenizer in its analyzer. Add the type :fulltext
(:exact
is default) when you declare the index and in the find method.
Example:
class Person
include Neo4j::NodeMixin
property :name, :index => :fulltext
end
Person.find('name: andreas', :type => :fulltext).first #=> andreas
In order to support sort order and range queries on Fixnum, Float and Date queries you need
to specify that the field will be indexed as a numerical field.
Example:
class Person
include Neo4j::NodeMixin
property :age, :type => Fixnum, :index => :exact
Since the neo4j-wrapper and neo4j gem has support for type converters (see YARD docs for Neo4j::TypeConverter
) you can also query on any type supported by the type converters, like Date and DateTime.
If you specify a :type of Date or DateTime it will be translated into an Fixnum.
class Person
include Neo4j::NodeMixin
property :born, :type => Date, :index => :exact
end
Person.find(:born => Date.today - 5 .. Date.today)
class Person
property :born, :type => DateTime, :index => :exact
end
Person.find(:born).between(Date.today, 5.years.ago)
Both Date
and DateTime
are supported.
The DateTime values will automatically be converted into UTC timezone.
Neo4j has support for converting DateTime and Date to Java long values.
You can create your own type conversion, read:
See TypeConverters method.
The type converters are also used in hash queries where the query parameters can be converted.
WARNING: Much of the information in this wiki is out of date. We are in the process of moving things to readthedocs
- Project Introduction
- Neo4j::ActiveNode
- Neo4j::ActiveRel
- Search and Scope
- Validation, Uniqueness, and Case Sensitivity
- Indexing VS Legacy Indexing
- Optimized Methods
- Inheritance
- Core: Nodes & Rels
- Introduction
- Persistence
- Find : Lucene
- Relationships
- Third Party Gems & extensions
- Scaffolding & Generators
- HA Cluster