Skip to content

Commit bd6e752

Browse files
authored
Feature/analyzers (#293)
* create analyzer * getAnalyzer and deleteAnalyzer * getAnalyzers * tests for every AnalyzerType * text AnalyzerType test * updated changelog
1 parent bcf2f88 commit bd6e752

File tree

10 files changed

+500
-25
lines changed

10 files changed

+500
-25
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
88

99
### Added
1010

11+
- added support for Analyzers
1112
- added support for Stream Transactions
1213
- added support for named indices
1314
- added support for TTL indices

src/main/java/com/arangodb/ArangoDatabase.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
import com.arangodb.entity.*;
2727
import com.arangodb.model.*;
28+
import com.arangodb.entity.arangosearch.AnalyzerEntity;
29+
import com.arangodb.model.arangosearch.AnalyzerDeleteOptions;
2830
import com.arangodb.model.arangosearch.ArangoSearchCreateOptions;
2931

3032
/**
@@ -707,4 +709,57 @@ <V, E> TraversalEntity<V, E> executeTraversal(Class<V> vertexClass, Class<E> edg
707709
*/
708710
ViewEntity createArangoSearch(String name, ArangoSearchCreateOptions options) throws ArangoDBException;
709711

712+
/**
713+
* Creates an Analyzer
714+
*
715+
* @param options AnalyzerEntity
716+
* @return the created Analyzer
717+
* @throws ArangoDBException
718+
* @see <a href="https://docs.arangodb.com/current/HTTP/analyzers.html">API Documentation</a>
719+
* @since ArangoDB 3.5.0
720+
*/
721+
AnalyzerEntity createAnalyzer(AnalyzerEntity options) throws ArangoDBException;
722+
723+
/**
724+
* Gets information about an Analyzer
725+
*
726+
* @param name of the Analyzer without database prefix
727+
* @return information about an Analyzer
728+
* @throws ArangoDBException
729+
* @see <a href="https://docs.arangodb.com/current/HTTP/analyzers.html">API Documentation</a>
730+
* @since ArangoDB 3.5.0
731+
*/
732+
AnalyzerEntity getAnalyzer(String name) throws ArangoDBException;
733+
734+
/**
735+
* Retrieves all analyzers definitions.
736+
*
737+
* @return collection of all analyzers definitions
738+
* @throws ArangoDBException
739+
* @see <a href="https://docs.arangodb.com/current/HTTP/analyzers.html">API Documentation</a>
740+
* @since ArangoDB 3.5.0
741+
*/
742+
Collection<AnalyzerEntity> getAnalyzers() throws ArangoDBException;
743+
744+
/**
745+
* Deletes an Analyzer
746+
*
747+
* @param name of the Analyzer without database prefix
748+
* @throws ArangoDBException
749+
* @see <a href="https://docs.arangodb.com/current/HTTP/analyzers.html">API Documentation</a>
750+
* @since ArangoDB 3.5.0
751+
*/
752+
void deleteAnalyzer(String name) throws ArangoDBException;
753+
754+
/**
755+
* Deletes an Analyzer
756+
*
757+
* @param name of the Analyzer without database prefix
758+
* @param options AnalyzerDeleteOptions
759+
* @throws ArangoDBException
760+
* @see <a href="https://docs.arangodb.com/current/HTTP/analyzers.html">API Documentation</a>
761+
* @since ArangoDB 3.5.0
762+
*/
763+
void deleteAnalyzer(String name, AnalyzerDeleteOptions options) throws ArangoDBException;
764+
710765
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2018 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;
22+
23+
import java.util.Map;
24+
import java.util.Set;
25+
26+
/**
27+
* @author Michele Rastelli
28+
*/
29+
public class AnalyzerEntity {
30+
31+
private Set<AnalyzerFeature> features;
32+
private AnalyzerType type;
33+
private String name;
34+
private Map<String, Object> properties;
35+
36+
public AnalyzerEntity() {
37+
}
38+
39+
public Set<AnalyzerFeature> getFeatures() {
40+
return features;
41+
}
42+
43+
public void setFeatures(Set<AnalyzerFeature> features) {
44+
this.features = features;
45+
}
46+
47+
public AnalyzerType getType() {
48+
return type;
49+
}
50+
51+
public void setType(AnalyzerType type) {
52+
this.type = type;
53+
}
54+
55+
public String getName() {
56+
return name;
57+
}
58+
59+
public void setName(String name) {
60+
this.name = name;
61+
}
62+
63+
public Map<String, Object> getProperties() {
64+
return properties;
65+
}
66+
67+
public void setProperties(Map<String, Object> properties) {
68+
this.properties = properties;
69+
}
70+
71+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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;
22+
23+
/**
24+
* @author Michele Rastelli
25+
*/
26+
public enum AnalyzerFeature {
27+
frequency, norm, position
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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;
22+
23+
/**
24+
* @author Michele Rastelli
25+
*/
26+
public enum AnalyzerType {
27+
identity, delimiter, stem, norm, ngram, text
28+
}

src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333
import com.arangodb.ArangoSearch;
3434
import com.arangodb.ArangoView;
3535
import com.arangodb.entity.*;
36+
import com.arangodb.entity.arangosearch.AnalyzerEntity;
3637
import com.arangodb.internal.cursor.ArangoCursorImpl;
3738
import com.arangodb.internal.net.HostHandle;
3839
import com.arangodb.internal.util.DocumentUtil;
3940
import com.arangodb.model.*;
41+
import com.arangodb.model.arangosearch.AnalyzerDeleteOptions;
4042
import com.arangodb.model.arangosearch.ArangoSearchCreateOptions;
4143
import com.arangodb.util.ArangoCursorInitializer;
4244
import com.arangodb.velocypack.Type;
@@ -423,4 +425,29 @@ public ViewEntity createArangoSearch(final String name, final ArangoSearchCreate
423425
return executor.execute(createArangoSearchRequest(name, options), ViewEntity.class);
424426
}
425427

428+
@Override
429+
public AnalyzerEntity createAnalyzer(AnalyzerEntity options) throws ArangoDBException {
430+
return executor.execute(createAnalyzerRequest(options), AnalyzerEntity.class);
431+
}
432+
433+
@Override
434+
public AnalyzerEntity getAnalyzer(String name) throws ArangoDBException {
435+
return executor.execute(getAnalyzerRequest(name), AnalyzerEntity.class);
436+
}
437+
438+
@Override
439+
public Collection<AnalyzerEntity> getAnalyzers() throws ArangoDBException {
440+
return executor.execute(getAnalyzersRequest(), getAnalyzersResponseDeserializer());
441+
}
442+
443+
@Override
444+
public void deleteAnalyzer(String name) throws ArangoDBException {
445+
executor.execute(deleteAnalyzerRequest(name, null), Void.class);
446+
}
447+
448+
@Override
449+
public void deleteAnalyzer(String name, AnalyzerDeleteOptions options) throws ArangoDBException {
450+
executor.execute(deleteAnalyzerRequest(name, options), Void.class);
451+
}
452+
426453
}

src/main/java/com/arangodb/internal/InternalArangoDatabase.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
import java.util.Map;
2727

2828
import com.arangodb.entity.*;
29+
import com.arangodb.entity.arangosearch.AnalyzerEntity;
2930
import com.arangodb.internal.ArangoExecutor.ResponseDeserializer;
3031
import com.arangodb.internal.util.ArangoSerializationFactory.Serializer;
3132
import com.arangodb.internal.util.RequestUtils;
3233
import com.arangodb.model.*;
34+
import com.arangodb.model.arangosearch.AnalyzerDeleteOptions;
3335
import com.arangodb.model.arangosearch.ArangoSearchCreateOptions;
3436
import com.arangodb.model.arangosearch.ArangoSearchOptionsBuilder;
3537
import com.arangodb.util.ArangoSerializer;
@@ -493,4 +495,35 @@ protected Request createArangoSearchRequest(final String name, final ArangoSearc
493495
return request(name(), RequestType.POST, InternalArangoView.PATH_API_VIEW).setBody(util().serialize(
494496
ArangoSearchOptionsBuilder.build(options != null ? options : new ArangoSearchCreateOptions(), name)));
495497
}
498+
499+
protected Request getAnalyzerRequest(final String name) {
500+
return request(name(), RequestType.GET, InternalArangoView.PATH_API_ANALYZER, name);
501+
}
502+
503+
protected Request getAnalyzersRequest() {
504+
return request(name(), RequestType.GET, InternalArangoView.PATH_API_ANALYZER);
505+
}
506+
507+
protected ResponseDeserializer<Collection<AnalyzerEntity>> getAnalyzersResponseDeserializer() {
508+
return new ResponseDeserializer<Collection<AnalyzerEntity>>() {
509+
@Override
510+
public Collection<AnalyzerEntity> deserialize(final Response response) throws VPackException {
511+
final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT);
512+
return util().deserialize(result, new Type<Collection<AnalyzerEntity>>() {
513+
}.getType());
514+
}
515+
};
516+
}
517+
518+
protected Request createAnalyzerRequest(final AnalyzerEntity options) {
519+
return request(name(), RequestType.POST, InternalArangoView.PATH_API_ANALYZER)
520+
.setBody(util().serialize(options));
521+
}
522+
523+
protected Request deleteAnalyzerRequest(final String name, final AnalyzerDeleteOptions options) {
524+
Request request = request(name(), RequestType.DELETE, InternalArangoView.PATH_API_ANALYZER, name);
525+
request.putQueryParam("force", options != null ? options.getForce() : null);
526+
return request;
527+
}
528+
496529
}

src/main/java/com/arangodb/internal/InternalArangoView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727

2828
/**
2929
* @author Mark Vollmary
30+
* @author Michele Rastelli
3031
*
3132
*/
3233
public abstract class InternalArangoView<A extends InternalArangoDB<E>, D extends InternalArangoDatabase<A, E>, E extends ArangoExecutor>
3334
extends ArangoExecuteable<E> {
3435

3536
protected static final String PATH_API_VIEW = "/_api/view";
37+
protected static final String PATH_API_ANALYZER = "/_api/analyzer";
3638

3739
protected final D db;
3840
protected volatile String name;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2018 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.model.arangosearch;
22+
23+
/**
24+
* @author Michele Rastelli
25+
*/
26+
public class AnalyzerDeleteOptions {
27+
28+
private Boolean force;
29+
30+
public AnalyzerDeleteOptions() {
31+
}
32+
33+
public Boolean getForce() {
34+
return force;
35+
}
36+
37+
public void setForce(Boolean force) {
38+
this.force = force;
39+
}
40+
}

0 commit comments

Comments
 (0)