Skip to content

Commit 0992ee3

Browse files
authored
Feature/3.8 analyzers (arangodb#375)
* pipeline analyzer * aql analyzer * geojson analyzer * geopoint analyzer * AQL analyzer returnType * StopwordsAnalyzer * javadoc upd
1 parent c2ca786 commit 0992ee3

15 files changed

+1104
-8
lines changed

ChangeLog.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9+
- added support for ArangoSearch `AQL`, `Pipeline`, `Stopwords`, `GeoJSON`, `GeoPoint` analyzers
910
- fixed active failover behavior for the asynchronous driver
1011
- deprecated `ArangoIterable` methods in favour of Java 8 Stream equivalents
1112

src/main/java/com/arangodb/entity/arangosearch/AnalyzerType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424
* @author Michele Rastelli
2525
*/
2626
public enum AnalyzerType {
27-
identity, delimiter, stem, norm, ngram, text
27+
identity, delimiter, stem, norm, ngram, text, pipeline, stopwords, aql, geojson, geopoint
2828
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb.entity.arangosearch.analyzer;
22+
23+
24+
import com.arangodb.entity.arangosearch.AnalyzerType;
25+
26+
import java.util.Objects;
27+
28+
/**
29+
* An Analyzer capable of running a restricted AQL query to perform data manipulation / filtering.
30+
*
31+
* @author Michele Rastelli
32+
* @see <a href= "https://www.arangodb.com/docs/stable/arangosearch-analyzers.html#aql">API Documentation</a>
33+
* @since ArangoDB 3.8
34+
*/
35+
public class AQLAnalyzer extends SearchAnalyzer {
36+
public AQLAnalyzer() {
37+
setType(AnalyzerType.aql);
38+
}
39+
40+
private AQLAnalyzerProperties properties;
41+
42+
public AQLAnalyzerProperties getProperties() {
43+
return properties;
44+
}
45+
46+
public void setProperties(AQLAnalyzerProperties properties) {
47+
this.properties = properties;
48+
}
49+
50+
@Override
51+
public boolean equals(Object o) {
52+
if (this == o) return true;
53+
if (o == null || getClass() != o.getClass()) return false;
54+
if (!super.equals(o)) return false;
55+
AQLAnalyzer that = (AQLAnalyzer) o;
56+
return Objects.equals(properties, that.properties);
57+
}
58+
59+
@Override
60+
public int hashCode() {
61+
return Objects.hash(super.hashCode(), properties);
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
22+
package com.arangodb.entity.arangosearch.analyzer;
23+
24+
25+
import java.util.Objects;
26+
27+
/**
28+
* @author Michele Rastelli
29+
*/
30+
public class AQLAnalyzerProperties {
31+
32+
private String queryString;
33+
private Boolean collapsePositions;
34+
private Boolean keepNull;
35+
private Integer batchSize;
36+
private Long memoryLimit;
37+
38+
private ReturnType returnType;
39+
40+
public enum ReturnType {
41+
string, number, bool
42+
}
43+
44+
/**
45+
* @return AQL query to be executed
46+
*/
47+
public String getQueryString() {
48+
return queryString;
49+
}
50+
51+
public void setQueryString(String queryString) {
52+
this.queryString = queryString;
53+
}
54+
55+
/**
56+
* @return <ul>
57+
* <li>
58+
* true: set the position to 0 for all members of the query result array
59+
* </li>
60+
* <li>
61+
* false (default): set the position corresponding to the index of the result array member
62+
* </li>
63+
* </ul>
64+
*/
65+
public Boolean getCollapsePositions() {
66+
return collapsePositions;
67+
}
68+
69+
public void setCollapsePositions(Boolean collapsePositions) {
70+
this.collapsePositions = collapsePositions;
71+
}
72+
73+
/**
74+
* @return <ul>
75+
* <li>
76+
* true (default): treat null like an empty string
77+
* </li>
78+
* <li>
79+
* false: discard nulls from View index. Can be used for index filtering (i.e. make your query return null for unwanted data). Note that empty results are always discarded.
80+
* </li>
81+
* </ul>
82+
*/
83+
public Boolean getKeepNull() {
84+
return keepNull;
85+
}
86+
87+
public void setKeepNull(Boolean keepNull) {
88+
this.keepNull = keepNull;
89+
}
90+
91+
/**
92+
* @return number between 1 and 1000 (default = 1) that determines the batch size for reading data from the query.
93+
* In general, a single token is expected to be returned. However, if the query is expected to return many results,
94+
* then increasing batchSize trades memory for performance.
95+
*/
96+
public Integer getBatchSize() {
97+
return batchSize;
98+
}
99+
100+
public void setBatchSize(Integer batchSize) {
101+
this.batchSize = batchSize;
102+
}
103+
104+
/**
105+
* @return memory limit for query execution in bytes. (default is 1048576 = 1Mb) Maximum is 33554432U (32Mb)
106+
*/
107+
public Long getMemoryLimit() {
108+
return memoryLimit;
109+
}
110+
111+
public void setMemoryLimit(Long memoryLimit) {
112+
this.memoryLimit = memoryLimit;
113+
}
114+
115+
/**
116+
* @return data type of the returned tokens. If the indicated type does not match the actual type then an implicit
117+
* type conversion is applied.
118+
*/
119+
public ReturnType getReturnType() {
120+
return returnType;
121+
}
122+
123+
public void setReturnType(ReturnType returnType) {
124+
this.returnType = returnType;
125+
}
126+
127+
@Override
128+
public boolean equals(Object o) {
129+
if (this == o) return true;
130+
if (o == null || getClass() != o.getClass()) return false;
131+
AQLAnalyzerProperties that = (AQLAnalyzerProperties) o;
132+
return Objects.equals(queryString, that.queryString) && Objects.equals(collapsePositions, that.collapsePositions) && Objects.equals(keepNull, that.keepNull) && Objects.equals(batchSize, that.batchSize) && Objects.equals(memoryLimit, that.memoryLimit) && returnType == that.returnType;
133+
}
134+
135+
@Override
136+
public int hashCode() {
137+
return Objects.hash(queryString, collapsePositions, keepNull, batchSize, memoryLimit, returnType);
138+
}
139+
140+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
22+
package com.arangodb.entity.arangosearch.analyzer;
23+
24+
25+
import java.util.Objects;
26+
27+
/**
28+
* @author Michele Rastelli
29+
*/
30+
public class GeoAnalyzerOptions {
31+
32+
private Integer maxCells;
33+
private Integer minLevel;
34+
private Integer maxLevel;
35+
36+
/**
37+
* @return maximum number of S2 cells (default: 20)
38+
*/
39+
public Integer getMaxCells() {
40+
return maxCells;
41+
}
42+
43+
public void setMaxCells(Integer maxCells) {
44+
this.maxCells = maxCells;
45+
}
46+
47+
/**
48+
* @return the least precise S2 level (default: 4)
49+
*/
50+
public Integer getMinLevel() {
51+
return minLevel;
52+
}
53+
54+
public void setMinLevel(Integer minLevel) {
55+
this.minLevel = minLevel;
56+
}
57+
58+
/**
59+
* @return the most precise S2 level (default: 23)
60+
*/
61+
public Integer getMaxLevel() {
62+
return maxLevel;
63+
}
64+
65+
public void setMaxLevel(Integer maxLevel) {
66+
this.maxLevel = maxLevel;
67+
}
68+
69+
@Override
70+
public boolean equals(Object o) {
71+
if (this == o) return true;
72+
if (o == null || getClass() != o.getClass()) return false;
73+
GeoAnalyzerOptions that = (GeoAnalyzerOptions) o;
74+
return Objects.equals(maxCells, that.maxCells) && Objects.equals(minLevel, that.minLevel) && Objects.equals(maxLevel, that.maxLevel);
75+
}
76+
77+
@Override
78+
public int hashCode() {
79+
return Objects.hash(maxCells, minLevel, maxLevel);
80+
}
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
22+
package com.arangodb.entity.arangosearch.analyzer;
23+
24+
import com.arangodb.entity.arangosearch.AnalyzerType;
25+
26+
import java.util.Objects;
27+
28+
/**
29+
* An Analyzer capable of breaking up a GeoJSON object into a set of indexable tokens for further usage with
30+
* ArangoSearch Geo functions.
31+
*
32+
* @author Michele Rastelli
33+
* @see <a href= "https://www.arangodb.com/docs/stable/arangosearch-analyzers.html#geojson">API Documentation</a>
34+
* @since ArangoDB 3.8
35+
*/
36+
public class GeoJSONAnalyzer extends SearchAnalyzer {
37+
public GeoJSONAnalyzer() {
38+
setType(AnalyzerType.geojson);
39+
}
40+
41+
private GeoJSONAnalyzerProperties properties;
42+
43+
public GeoJSONAnalyzerProperties getProperties() {
44+
return properties;
45+
}
46+
47+
public void setProperties(GeoJSONAnalyzerProperties properties) {
48+
this.properties = properties;
49+
}
50+
51+
@Override
52+
public boolean equals(Object o) {
53+
if (this == o) return true;
54+
if (o == null || getClass() != o.getClass()) return false;
55+
if (!super.equals(o)) return false;
56+
GeoJSONAnalyzer that = (GeoJSONAnalyzer) o;
57+
return Objects.equals(properties, that.properties);
58+
}
59+
60+
@Override
61+
public int hashCode() {
62+
return Objects.hash(super.hashCode(), properties);
63+
}
64+
}

0 commit comments

Comments
 (0)