Skip to content

Feature/analyzers #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/main/java/com/arangodb/ArangoDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

import com.arangodb.entity.*;
import com.arangodb.model.*;
import com.arangodb.entity.arangosearch.AnalyzerEntity;
import com.arangodb.model.arangosearch.AnalyzerDeleteOptions;
import com.arangodb.model.arangosearch.ArangoSearchCreateOptions;

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

/**
* Creates an Analyzer
*
* @param options AnalyzerEntity
* @return the created Analyzer
* @throws ArangoDBException
* @see <a href="https://docs.arangodb.com/current/HTTP/analyzers.html">API Documentation</a>
* @since ArangoDB 3.5.0
*/
AnalyzerEntity createAnalyzer(AnalyzerEntity options) throws ArangoDBException;

/**
* Gets information about an Analyzer
*
* @param name of the Analyzer without database prefix
* @return information about an Analyzer
* @throws ArangoDBException
* @see <a href="https://docs.arangodb.com/current/HTTP/analyzers.html">API Documentation</a>
* @since ArangoDB 3.5.0
*/
AnalyzerEntity getAnalyzer(String name) throws ArangoDBException;

/**
* Retrieves all analyzers definitions.
*
* @return collection of all analyzers definitions
* @throws ArangoDBException
* @see <a href="https://docs.arangodb.com/current/HTTP/analyzers.html">API Documentation</a>
* @since ArangoDB 3.5.0
*/
Collection<AnalyzerEntity> getAnalyzers() throws ArangoDBException;

/**
* Deletes an Analyzer
*
* @param name of the Analyzer without database prefix
* @throws ArangoDBException
* @see <a href="https://docs.arangodb.com/current/HTTP/analyzers.html">API Documentation</a>
* @since ArangoDB 3.5.0
*/
void deleteAnalyzer(String name) throws ArangoDBException;

/**
* Deletes an Analyzer
*
* @param name of the Analyzer without database prefix
* @param options AnalyzerDeleteOptions
* @throws ArangoDBException
* @see <a href="https://docs.arangodb.com/current/HTTP/analyzers.html">API Documentation</a>
* @since ArangoDB 3.5.0
*/
void deleteAnalyzer(String name, AnalyzerDeleteOptions options) throws ArangoDBException;

}
71 changes: 71 additions & 0 deletions src/main/java/com/arangodb/entity/arangosearch/AnalyzerEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* DISCLAIMER
*
* Copyright 2018 ArangoDB GmbH, Cologne, Germany
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright holder is ArangoDB GmbH, Cologne, Germany
*/

package com.arangodb.entity.arangosearch;

import java.util.Map;
import java.util.Set;

