@Override public <V> IndexSlot selectSlot( V[] values, Function<V,ValueGroup> groupOf ) { if ( values.length > 1 ) { return LUCENE; } ValueGroup singleGroup = groupOf.apply( values[0] ); switch ( singleGroup.category() ) { case GEOMETRY: return SPATIAL; case TEMPORAL: return TEMPORAL; case UNKNOWN: return null; default: return LUCENE; } } }
void initValueAsHighest( ValueGroup valueGroup ) { clear(); type = valueGroup == ValueGroup.UNKNOWN ? HIGHEST_BY_VALUE_GROUP : Types.BY_GROUP[valueGroup.ordinal()]; type.initializeAsHighest( this ); }
@Test void copyShouldCopyExtremeValues() { // Given GenericKey extreme = newKeyState(); GenericKey copy = newKeyState(); for ( ValueGroup valueGroup : ValueGroup.values() ) { if ( valueGroup != ValueGroup.NO_VALUE ) { extreme.initValueAsLowest( valueGroup ); copy.copyFrom( extreme ); assertEquals( 0, extreme.compareValueTo( copy ), "states not equals after copy, valueGroup=" + valueGroup ); extreme.initValueAsHighest( valueGroup ); copy.copyFrom( extreme ); assertEquals( 0, extreme.compareValueTo( copy ), "states not equals after copy, valueGroup=" + valueGroup ); } } }
@Override public <V> IndexSlot selectSlot( V[] values, Function<V,ValueGroup> groupOf ) { if ( values.length > 1 ) { return LUCENE; } ValueGroup singleGroup = groupOf.apply( values[0] ); switch ( singleGroup.category() ) { case NUMBER: return NUMBER; case GEOMETRY: return SPATIAL; case TEMPORAL: return TEMPORAL; case UNKNOWN: return null; default: return LUCENE; } } }
void initValueAsLowest( ValueGroup valueGroup ) { clear(); type = valueGroup == ValueGroup.UNKNOWN ? LOWEST_BY_VALUE_GROUP : Types.BY_GROUP[valueGroup.ordinal()]; type.initializeAsLowest( this ); }
@Override public <V> IndexSlot selectSlot( V[] values, Function<V,ValueGroup> groupOf ) { if ( values.length > 1 ) { return LUCENE; } ValueGroup singleGroup = groupOf.apply( values[0] ); switch ( singleGroup.category() ) { case NUMBER: return NUMBER; case TEXT: return STRING; case GEOMETRY: return SPATIAL; case TEMPORAL: return TEMPORAL; case UNKNOWN: return null; default: return LUCENE; } } }
void initValueAsHighest( ValueGroup valueGroup ) { clear(); type = valueGroup == ValueGroup.UNKNOWN ? HIGHEST_BY_VALUE_GROUP : Types.BY_GROUP[valueGroup.ordinal()]; type.initializeAsHighest( this ); }
static void validateQuery( IndexCapability capability, IndexOrder indexOrder, IndexQuery[] predicates ) { if ( indexOrder != IndexOrder.NONE ) { ValueCategory valueCategory = predicates[0].valueGroup().category(); IndexOrder[] orderCapability = capability.orderCapability( valueCategory ); if ( !ArrayUtil.contains( orderCapability, indexOrder ) ) { orderCapability = ArrayUtils.add( orderCapability, IndexOrder.NONE ); throw new UnsupportedOperationException( format( "Tried to query index with unsupported order %s. Supported orders for query %s are %s.", indexOrder, Arrays.toString( predicates ), Arrays.toString( orderCapability ) ) ); } } } }
void initValueAsLowest( ValueGroup valueGroup ) { clear(); type = valueGroup == ValueGroup.UNKNOWN ? LOWEST_BY_VALUE_GROUP : Types.BY_GROUP[valueGroup.ordinal()]; type.initializeAsLowest( this ); }
public ValueCategory[] getValueCategories( IndexQuery[] predicates ) { return Arrays.stream( predicates ) .map( iq -> iq.valueGroup().category() ) .toArray( ValueCategory[]::new ); }
IndexOrder[] orderCapability( IndexQuery... predicates ) { ValueCategory[] categories = new ValueCategory[predicates.length]; for ( int i = 0; i < predicates.length; i++ ) { categories[i] = predicates[i].valueGroup().category(); } return indexProvider.getCapability( descriptor ).orderCapability( categories ); }
private static int worstCaseLength( AnyValue value ) { if ( value.isSequenceValue() ) { SequenceValue sequenceValue = (SequenceValue) value; if ( sequenceValue instanceof TextArray ) { TextArray textArray = (TextArray) sequenceValue; int length = 0; for ( int i = 0; i < textArray.length(); i++ ) { length += stringWorstCaseLength( textArray.stringValue( i ).length() ); } return length; } return sequenceValue.length() * BIGGEST_STATIC_SIZE; } else { switch ( ((Value) value).valueGroup().category() ) { case TEXT: // For text, which is very dynamic in its nature do a worst-case off of number of characters in it return stringWorstCaseLength( ((TextValue) value).length() ); default: // For all else then use the biggest possible value for a non-dynamic, non-array value a state can occupy return BIGGEST_STATIC_SIZE; } } }
ValueGroup valueGroup = value.valueGroup(); IndexValueCapability valueCapability = indexCapability().valueCapability( valueGroup.category() ); if ( !valueCapability.equals( IndexValueCapability.YES ) )
IndexQuery.RangePredicate<?> supportedQuery = IndexQuery.range( 0, valueGroup ); IndexOrder[] supportedOrders = indexCapability().orderCapability( valueGroup.category() ); for ( IndexOrder supportedOrder : supportedOrders )
IndexOrder[] indexOrders = indexProvider.getCapability( descriptor ).orderCapability( predicate.valueGroup().category() ); for ( IndexOrder order : indexOrders )
IndexOrder[] order = index.orderCapability( type.valueGroup.category() ); for ( IndexOrder indexOrder : order )
@Test public void shouldPerformBooleanSearch() throws KernelException { // given boolean needsValues = indexProvidesBooleanValues(); int label = token.nodeLabel( "Node" ); int prop = token.propertyKey( "prop" ); IndexReference index = schemaRead.index( label, prop ); IndexValueCapability capability = index.valueCapability( ValueGroup.BOOLEAN.category() ); try ( NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor() ) { MutableLongSet uniqueIds = new LongHashSet(); // when read.nodeIndexSeek( index, node, IndexOrder.NONE, needsValues, IndexQuery.exact( prop, false ) ); // then assertFoundNodesAndValue( node, 1, uniqueIds, capability, needsValues ); // when read.nodeIndexSeek( index, node, IndexOrder.NONE, needsValues, IndexQuery.exact( prop, true ) ); // then assertFoundNodesAndValue( node, 1, uniqueIds, capability, needsValues ); } }
@Test public void shouldPerformTextArraySearch() throws KernelException { // given boolean needsValues = indexProvidesArrayValues(); int label = token.nodeLabel( "Node" ); int prop = token.propertyKey( "prop" ); IndexReference index = schemaRead.index( label, prop ); IndexValueCapability capability = index.valueCapability( ValueGroup.TEXT_ARRAY.category() ); try ( NodeValueIndexCursor node = cursors.allocateNodeValueIndexCursor() ) { MutableLongSet uniqueIds = new LongHashSet(); // when read.nodeIndexSeek( index, node, IndexOrder.NONE, needsValues, IndexQuery.exact( prop, new String[]{"first", "second", "third"} ) ); // then assertFoundNodesAndValue( node, 1, uniqueIds, capability, needsValues ); // when read.nodeIndexSeek( index, node, IndexOrder.NONE, needsValues, IndexQuery.exact( prop, new String[]{"fourth", "fifth", "sixth", "seventh"} ) ); // then assertFoundNodesAndValue( node, 1, uniqueIds, capability, needsValues ); } }
@Override public <V> IndexSlot selectSlot( V[] values, Function<V,ValueGroup> groupOf ) { if ( values.length > 1 ) { return LUCENE; } ValueGroup singleGroup = groupOf.apply( values[0] ); switch ( singleGroup.category() ) { case GEOMETRY: return SPATIAL; case TEMPORAL: return TEMPORAL; case UNKNOWN: return null; default: return LUCENE; } } }
@Override public <V> IndexSlot selectSlot( V[] values, Function<V,ValueGroup> groupOf ) { if ( values.length > 1 ) { return LUCENE; } ValueGroup singleGroup = groupOf.apply( values[0] ); switch ( singleGroup.category() ) { case NUMBER: return NUMBER; case TEXT: return STRING; case GEOMETRY: return SPATIAL; case TEMPORAL: return TEMPORAL; case UNKNOWN: return null; default: return LUCENE; } } }