Skip to content
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

[DE-751] multi_delimiter analyzer #545

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
public enum AnalyzerType {
identity,
delimiter,
multi_delimiter,
stem,
norm,
ngram,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.analyzer;


import com.arangodb.entity.arangosearch.AnalyzerType;

import java.util.Objects;

/**
* An Analyzer capable of breaking up text into tokens using multiple delimiters.
* Unlike with the delimiter Analyzer, the multi_delimiter Analyzer does not support quoting fields.
*
* @author Michele Rastelli
* @see <a href= "https://docs.arangodb.com/devel/index-and-search/analyzers/#multi_delimiter">API Documentation</a>
* @since ArangoDB 3.12
*/
public final class MultiDelimiterAnalyzer extends SearchAnalyzer {
private MultiDelimiterAnalyzerProperties properties;

public MultiDelimiterAnalyzer() {
setType(AnalyzerType.multi_delimiter);
}

public MultiDelimiterAnalyzerProperties getProperties() {
return properties;
}

public void setProperties(MultiDelimiterAnalyzerProperties properties) {
this.properties = properties;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
MultiDelimiterAnalyzer that = (MultiDelimiterAnalyzer) o;
return Objects.equals(properties, that.properties);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), properties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.analyzer;


import java.util.*;

/**
* @author Michele Rastelli
* @since ArangoDB 3.12
*/
public final class MultiDelimiterAnalyzerProperties {

private Collection<String> delimiter = Collections.emptyList();

/**
* @return a list of strings of which each is considered as one delimiter that can be one or multiple characters
* long. The delimiters must not overlap, which means that a delimiter cannot be a prefix of another delimiter.
*/
public Collection<String> getDelimiter() {
return delimiter;
}

public void setDelimiter(String... delimiter) {
this.delimiter = Arrays.asList(delimiter);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MultiDelimiterAnalyzerProperties that = (MultiDelimiterAnalyzerProperties) o;
return Objects.equals(delimiter, that.delimiter);
}

@Override
public int hashCode() {
return Objects.hash(delimiter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
@JsonSubTypes({
@JsonSubTypes.Type(name = "identity", value = IdentityAnalyzer.class),
@JsonSubTypes.Type(name = "delimiter", value = DelimiterAnalyzer.class),
@JsonSubTypes.Type(name = "multi_delimiter", value = MultiDelimiterAnalyzer.class),
@JsonSubTypes.Type(name = "stem", value = StemAnalyzer.class),
@JsonSubTypes.Type(name = "norm", value = NormAnalyzer.class),
@JsonSubTypes.Type(name = "ngram", value = NGramAnalyzer.class),
Expand Down
23 changes: 23 additions & 0 deletions driver/src/test/java/com/arangodb/ArangoSearchAsyncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,29 @@ void delimiterAnalyzerTyped(ArangoDatabaseAsync db) throws ExecutionException, I
createGetAndDeleteTypedAnalyzer(db, analyzer);
}

@ParameterizedTest
@MethodSource("asyncDbs")
void multiDelimiterAnalyzerTyped(ArangoDatabaseAsync db) throws ExecutionException, InterruptedException {
assumeTrue(isAtLeastVersion(3, 12));

String name = "test-" + UUID.randomUUID();

Set<AnalyzerFeature> features = new HashSet<>();
features.add(AnalyzerFeature.frequency);
features.add(AnalyzerFeature.norm);
features.add(AnalyzerFeature.position);

MultiDelimiterAnalyzerProperties properties = new MultiDelimiterAnalyzerProperties();
properties.setDelimiter("-", ",", "...");

MultiDelimiterAnalyzer analyzer = new MultiDelimiterAnalyzer();
analyzer.setFeatures(features);
analyzer.setName(name);
analyzer.setProperties(properties);

createGetAndDeleteTypedAnalyzer(db, analyzer);
}

@ParameterizedTest
@MethodSource("asyncDbs")
void stemAnalyzerTyped(ArangoDatabaseAsync db) throws ExecutionException, InterruptedException {
Expand Down
23 changes: 23 additions & 0 deletions driver/src/test/java/com/arangodb/ArangoSearchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,29 @@ void delimiterAnalyzerTyped(ArangoDatabase db) {
createGetAndDeleteTypedAnalyzer(db, analyzer);
}

@ParameterizedTest
@MethodSource("dbs")
void multiDelimiterAnalyzerTyped(ArangoDatabase db) {
assumeTrue(isAtLeastVersion(3, 12));

String name = "test-" + UUID.randomUUID();

Set<AnalyzerFeature> features = new HashSet<>();
features.add(AnalyzerFeature.frequency);
features.add(AnalyzerFeature.norm);
features.add(AnalyzerFeature.position);

MultiDelimiterAnalyzerProperties properties = new MultiDelimiterAnalyzerProperties();
properties.setDelimiter("-", ",", "...");

MultiDelimiterAnalyzer analyzer = new MultiDelimiterAnalyzer();
analyzer.setFeatures(features);
analyzer.setName(name);
analyzer.setProperties(properties);

createGetAndDeleteTypedAnalyzer(db, analyzer);
}

@ParameterizedTest
@MethodSource("dbs")
void stemAnalyzerTyped(ArangoDatabase db) {
Expand Down
Loading