/**
* @author Michele Rastelli
*/
public class AnalyzerEntity {

private Set<AnalyzerFeature> features;
private AnalyzerType type;
private String name;
private Map<String, Object> properties;

public AnalyzerEntity() {
}

public Set<AnalyzerFeature> getFeatures() {
return features;
}

public void setFeatures(Set<AnalyzerFeature> features) {
this.features = features;
}

public AnalyzerType getType() {
return type;
}

public void setType(AnalyzerType type) {
this.type = type;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Map<String, Object> getProperties() {
return properties;
}

public void setProperties(Map<String, Object> properties) {
this.properties = properties;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* DISCLAIMER
*
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright holder is ArangoDB GmbH, Cologne, Germany
*/

package com.arangodb.entity.arangosearch;

/**
* @author Michele Rastelli
*/
public enum AnalyzerFeature {
frequency, norm, position
}
28 changes: 28 additions & 0 deletions src/main/java/com/arangodb/entity/arangosearch/AnalyzerType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* DISCLAIMER
*
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright holder is ArangoDB GmbH, Cologne, Germany
*/

package com.arangodb.entity.arangosearch;

/**
* @author Michele Rastelli
*/
public enum AnalyzerType {
identity, delimiter, stem, norm, ngram, text
}
27 changes: 27 additions & 0 deletions src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
import com.arangodb.ArangoSearch;
import com.arangodb.ArangoView;
import com.arangodb.entity.*;
import com.arangodb.entity.arangosearch.AnalyzerEntity;
import com.arangodb.internal.cursor.ArangoCursorImpl;
import com.arangodb.internal.net.HostHandle;
import com.arangodb.internal.util.DocumentUtil;
import com.arangodb.model.*;
import com.arangodb.model.arangosearch.AnalyzerDeleteOptions;
import com.arangodb.model.arangosearch.ArangoSearchCreateOptions;
import com.arangodb.util.ArangoCursorInitializer;
import com.arangodb.velocypack.Type;
Expand Down Expand Up @@ -423,4 +425,29 @@ public ViewEntity createArangoSearch(final String name, final ArangoSearchCreate
return executor.execute(createArangoSearchRequest(name, options), ViewEntity.class);
}

@Override
public AnalyzerEntity createAnalyzer(AnalyzerEntity options) throws ArangoDBException {
return executor.execute(createAnalyzerRequest(options), AnalyzerEntity.class);
}

@Override
public AnalyzerEntity getAnalyzer(String name) throws ArangoDBException {
return executor.execute(getAnalyzerRequest(name), AnalyzerEntity.class);
}

@Override
public Collection<AnalyzerEntity> getAnalyzers() throws ArangoDBException {
return executor.execute(getAnalyzersRequest(), getAnalyzersResponseDeserializer());
}

@Override
public void deleteAnalyzer(String name) throws ArangoDBException {
executor.execute(deleteAnalyzerRequest(name, null), Void.class);
}

@Override
public void deleteAnalyzer(String name, AnalyzerDeleteOptions options) throws ArangoDBException {
executor.execute(deleteAnalyzerRequest(name, options), Void.class);
}

}
33 changes: 33 additions & 0 deletions src/main/java/com/arangodb/internal/InternalArangoDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
import java.util.Map;

import com.arangodb.entity.*;
import com.arangodb.entity.arangosearch.AnalyzerEntity;
import com.arangodb.internal.ArangoExecutor.ResponseDeserializer;
import com.arangodb.internal.util.ArangoSerializationFactory.Serializer;
import com.arangodb.internal.util.RequestUtils;
import com.arangodb.model.*;
import com.arangodb.model.arangosearch.AnalyzerDeleteOptions;
import com.arangodb.model.arangosearch.ArangoSearchCreateOptions;
import com.arangodb.model.arangosearch.ArangoSearchOptionsBuilder;
import com.arangodb.util.ArangoSerializer;
Expand Down Expand Up @@ -493,4 +495,35 @@ protected Request createArangoSearchRequest(final String name, final ArangoSearc
return request(name(), RequestType.POST, InternalArangoView.PATH_API_VIEW).setBody(util().serialize(
ArangoSearchOptionsBuilder.build(options != null ? options : new ArangoSearchCreateOptions(), name)));
}

protected Request getAnalyzerRequest(final String name) {
return request(name(), RequestType.GET, InternalArangoView.PATH_API_ANALYZER, name);
}

protected Request getAnalyzersRequest() {
return request(name(), RequestType.GET, InternalArangoView.PATH_API_ANALYZER);
}

protected ResponseDeserializer<Collection<AnalyzerEntity>> getAnalyzersResponseDeserializer() {
return new ResponseDeserializer<Collection<AnalyzerEntity>>() {
@Override
public Collection<AnalyzerEntity> deserialize(final Response response) throws VPackException {
final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT);
return util().deserialize(result, new Type<Collection<AnalyzerEntity>>() {
}.getType());
}
};
}

protected Request createAnalyzerRequest(final AnalyzerEntity options) {
return request(name(), RequestType.POST, InternalArangoView.PATH_API_ANALYZER)
.setBody(util().serialize(options));
}

protected Request deleteAnalyzerRequest(final String name, final AnalyzerDeleteOptions options) {
Request request = request(name(), RequestType.DELETE, InternalArangoView.PATH_API_ANALYZER, name);
request.putQueryParam("force", options != null ? options.getForce() : null);
return request;
}

}
2 changes: 2 additions & 0 deletions src/main/java/com/arangodb/internal/InternalArangoView.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@

/**
* @author Mark Vollmary
* @author Michele Rastelli
*
*/
public abstract class InternalArangoView<A extends InternalArangoDB<E>, D extends InternalArangoDatabase<A, E>, E extends ArangoExecutor>
extends ArangoExecuteable<E> {

protected static final String PATH_API_VIEW = "/_api/view";
protected static final String PATH_API_ANALYZER = "/_api/analyzer";

protected final D db;
protected volatile String name;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* DISCLAIMER
*
* Copyright 2018 ArangoDB GmbH, Cologne, Germany
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright holder is ArangoDB GmbH, Cologne, Germany
*/

package com.arangodb.model.arangosearch;

/**
* @author Michele Rastelli
*/
public class AnalyzerDeleteOptions {

private Boolean force;

public AnalyzerDeleteOptions() {
}

public Boolean getForce() {
return force;
}

public void setForce(Boolean force) {
this.force = force;
}
}
Loading