Search in sources :

Example 6 with TextValue

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));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TextValue(org.neo4j.values.storable.TextValue) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Pair(org.neo4j.internal.helpers.collection.Pair) HashSet(java.util.HashSet) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with TextValue

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);
    }
}
Also used : TextValue(org.neo4j.values.storable.TextValue)

Example 8 with TextValue

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());
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) TextValue(org.neo4j.values.storable.TextValue) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with TextValue

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;
}
Also used : AnalyzerProvider(org.neo4j.graphdb.schema.AnalyzerProvider) TextValue(org.neo4j.values.storable.TextValue) Analyzer(org.apache.lucene.analysis.Analyzer)

Example 10 with TextValue

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);
}
Also used : TextValue(org.neo4j.values.storable.TextValue) TextField(org.apache.lucene.document.TextField)

Aggregations

TextValue (org.neo4j.values.storable.TextValue)29 Test (org.junit.jupiter.api.Test)12 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)7 AnyValue (org.neo4j.values.AnyValue)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 BooleanValue (org.neo4j.values.storable.BooleanValue)6 Config (org.neo4j.configuration.Config)5 Value (org.neo4j.values.storable.Value)5 Arrays (java.util.Arrays)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 ArrayUtils.toArray (org.apache.commons.lang3.ArrayUtils.toArray)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Matchers.contains (org.hamcrest.Matchers.contains)4 Assertions.assertArrayEquals (org.junit.jupiter.api.Assertions.assertArrayEquals)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)4 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)4 Public (org.neo4j.annotations.Public)4 CapabilitiesRegistry (org.neo4j.capabilities.CapabilitiesRegistry)4