use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.
the class IndexTransactionStateTestBase method shouldPerformStringRangeSearchWithAddedEntityInTxState.
@ParameterizedTest
@ValueSource(strings = { "true", "false" })
void shouldPerformStringRangeSearchWithAddedEntityInTxState(boolean needsValues) throws Exception {
// given
Set<Pair<Long, Value>> expected = new HashSet<>();
long entityToChange;
try (KernelTransaction tx = beginTransaction()) {
expected.add(entityWithProp(tx, "banana"));
entityToChange = entityWithPropId(tx, "apple");
tx.commit();
}
createIndex();
// when
try (KernelTransaction tx = beginTransaction()) {
expected.add(entityWithProp(tx, "cherry"));
entityWithProp(tx, "dragonfruit");
IndexDescriptor index = tx.schemaRead().indexGetForName(INDEX_NAME);
TextValue newProperty = stringValue("blueberry");
setProperty(tx, entityToChange, newProperty);
expected.add(Pair.of(entityToChange, newProperty));
int prop = tx.tokenRead().propertyKey(DEFAULT_PROPERTY_NAME);
assertEntityAndValueForSeek(expected, tx, index, needsValues, "berry", PropertyIndexQuery.range(prop, "b", true, "d", false));
}
}
use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.
the class CypherFunctions method right.
public static TextValue right(AnyValue original, AnyValue length) {
assert original != NO_VALUE : "NO_VALUE checks need to happen outside this call";
if (original instanceof TextValue) {
TextValue asText = (TextValue) original;
int len = asInt(length, () -> "Invalid input for length value in function 'right()'");
if (len < 0) {
throw new IndexOutOfBoundsException("negative length");
}
int startVal = asText.length() - len;
return asText.substring(Math.max(0, startVal));
} else {
throw notAString("right", original);
}
}
use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.
the class IndexOrderTestBase method shouldNodeIndexScanInOrderWithStringInMemoryAndConcurrentUpdate.
@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldNodeIndexScanInOrderWithStringInMemoryAndConcurrentUpdate(IndexOrder indexOrder) throws Exception {
String a = "a";
String b = "b";
String c = "c";
createIndex();
TextValue expectedFirst = indexOrder == IndexOrder.ASCENDING ? stringValue(a) : stringValue(c);
TextValue expectedLast = indexOrder == IndexOrder.ASCENDING ? stringValue(c) : stringValue(a);
try (KernelTransaction tx = beginTransaction()) {
int prop = tx.tokenRead().propertyKey(DEFAULT_PROPERTY_NAME);
entityWithProp(tx, a);
entityWithProp(tx, c);
IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
try (var cursor = getEntityValueIndexCursor(tx)) {
PropertyIndexQuery query = PropertyIndexQuery.stringPrefix(prop, stringValue(""));
entityIndexSeek(tx, index, cursor, constrained(indexOrder, true), query);
assertTrue(cursor.next());
assertThat(cursor.propertyValue(0)).isEqualTo(expectedFirst);
assertTrue(cursor.next());
assertThat(cursor.propertyValue(0)).isEqualTo(expectedLast);
concurrentInsert(b);
assertFalse(cursor.next(), () -> "Did not expect to find anything more but found " + cursor.propertyValue(0));
}
tx.commit();
}
// Verify we see all data in the end
try (KernelTransaction tx = beginTransaction()) {
int prop = tx.tokenRead().propertyKey(DEFAULT_PROPERTY_NAME);
IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
try (var cursor = getEntityValueIndexCursor(tx)) {
PropertyIndexQuery query = PropertyIndexQuery.stringPrefix(prop, stringValue(""));
entityIndexSeek(tx, index, cursor, constrained(indexOrder, true), query);
assertTrue(cursor.next());
assertThat(cursor.propertyValue(0)).isEqualTo(expectedFirst);
assertTrue(cursor.next());
assertThat(cursor.propertyValue(0)).isEqualTo(stringValue(b));
assertTrue(cursor.next());
assertThat(cursor.propertyValue(0)).isEqualTo(expectedLast);
assertFalse(cursor.next());
}
}
}
use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.
the class FulltextIndexSettings method createAnalyzer.
static Analyzer createAnalyzer(IndexDescriptor descriptor, TokenNameLookup tokenNameLookup) {
TextValue analyzerName = descriptor.getIndexConfig().get(ANALYZER);
if (analyzerName == null) {
throw new RuntimeException("Index has no analyzer configured: " + descriptor.userDescription(tokenNameLookup));
}
Analyzer analyzer;
try {
AnalyzerProvider analyzerProvider = Services.loadOrFail(AnalyzerProvider.class, analyzerName.stringValue());
analyzer = analyzerProvider.createAnalyzer();
} catch (Exception e) {
throw new RuntimeException("Could not create fulltext analyzer: " + analyzerName, e);
}
Objects.requireNonNull(analyzer, "The '" + analyzerName + "' analyzer provider returned a null analyzer.");
return analyzer;
}
use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.
the class LuceneFulltextDocumentStructure method encodeValueField.
private static Field encodeValueField(String propertyKey, Value value) {
TextValue textValue = (TextValue) value;
String stringValue = textValue.stringValue();
return new TextField(propertyKey, stringValue, NO);
}
Aggregations