diff --git a/src/docbkx/reference/programming-model/indexing.xml b/src/docbkx/reference/programming-model/indexing.xml index 79ed0c768..a405c5fd8 100644 --- a/src/docbkx/reference/programming-model/indexing.xml +++ b/src/docbkx/reference/programming-model/indexing.xml @@ -4,132 +4,139 @@ Indexing - The Neo4j graph database can use different index providers for exact lookups and fulltext searches. Lucene is - used as default index provider implementation. There is support for distinct indexes for nodes and relationships - which can be configured to be of fulltext or exact types. + The Neo4j graph database can use different so-called index providers for exact lookups and fulltext + searches. Lucene is the default index provider implementation. Each named index is configured to be + fulltext or exact.
- Exact and Numeric Index - - Using the standard Neo4j API, Nodes and Relationships and their indexed field-value combinations - have to be added manually to the appropriate index. When using Spring Data Graph, this task is simplified by - eased by applying an @Indexed annotation on entity fields. This will result in updates to the - index on every change. - - Numerical fields are indexed numerically so that they are available for range queries. - All other fields are indexed with their string representation. - - The @Indexed annotation can also set the - index-name to be used the default index name is the simple class name of the entity. So the same field names - from different classes don't end up in the same index by default. That would return different domain objects - for a single index query. - - - Query access to the index happens with the Node- and Relationship-Repostories that are created via an instance of - org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory. The methods - findByPropertyValue and findAllByPropertyValue work on the exact indexes and - return the first or all matches. To do range queries, use findAllByRange (please note that - currently both values are inclusive). - - Exact and numeric index + + When using the standard Neo4j API, nodes and relationships have to be manually indexed with + key-value pairs, typically being the property name and value. When using Spring Data Graph, + this task is simplified to just adding an @Indexed annotation on entity fields + by which the entity should be searchable. This will result in automatic updates of the index + every time an indexed field changes. + + + Numerical fields are indexed numerically so that they are available for range queries. All + other fields are indexed with their string representation. + + + The @Indexed annotation also provides the option of using a custom index. The default index + name is the simple class name of the entity, so that each class typically gets its own index. + It is recommended to not have two entity classes with the same class name, regardless of + package. + + + The indexes can be queried by using a repository (see ). + Typically, the repository is an instance of + org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory. + The methods findByPropertyValue() and findAllByPropertyValue() work on + the exact indexes and return the first or all matches. To do range queries, use + findAllByRange() (please note that currently both values are inclusive). + + + Indexing entities + graphRepository = graphRepositoryFactory.createGraphRepository(Person.class); -// exact graphRepository -Person mark = graphRepository.findByProperyValue("people","name","mark"); +// Exact match, in named index +Person mark = graphRepository.findByPropertyValue("people", "name", "mark"); -// numeric range queries -for (Person middleAgedDeveloper : graphRepository.findAllByRange( "age", 20, 40)) { +// Numeric range query, index name inferred automatically +for (Person middleAgedDeveloper : graphRepository.findAllByRange("age", 20, 40)) { Developer developer=middleAgedDeveloper.projectTo(Developer.class); } ]]> -
+ + +
- Fulltext Indexes + Fulltext indexes - Spring Data Graph also supports full-text indexes. By default indexed fields are stored in an exact-lookup - index. To have them analyzed and prepared for fulltext search, the @Indexed annotation has - the boolean fulltext attribute. Please note that fulltext-indexes require a separate index name - as the fulltext-configuration is stored in the index itself. + Spring Data Graph also supports fulltext indexes. By default, indexed fields are stored in + an exact lookup index. To have them analyzed and prepared for fulltext search, the + @Indexed annotation has the boolean fulltext attribute. + + Please note that fulltext indexes require a separate index name as the fulltext configuration + is stored in the index itself. - Access to the fulltext index is provided by the findAllByQuery method of the repositories. Wildcard - like * are allowed. Otherwise the fulltext querying rules of the underlying index provider apply. (In most - cases this will be lucene. + Access to the fulltext index is provided by the findAllByQuery() repository method. + Wildcards like * are allowed. Generally though, the fulltext querying rules of the + underlying index provider apply. See the + Lucene documentation for more + information on this. - + Fulltext indexing + graphRepository = graphRepositoryFactory.createGraphRepository(Person.class); -// exact graphRepository -Person mark = graphRepository.findAllByQuery("people-search","name","ma*"); +Person mark = graphRepository.findAllByQuery("people-search", "name", "ma*"); ]]> + + - - Please note that indexes are currently created on demand, so whenever an index that doesn't exist - is requested from a query or get operation it is created. This is subject to change but has currently - the implication that those indexes won't be configured as fulltext which causes subsequent fulltext- - updates to those indexes to fail. - + Please note that indexes are currently created on demand, so whenever an index that doesn't exist + is requested from a query or get operation it is created. This is subject to change but has + currently the implication that those indexes won't be configured as fulltext which causes + subsequent fulltext updates to those indexes to fail.
- Raw Index Access - The raw index for a domain class is also available from GraphDatabaseContext via the - getIndex method. The second parameter is optional and takes the index-name if it doesn't default - to the simple domain class name. It returns the Index implementation that is provided by Neo4j. + Manual index access + + The index for a domain class is also available from GraphDatabaseContext via + the getIndex() method. The second parameter is optional and takes the index name + if it should not be inferred from the class name. It returns the index implementation that is + provided by Neo4j. + + + Manual index usage personIndex=gdc.getIndex(Person.class,null); -personIndex.add(node,"name","Mark"); +// Default index +Index personIndex = gdc.getIndex(Person.class); +personIndex.query(new QueryContext(NumericRangeQuery.newÍntRange("age", 20, 40, true, true)) + .sort(new Sort(new SortField("age", SortField.INT, false)))); -Index namedPersonIndex=gdc.getIndex(Person.class,"people"); -namedPersonIndex.get("name","Mark"); +// Named index +Index namedPersonIndex = gdc.getIndex(Person.class, "people"); +namedPersonIndex.get("name", "Mark"); -// complex range & sort query -namedPersonIndex.query( new QueryContext( NumericRangeQuery.newÍntRange( "age", 20, 40, true, true ) ) - .sort( new Sort( new SortField( "age", SortField.INT, false ) ) ) ); - -// fulltext index -Index personFulltextIndex=gdc.getIndex(Person.class,"person-name",true); -namedPersonIndex.query("name","Ma*"); -namedPersonIndex.query("{name:Ma*}"); - - ]]> - - +// Fulltext index +Index personFulltextIndex = gdc.getIndex(Person.class, "person-name", true); +personFulltextIndex.query("name", "*cha*"); +personFulltextIndex.query("{name:*cha*}"); +]]> +
Indexing in Neo4jTemplate - Neo4jTemplate also offers index support, providing auto-indexing for fields at creation time of nodes and - relationships. There is an autoIndex method that can also add indexes for a set of fields in one - go. + Neo4jTemplate also offers index support, providing auto-indexing for fields at creation time. + There is an autoIndex method that can also add indexes for a set of fields in one go. - For querying the index, the template offers query-methods that take either the exact match parameters or a query - object / query expression and push the results wrapped uniformly as Paths to the supplied - PathMapper to be converted or collected. + For querying the index, the template offers query methods that take either the exact match + parameters or a query object/expression, and push the results wrapped uniformly as Paths to + the supplied PathMapper to be converted or collected.
diff --git a/src/docbkx/reference/programming-model/repositories.xml b/src/docbkx/reference/programming-model/repositories.xml index 1fb999be9..7f173bef8 100644 --- a/src/docbkx/reference/programming-model/repositories.xml +++ b/src/docbkx/reference/programming-model/repositories.xml @@ -1,6 +1,6 @@ -
+
GraphRepositories for basic CRUD and find-operations The repositories provided by Spring Data Graph build on the composable repository infrastructure contained