Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions solr/core/src/java/org/apache/solr/schema/BoolField.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.document.SortedDocValuesField;
import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.LeafReaderContext;
Expand Down Expand Up @@ -189,9 +187,13 @@ public List<IndexableField> createFields(SchemaField field, Object value) {
IndexableField docval;
final BytesRef bytes = new BytesRef(toInternal(value.toString()));
if (field.multiValued()) {
docval = new SortedSetDocValuesField(field.getName(), bytes);
docval =
DocValuesFieldUtil.createSortedSetDocValuesField(
field.getName(), bytes, field.hasDocValuesSkipList());
} else {
docval = new SortedDocValuesField(field.getName(), bytes);
docval =
DocValuesFieldUtil.createSortedDocValuesField(
field.getName(), bytes, field.hasDocValuesSkipList());
}

// Only create a list of we have 2 values...
Expand Down
9 changes: 6 additions & 3 deletions solr/core/src/java/org/apache/solr/schema/CollationField.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute;
import org.apache.lucene.collation.CollationKeyAnalyzer;
import org.apache.lucene.document.SortedDocValuesField;
import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.search.Query;
Expand Down Expand Up @@ -253,9 +252,13 @@ public List<IndexableField> createFields(SchemaField field, Object value) {
fields.add(createField(field, value));
final BytesRef bytes = getCollationKey(field.getName(), value.toString());
if (field.multiValued()) {
fields.add(new SortedSetDocValuesField(field.getName(), bytes));
fields.add(
DocValuesFieldUtil.createSortedSetDocValuesField(
field.getName(), bytes, field.hasDocValuesSkipList()));
} else {
fields.add(new SortedDocValuesField(field.getName(), bytes));
fields.add(
DocValuesFieldUtil.createSortedDocValuesField(
field.getName(), bytes, field.hasDocValuesSkipList()));
}
return fields;
} else {
Expand Down
99 changes: 99 additions & 0 deletions solr/core/src/java/org/apache/solr/schema/DocValuesFieldUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.schema;

import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.SortedDocValuesField;
import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.util.BytesRef;

/**
* Utility class for creating DocValues {@link IndexableField} instances with optional skip index
* support.
*
* <p>When {@code hasDocValuesSkipList} is true, this utility creates indexed DocValues fields that
* include a range skip index for more efficient range queries. Otherwise, it creates standard
* DocValues fields.
*/
public final class DocValuesFieldUtil {

private DocValuesFieldUtil() {
// utility class
}

/**
* Creates a sorted DocValues field for a single-value (non-multi-valued) string/bytes field.
*
* @param fieldName the field name
* @param value the bytes value
* @param hasDocValuesSkipList whether to include a range skip index
* @return the created IndexableField
*/
public static IndexableField createSortedDocValuesField(
String fieldName, BytesRef value, boolean hasDocValuesSkipList) {
return hasDocValuesSkipList
? SortedDocValuesField.indexedField(fieldName, value)
: new SortedDocValuesField(fieldName, value);
}

/**
* Creates a sorted set DocValues field for a multi-valued string/bytes field.
*
* @param fieldName the field name
* @param value the bytes value
* @param hasDocValuesSkipList whether to include a range skip index
* @return the created IndexableField
*/
public static IndexableField createSortedSetDocValuesField(
String fieldName, BytesRef value, boolean hasDocValuesSkipList) {
return hasDocValuesSkipList
? SortedSetDocValuesField.indexedField(fieldName, value)
: new SortedSetDocValuesField(fieldName, value);
}

/**
* Creates a numeric DocValues field for a single-value numeric field.
*
* @param fieldName the field name
* @param value the long value
* @param hasDocValuesSkipList whether to include a range skip index
* @return the created IndexableField
*/
public static IndexableField createNumericDocValuesField(
String fieldName, long value, boolean hasDocValuesSkipList) {
return hasDocValuesSkipList
? NumericDocValuesField.indexedField(fieldName, value)
: new NumericDocValuesField(fieldName, value);
}

/**
* Creates a sorted numeric DocValues field for a multi-valued numeric field.
*
* @param fieldName the field name
* @param value the long value
* @param hasDocValuesSkipList whether to include a range skip index
* @return the created IndexableField
*/
public static IndexableField createSortedNumericDocValuesField(
String fieldName, long value, boolean hasDocValuesSkipList) {
return hasDocValuesSkipList
? SortedNumericDocValuesField.indexedField(fieldName, value)
: new SortedNumericDocValuesField(fieldName, value);
}
}
8 changes: 6 additions & 2 deletions solr/core/src/java/org/apache/solr/schema/EnumFieldType.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,13 @@ public List<IndexableField> createFields(SchemaField sf, Object value) {
fields.add(field);
final long longValue = field.numericValue().longValue();
if (sf.multiValued()) {
fields.add(new SortedNumericDocValuesField(sf.getName(), longValue));
fields.add(
DocValuesFieldUtil.createSortedNumericDocValuesField(
sf.getName(), longValue, sf.hasDocValuesSkipList()));
} else {
fields.add(new NumericDocValuesField(sf.getName(), longValue));
fields.add(
DocValuesFieldUtil.createNumericDocValuesField(
sf.getName(), longValue, sf.hasDocValuesSkipList()));
}
return fields;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public abstract class FieldProperties {
protected static final int USE_DOCVALUES_AS_STORED = 0b100000000000000000;
protected static final int LARGE_FIELD = 0b1000000000000000000;
protected static final int UNINVERTIBLE = 0b10000000000000000000;
protected static final int DOC_VALUES_SKIP_LIST = 0b100000000000000000000;

static final String[] propertyNames = {
"indexed",
Expand All @@ -73,7 +74,8 @@ public abstract class FieldProperties {
"termPayloads",
"useDocValuesAsStored",
"large",
"uninvertible"
"uninvertible",
"docValuesSkipList"
};

static final Map<String, Integer> propertyMap = new HashMap<>();
Expand Down
10 changes: 6 additions & 4 deletions solr/core/src/java/org/apache/solr/schema/PointField.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.document.StoredField;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.queries.function.ValueSource;
Expand Down Expand Up @@ -292,7 +290,9 @@ public List<IndexableField> createFields(SchemaField sf, Object value) {
assert numericValue instanceof Double;
bits = Double.doubleToLongBits(numericValue.doubleValue());
}
fields.add(new NumericDocValuesField(sf.getName(), bits));
fields.add(
DocValuesFieldUtil.createNumericDocValuesField(
sf.getName(), bits, sf.hasDocValuesSkipList()));
} else {
// MultiValued
if (numericValue instanceof Integer || numericValue instanceof Long) {
Expand All @@ -303,7 +303,9 @@ public List<IndexableField> createFields(SchemaField sf, Object value) {
assert numericValue instanceof Double;
bits = NumericUtils.doubleToSortableLong(numericValue.doubleValue());
}
fields.add(new SortedNumericDocValuesField(sf.getName(), bits));
fields.add(
DocValuesFieldUtil.createSortedNumericDocValuesField(
sf.getName(), bits, sf.hasDocValuesSkipList()));
}
}
if (sf.stored()) {
Expand Down
22 changes: 22 additions & 0 deletions solr/core/src/java/org/apache/solr/schema/SchemaField.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public boolean hasDocValues() {
return (properties & DOC_VALUES) != 0;
}

public boolean hasDocValuesSkipList() {
return (properties & DOC_VALUES_SKIP_LIST) != 0;
}

public boolean storeTermVector() {
return (properties & STORE_TERMVECTORS) != 0;
}
Expand Down Expand Up @@ -373,6 +377,18 @@ static int calcProps(String name, FieldType ft, Map<String, ?> props) {
p &= ~pp;
}

if (on(falseProps, DOC_VALUES)) {
int pp = DOC_VALUES_SKIP_LIST;
if (on(DOC_VALUES_SKIP_LIST, trueProps)) {
throw new RuntimeException(
"SchemaField: "
+ name
+ " conflicting 'true' field options for non-docValues field:"
+ props);
}
p &= ~pp;
}

if (on(falseProps, INDEXED)) {
int pp = (OMIT_NORMS | OMIT_TF_POSITIONS | OMIT_POSITIONS);
if (on(pp, falseProps)) {
Expand Down Expand Up @@ -466,6 +482,7 @@ public SimpleOrderedMap<Object> getNamedPropertyValues(boolean showDefaults) {
properties.add(getPropertyName(REQUIRED), isRequired());
properties.add(getPropertyName(TOKENIZED), isTokenized());
properties.add(getPropertyName(USE_DOCVALUES_AS_STORED), useDocValuesAsStored());
properties.add(getPropertyName(DOC_VALUES_SKIP_LIST), hasDocValuesSkipList());
// The BINARY property is always false
// properties.add(getPropertyName(BINARY), isBinary());
} else {
Expand Down Expand Up @@ -532,6 +549,11 @@ public DocValuesType docValuesType() {
return DocValuesType.NONE;
}

/**
* For fields with docValues the underlaying lucene field is created without passing these values
* as is. Instead the creating class should check on {@link #hasDocValuesSkipList()} and create
* the appropriate field type.
*/
@Override
public DocValuesSkipIndexType docValuesSkipIndexType() {
return DocValuesSkipIndexType.NONE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.lucene.document.SortedDocValuesField;
import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.queries.function.valuesource.SortedSetFieldSource;
Expand Down Expand Up @@ -133,8 +131,10 @@ private static List<IndexableField> getIndexableFields(
SchemaField field, IndexableField f, BytesRef bytes) {
final IndexableField docval =
field.multiValued()
? new SortedSetDocValuesField(field.getName(), bytes)
: new SortedDocValuesField(field.getName(), bytes);
? DocValuesFieldUtil.createSortedSetDocValuesField(
field.getName(), bytes, field.hasDocValuesSkipList())
: DocValuesFieldUtil.createSortedDocValuesField(
field.getName(), bytes, field.hasDocValuesSkipList());

if (null == f) {
return List.of(docval);
Expand Down
10 changes: 6 additions & 4 deletions solr/core/src/java/org/apache/solr/schema/StrField.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.lucene.document.SortedDocValuesField;
import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.queries.function.valuesource.SortedSetFieldSource;
Expand Down Expand Up @@ -49,9 +47,13 @@ public List<IndexableField> createFields(SchemaField field, Object value) {
IndexableField docval;
final BytesRef bytes = getBytesRef(value);
if (field.multiValued()) {
docval = new SortedSetDocValuesField(field.getName(), bytes);
docval =
DocValuesFieldUtil.createSortedSetDocValuesField(
field.getName(), bytes, field.hasDocValuesSkipList());
} else {
docval = new SortedDocValuesField(field.getName(), bytes);
docval =
DocValuesFieldUtil.createSortedDocValuesField(
field.getName(), bytes, field.hasDocValuesSkipList());
}

// Only create a list of we have 2 values...
Expand Down
10 changes: 6 additions & 4 deletions solr/core/src/java/org/apache/solr/schema/TrieField.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import java.util.Locale;
import java.util.Map;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.index.DocValuesType;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.LeafReaderContext;
Expand Down Expand Up @@ -673,7 +671,9 @@ public List<IndexableField> createFields(SchemaField sf, Object value) {
if (sf.multiValued()) {
BytesRefBuilder bytes = new BytesRefBuilder();
storedToIndexed(field, bytes);
fields.add(new SortedSetDocValuesField(sf.getName(), bytes.get()));
fields.add(
DocValuesFieldUtil.createSortedSetDocValuesField(
sf.getName(), bytes.get(), sf.hasDocValuesSkipList()));
} else {
final long bits;
if (field.numericValue() instanceof Integer || field.numericValue() instanceof Long) {
Expand All @@ -684,7 +684,9 @@ public List<IndexableField> createFields(SchemaField sf, Object value) {
assert field.numericValue() instanceof Double;
bits = Double.doubleToLongBits(field.numericValue().doubleValue());
}
fields.add(new NumericDocValuesField(sf.getName(), bits));
fields.add(
DocValuesFieldUtil.createNumericDocValuesField(
sf.getName(), bits, sf.hasDocValuesSkipList()));
}

return fields;
Expand Down
Loading