org.vertexium.TextIndexHint Maven / Gradle / Ivy
package org.vertexium;
import java.util.*;
public enum TextIndexHint {
/**
* Tokenize this property and index it for full text search.
*/
FULL_TEXT((byte) 0x01),
/**
* Index this property for exact match searches.
*/
EXACT_MATCH((byte) 0x02);
private final byte value;
TextIndexHint(byte value) {
this.value = value;
}
public static byte toBits(TextIndexHint... indexHints) {
return toBits(EnumSet.copyOf(Arrays.asList(indexHints)));
}
public static byte toBits(Collection hints) {
byte b = 0;
for (TextIndexHint hint : hints) {
b |= hint.value;
}
return b;
}
public static Set toSet(byte indexHint) {
Set hints = new HashSet();
if ((indexHint & FULL_TEXT.value) == FULL_TEXT.value) {
hints.add(FULL_TEXT);
}
if ((indexHint & EXACT_MATCH.value) == EXACT_MATCH.value) {
hints.add(EXACT_MATCH);
}
return hints;
}
public static Set parse(String str) {
if (str == null || str.equalsIgnoreCase("NONE")) {
return NONE;
}
if (str.equalsIgnoreCase("ALL")) {
return ALL;
}
String[] textIndexHintParts = str.split(",");
Set textIndexHints = new HashSet();
for (String textIndexHintPart : textIndexHintParts) {
if (textIndexHintPart.trim().length() == 0) {
continue;
}
textIndexHints.add(parsePart(textIndexHintPart));
}
return textIndexHints;
}
private static TextIndexHint parsePart(String part) {
part = part.trim();
for (TextIndexHint textIndexHint : TextIndexHint.values()) {
if (textIndexHint.name().equalsIgnoreCase(part)) {
return textIndexHint;
}
}
return TextIndexHint.valueOf(part);
}
/**
* Use this to prevent indexing of this Text property. The property
* will not be searchable.
*/
public static final Set NONE = EnumSet.noneOf(TextIndexHint.class);
/**
* The set of indexing hints that trigger all available indexes for
* a Text property.
*/
public static final Set ALL = EnumSet.of(FULL_TEXT, EXACT_MATCH);
}