You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This describes how to write, test and deploy a user-defined aggregation function for Neo4j.
10
-
11
9
_User-defined aggregation functions_ are functions that aggregate data and return a single result.
12
-
For a comparison between user-defined procedures, functions, and aggregation functions see xref:extending-neo4j/customized-code.adoc[].
10
+
For a comparison between user-defined procedures, functions, and aggregation functions, see xref:extending-neo4j/customized-code.adoc[].
13
11
14
12
15
13
[[call-user-defined-aggregation-function]]
16
-
== Call a aggregation function
14
+
== Call an aggregation function
17
15
18
16
User-defined aggregation functions are called in the same way as any other Cypher aggregation function.
19
17
The function name must be fully qualified, so a function named `longestString` defined in the package `org.neo4j.examples` could be called using:
@@ -32,15 +30,15 @@ User-defined aggregation functions are annotated with `@UserAggregationFunction`
32
30
The annotated function must return an instance of an aggregator class.
33
31
An aggregator class contains one method annotated with `@UserAggregationUpdate` and one method annotated with `@UserAggregationResult`.
34
32
The method annotated with `@UserAggregationUpdate` will be called multiple times and enables the class to aggregate data.
35
-
When the aggregation is done the method annotated with `@UserAggregationResult` is called once and the result of the aggregation will be returned.
33
+
When the aggregation is done, the method annotated with `@UserAggregationResult` will be called once and the result of the aggregation will be returned.
36
34
37
35
See xref:extending-neo4j/values-and-types.adoc[] for details on values and types.
38
36
39
37
For more details, see the Neo4j Javadocs for link:{org-neo4j-procedure-UserAggregationFunction}[`org.neo4j.procedure.UserAggregationFunction`^].
40
38
41
39
[NOTE]
42
40
====
43
-
The correct way to signal an error from within an aggregation function is to throw a `RuntimeException`.
41
+
The correct way to signal an error from within an aggregation function is to throw `RuntimeException`.
44
42
====
45
43
46
44
[source, java]
@@ -92,8 +90,8 @@ public class LongestString
92
90
93
91
Tests for user-defined aggregation functions are created in the same way as those for normal user-defined functions.
94
92
95
-
Below is a template for testing a user-defined aggregation function that finds the longest string.
96
93
94
+
.A template for testing a user-defined aggregation function that finds the longest string.
Copy file name to clipboardExpand all lines: modules/ROOT/pages/extending-neo4j/best-practices.adoc
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,15 @@
4
4
[[best-practices]]
5
5
= Best practices
6
6
7
-
It is also important to consider any security implications of deploying customized code.
7
+
It is important to consider any security implications of deploying customized code.
8
8
Refer to the link:{neo4j-docs-base-uri}/operations-manual/{page-version}/security/securing-extensions[Operations Manual -> Securing Extensions] for details on best practices for securing user-defined procedures and functions.
9
9
10
-
Since you will be running customized-built code and Neo4j in the same JVM, there are a few things you should keep in mind:
10
+
Since you will be running custom-built code and Neo4j in the same JVM, there are a few things you should keep in mind:
11
11
12
12
* Do not create or retain more objects than you strictly need to.
13
13
Large caches in particular tend to promote more objects to the old generation, thus increasing the need for expensive full garbage collections.
14
14
* Do not use internal Neo4j APIs.
15
15
They are internal to Neo4j and subject to change without notice, which may break or change the behavior of your code.
16
16
* If possible, avoid using Java object serialization or reflection in your code or in any runtime dependency that you use.
17
-
Otherwise, if you cannot avoid using Java object serialization and reflection, then ensure that the `-XX:+TrustFinalNonStaticFields` JVM flag is disabled in `neo4j.conf`.
17
+
If you cannot avoid using Java object serialization and reflection, ensure that the `-XX:+TrustFinalNonStaticFields` JVM flag is disabled in `neo4j.conf`.
Copy file name to clipboardExpand all lines: modules/ROOT/pages/extending-neo4j/customized-code.adoc
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,14 +10,14 @@ This is the preferred means for extending Neo4j.
10
10
Examples of use cases for procedures and functions are:
11
11
12
12
* To provide access to functionality that is not available in Cypher.
13
-
* To provide access to thirdparty systems.
13
+
* To provide access to third-party systems.
14
14
* To perform graph-global operations, such as counting connected components or finding dense nodes.
15
15
* To express a procedural operation that is difficult to express declaratively with Cypher.
16
16
17
-
Procedures and functions are written in Java and compiled into _jar_ files.
18
-
They are deployed to the database by dropping that _jar_ file into the _plugins_ directory on each standalone or clustered server.
19
-
For the location of the _plugins_ directory, refer to link:{neo4j-docs-base-uri}/operations-manual/{page-version}/configuration/file-locations[Operations Manual -> File locations].
20
-
The database must be re-started on each server to pick up new procedures and functions.
17
+
Procedures and functions are written in Java and compiled into JAR files.
18
+
They are deployed to the database by dropping that JAR file into the _plugins_ directory on each standalone or clustered server.
19
+
For the location of the _plugins_ directory, refer to link:{neo4j-docs-base-uri}/operations-manual/{page-version}/configuration/file-locations[Operations Manual -> Default file locations].
20
+
The database must be restarted on each server to pick up new procedures and functions.
21
21
22
22
Procedures and functions can take arguments and return results.
23
23
In addition, procedures can perform write operations on the database.
@@ -32,13 +32,13 @@ In addition, procedures can perform write operations on the database.
32
32
| Cardinality
33
33
34
34
| `Procedure`
35
-
| For each row the procedure takes parameters and returns multiple results.
35
+
| For each row, the procedure takes parameters and returns multiple results.
36
36
| `+CALL abc(...)+`
37
37
| Update allowed.
38
38
| Changes cardinality similarly to a `MATCH` clause (0, 1, or many).
39
39
40
40
| `Scalar function`
41
-
| For each row the function takes parameters and returns a single result.
41
+
| For each row, the function takes parameters and returns a single result.
42
42
| `+abc(...)+`
43
43
| Read-only.
44
44
| Maintains cardinality, one for one.
@@ -53,9 +53,9 @@ In addition, procedures can perform write operations on the database.
53
53
54
54
Neo4j also comes bundled with a number of _built-in_ procedures and functions.
55
55
56
-
The available built-in procedures varies depending edition and mode, as described in link:{neo4j-docs-base-uri}/operations-manual/{page-version}/reference/procedures[Operations Manual -> Procedures].
57
-
Running `SHOW PROCEDURES` will display the full list of procedures available in a particular database instance, including user-defined procedures.
56
+
The available built-in procedures vary depending on edition and mode, as described in link:{neo4j-docs-base-uri}/operations-manual/{page-version}/reference/procedures[Operations Manual -> Procedures].
57
+
Running `SHOW PROCEDURES` displays the full list of procedures available in your Neo4j DBMS, including user-defined procedures.
58
58
59
59
The built-in functions are described in link:{neo4j-docs-base-uri}/cypher-manual/{page-version}/functions[Cypher Manual -> Functions].
60
-
Running `SHOW FUNCTIONS` will display the full list of all the functions available in a particular database instance, including user-defined functions.
60
+
Running `SHOW FUNCTIONS` displays the full list of all the functions available in your Neo4j DBMS, including user-defined functions.
Copy file name to clipboardExpand all lines: modules/ROOT/pages/extending-neo4j/full-text-analyzer-provider.adoc
+14-17Lines changed: 14 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,12 @@
4
4
[[extending-neo4j-analyzer-provider]]
5
5
= Full-text index analyzer providers
6
6
7
-
This describes how to extend full-text index analyzers provided in Neo4j.
8
-
9
7
Full-text indexes always have an analyzer, which describes how text is analyzed for indexing and querying.
10
-
The analyzer breaks the text up into smaller tokens, and processes these tokens with a number of filters.
11
-
These filters can do many different things.
12
-
For example, some remove stop-words, such as "the" and "is", while others transform the tokens by stemming them, or turn them into lower-case.
8
+
The analyzer breaks the text up into smaller tokens and processes these tokens using filters.
9
+
The filters can do different things, such as removing stop-words (e.g., _the_ and _is_), stemming the tokens, or turning them into lower-case.
13
10
14
-
Which analyzer you should use depends on what you want to use the index for.
15
-
For example, if the text being indexed belong to a special domain, such as email addresses, you would want an analyzer specific to that domain.
11
+
Which analyzer to use, depends on what you want to use the index for.
12
+
For example, if the text being indexed belongs to a special domain, such as email addresses, you would want an analyzer specific to that domain.
16
13
Or if the text is always in a particular language, such as Russian, you could use an analyzer specific to that language.
17
14
18
15
Neo4j comes with a number of built-in analyzers.
@@ -24,7 +21,7 @@ This default can be changed with the `dbms.index.fulltext.default_analyzer` sett
24
21
This setting only takes effect when a full-text index is created.
25
22
Once a full-text index has been created, it remembers the analyzer in its index-specific settings.
26
23
27
-
It is possible to extend the available analyzers in Neo4j, by implementing an `AnalyzerProvider`.
24
+
It is possible to extend the available analyzers in Neo4j by implementing `AnalyzerProvider`.
28
25
The `AnalyzerProvider` acts as a factory, which builds the concrete Lucene `Analyzer` instance used by the index.
29
26
The following example creates a customized analyzer:
30
27
@@ -61,21 +58,21 @@ public class CustomAnalyzerProvider extends AnalyzerProvider // <1>
61
58
<1> The `CustomAnalyzerProvider` class must be `public`, and it must extend the `org.neo4j.graphdb.schema.AnalyzerProvider` class.
62
59
<2> The `CustomAnalyzerProvider` class must additionally have a `public` constructor that takes no arguments.
63
60
Without this constructor, the new analyzer provider will not be loaded by Neo4j.
64
-
There will be no warnings logged when an analyzer provider is ignored for this reason, so take care.
61
+
There will be no warnings logged when an analyzer provider is ignored because of this reason, so take care.
65
62
<3> The constructor must then call its super-constructor, and give the name of the `custom-analyzer` provider as an argument.
66
-
This is the name that will be used to refer to this analyzer provider, when configuring indexes.
63
+
This is the name that will be used to refer to this analyzer provider when configuring indexes.
67
64
<4> Lastly, the `createAnalyzer` method must be implemented.
68
65
This method creates and returns the concrete `Analyzer` instance, that the indexes will use.
69
-
If this method returns `null` or throws an exception, then the index will be marked as FAILED.
70
-
<5> In this example, we are creating instances of Lucene's `CustomAnalyzer`.
71
-
We can, however, create and return anything that extends the `org.apache.lucene.analysis.Analyzer` class.
66
+
If this method returns `null` or throws an exception, the index will be marked as FAILED.
67
+
<5> This example creates instances of Lucene's `CustomAnalyzer`.
68
+
You can, however, create and return anything that extends the `org.apache.lucene.analysis.Analyzer` class.
72
69
73
70
Follow the guide in xref:extending-neo4j/project-setup.adoc[], to learn how to package the customized `AnalyzerProvider` in a JAR file that can be integrated into Neo4j.
74
71
75
72
The analyzer providers are picked up by Neo4j via service loading.
76
-
This means that in addition to having implemented the class above, we must also add the fully qualified class name to a service file, and put that file on the class path.
73
+
This means that in addition to having implemented the class, you must also add the fully qualified class name to a service file, and put that file on the classpath.
77
74
These service files are usually included in the JAR file that contains the Neo4j extensions.
78
-
In a typical Maven project, such as the one created by the guide above, the directory structure would look like this:
75
+
In a typical Maven project, such as the one created by xref:extending-neo4j/project-setup.adoc[], the directory structure would look like this:
79
76
80
77
[source]
81
78
----
@@ -92,11 +89,11 @@ project/
92
89
----
93
90
<1> This is the `CustomAnalyzerProvider` from our previous code example.
94
91
<2> This is the service loader file.
95
-
It is a plain-text file that contains a line, with the fully qualified name, for each `AnalyzerProvider` we implement in our project.
92
+
It is a plain-text file that contains a line, with the fully qualified name, for each `AnalyzerProvider` implemented in our project.
96
93
In this case, it contains a single line: `my_package.CustomAnalyzerProvider`.
97
94
98
95
99
-
In order for the `META-INF/services` resources to be handled correctly by the `maven-shade-plugin`, it may be necessary to include a service resource transformation to the plug-in configuration.
96
+
For the `META-INF/services` resources to be handled correctly by the `maven-shade-plugin`, it may be necessary to include a service resource transformation to the plug-in configuration.
User-defined functions are created similarly to how procedures are created, but are instead annotated with `@UserFunction` and instead of returning a stream of values it returns a single value.
30
+
User-defined functions are created similarly to how procedures are created.
31
+
But unlike procedures, they are annotated with `@UserFunction` and return a single value instead of a stream of values.
33
32
34
33
See xref:extending-neo4j/values-and-types.adoc[] for details on values and types.
35
34
36
35
For more details, see the link:{org-neo4j-procedure-UserFunction}[Neo4j Javadocs for `org.neo4j.procedure.UserFunction`^].
37
36
38
37
[NOTE]
39
38
====
40
-
The correct way to signal an error from within a function is to throw a `RuntimeException`.
39
+
The correct way to signal an error from within a function is to throw `RuntimeException`.
41
40
====
42
41
43
42
[source, java]
@@ -68,8 +67,7 @@ public class Join
68
67
69
68
Tests for user-defined functions are created in the same way as those for procedures.
70
69
71
-
Below is a template for testing a user-defined function that joins a list of strings.
72
-
70
+
.A template for testing a user-defined function that joins a list of strings.
0 commit comments