RED-10290: Improve SearchImplementation logic for dictionaries
* pmd and checkstyle fixup
This commit is contained in:
parent
f1090909cc
commit
a9e4fa31bf
@ -5,31 +5,31 @@ import org.ahocorasick.trie.PayloadTrie;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public class DictionaryIdentifierTrie {
|
public final class DictionaryIdentifierTrie {
|
||||||
private final PayloadTrie<DictionaryIdentifier> trie;
|
private final PayloadTrie<DictionaryIdentifier> trie;
|
||||||
|
|
||||||
private DictionaryIdentifierTrie(PayloadTrie<DictionaryIdentifier> trie) {
|
private DictionaryIdentifierTrie(PayloadTrie<DictionaryIdentifier> trie) {
|
||||||
this.trie = trie;
|
this.trie = trie;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class DictionaryIdentifierTrieBuilder {
|
||||||
private final PayloadTrie.PayloadTrieBuilder<DictionaryIdentifier> builder;
|
private final PayloadTrie.PayloadTrieBuilder<DictionaryIdentifier> builder;
|
||||||
|
|
||||||
public Builder() {
|
public DictionaryIdentifierTrieBuilder() {
|
||||||
this.builder = PayloadTrie.builder();
|
this.builder = PayloadTrie.builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder ignoreCase() {
|
public DictionaryIdentifierTrieBuilder ignoreCase() {
|
||||||
builder.ignoreCase();
|
builder.ignoreCase();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addKeyword(String keyword, DictionaryIdentifier payload) {
|
public DictionaryIdentifierTrieBuilder addKeyword(String keyword, DictionaryIdentifier payload) {
|
||||||
builder.addKeyword(keyword, payload);
|
builder.addKeyword(keyword, payload);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addKeywords(Collection<String> keywords, DictionaryIdentifier payload) {
|
public DictionaryIdentifierTrieBuilder addKeywords(Collection<String> keywords, DictionaryIdentifier payload) {
|
||||||
for (String keyword : keywords) {
|
for (String keyword : keywords) {
|
||||||
builder.addKeyword(keyword, payload);
|
builder.addKeyword(keyword, payload);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -137,7 +137,7 @@ public class DoubleArrayTrieDictionarySearch implements DictionarySearch {
|
|||||||
private final int offset;
|
private final int offset;
|
||||||
|
|
||||||
|
|
||||||
public TextContext(CharSequence text, int offset) {
|
TextContext(CharSequence text, int offset) {
|
||||||
|
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.lowerText = text.toString().toLowerCase(Locale.ROOT);
|
this.lowerText = text.toString().toLowerCase(Locale.ROOT);
|
||||||
@ -145,7 +145,7 @@ public class DoubleArrayTrieDictionarySearch implements DictionarySearch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public TextContext(CharSequence text) {
|
TextContext(CharSequence text) {
|
||||||
|
|
||||||
this(text, 0);
|
this(text, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,7 @@ public class TrieDictionarySearch implements DictionarySearch {
|
|||||||
if (entries.isEmpty()) {
|
if (entries.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
DictionaryIdentifierTrie.Builder builder = new DictionaryIdentifierTrie.Builder();
|
DictionaryIdentifierTrie.DictionaryIdentifierTrieBuilder builder = new DictionaryIdentifierTrie.DictionaryIdentifierTrieBuilder();
|
||||||
if (ignoreCase) {
|
if (ignoreCase) {
|
||||||
builder.ignoreCase();
|
builder.ignoreCase();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user