Package org.xwiki.search.solr
Interface SolrUtils
-
@Role public interface SolrUtils
Various helpers around the Solr API.- Since:
- 12.3RC1
- Version:
- $Id: f206192cfc90f0d7a7ec3ec8e234342790b0ab13 $
-
-
Field Summary
Fields Modifier and Type Field Description static String
ATOMIC_UPDATE_MODIFIER_ADD
Adds the specified values to a multiValued field.static String
ATOMIC_UPDATE_MODIFIER_ADD_DISTINCT
Adds the specified values to a multiValued field, only if not already present.static String
ATOMIC_UPDATE_MODIFIER_INC
Increments a numeric value by a specific amount.static String
ATOMIC_UPDATE_MODIFIER_REMOVE
Removes (all occurrences of) the specified values from a multiValued field.static String
ATOMIC_UPDATE_MODIFIER_REMOVEREGEX
Removes all occurrences of the specified regex from a multiValued field.static String
ATOMIC_UPDATE_MODIFIER_SET
Set or replace the field value(s) with the specified value(s), or remove the values if 'null' or empty list is specified as the new value.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description <T> T
get(String fieldName, org.apache.solr.common.SolrDocument document)
Extract from the document the value associated with the passed field name.<T> T
get(String fieldName, org.apache.solr.common.SolrDocument document, Type targetType)
Extract from the document the value associated with the passed field name.<T> T
get(String fieldName, org.apache.solr.common.SolrDocument document, T def)
Extract from the document the value associated with the passed field name.<T> Collection<T>
getCollection(String fieldName, org.apache.solr.common.SolrDocument document)
Extract from the document the values associated with the passed field name.default <T> Collection<T>
getCollection(String fieldName, org.apache.solr.common.SolrDocument document, Type targetType)
Extract from the document the values associated with the passed field name.String
getId(org.apache.solr.common.SolrDocument document)
Extract the identifier of the document.<T> List<T>
getList(String fieldName, org.apache.solr.common.SolrDocument document)
Extract from the document the values associated with the passed field name.<V> Map<String,V>
getMap(String fieldName, org.apache.solr.common.SolrDocument document)
Extract aMap<String, Object>
from the passedSolrDocument
.default String
getMapFieldName(String key, String mapFieldName, Type type)
<T> Set<T>
getSet(String fieldName, org.apache.solr.common.SolrDocument document)
Extract from the document the values associated with the passed field name.void
set(String fieldName, Object fieldValue, org.apache.solr.common.SolrInputDocument document)
Store in the document the value associated with the passed field name.void
set(String fieldName, Collection<?> fieldValue, org.apache.solr.common.SolrInputDocument document)
Store in the document the values associated with the passed field name.default void
setAtomic(String modifier, String fieldName, Object fieldValue, Type valueType, org.apache.solr.common.SolrInputDocument document)
Store in the document the value associated with the passed field name.void
setAtomic(String modifier, String fieldName, Object fieldValue, org.apache.solr.common.SolrInputDocument document)
Store in the document the value associated with the passed field name.void
setId(Object fieldValue, org.apache.solr.common.SolrInputDocument document)
Set the identifier of the document.void
setMap(String fieldName, Map<String,?> fieldValue, org.apache.solr.common.SolrInputDocument document)
Set aMap<String, Object>
in the passedSolrDocument
.void
setString(String fieldName, Object fieldValue, Type valueType, org.apache.solr.common.SolrInputDocument document)
Store in the document the value associated with the passed field name.void
setString(String fieldName, Object fieldValue, org.apache.solr.common.SolrInputDocument document)
Store in the document the value associated with the passed field name.default void
setString(String fieldName, Collection<?> fieldValue, Type valueType, org.apache.solr.common.SolrInputDocument document)
default String
toCompleteFilterQueryString(Object fieldValue)
Serialize the value into a string that is a complete query string, i.e., cannot be combined with other strings.default String
toCompleteFilterQueryString(Object fieldValue, Type valueType)
Serialize the value into a string that is a complete query string, i.e., cannot be combined with other strings.String
toFilterQueryString(Object fieldValue)
Serialize the value into a value usable in a Solr filter query.default String
toFilterQueryString(Object fieldValue, Type valueType)
Serialize the value into a value usable in a Solr filter query.
-
-
-
Field Detail
-
ATOMIC_UPDATE_MODIFIER_SET
static final String ATOMIC_UPDATE_MODIFIER_SET
Set or replace the field value(s) with the specified value(s), or remove the values if 'null' or empty list is specified as the new value. May be specified as a single value, or as a list for multiValued fields.- Since:
- 12.5RC1
- See Also:
- Constant Field Values
-
ATOMIC_UPDATE_MODIFIER_ADD
static final String ATOMIC_UPDATE_MODIFIER_ADD
Adds the specified values to a multiValued field. May be specified as a single value, or as a list.- Since:
- 12.5RC1
- See Also:
- Constant Field Values
-
ATOMIC_UPDATE_MODIFIER_ADD_DISTINCT
static final String ATOMIC_UPDATE_MODIFIER_ADD_DISTINCT
Adds the specified values to a multiValued field, only if not already present. May be specified as a single value, or as a list.- Since:
- 12.5RC1
- See Also:
- Constant Field Values
-
ATOMIC_UPDATE_MODIFIER_REMOVE
static final String ATOMIC_UPDATE_MODIFIER_REMOVE
Removes (all occurrences of) the specified values from a multiValued field. May be specified as a single value, or as a list.- Since:
- 12.5RC1
- See Also:
- Constant Field Values
-
ATOMIC_UPDATE_MODIFIER_REMOVEREGEX
static final String ATOMIC_UPDATE_MODIFIER_REMOVEREGEX
Removes all occurrences of the specified regex from a multiValued field. May be specified as a single value, or as a list.- Since:
- 12.5RC1
- See Also:
- Constant Field Values
-
ATOMIC_UPDATE_MODIFIER_INC
static final String ATOMIC_UPDATE_MODIFIER_INC
Increments a numeric value by a specific amount. Must be specified as a single numeric value.- Since:
- 12.5RC1
- See Also:
- Constant Field Values
-
-
Method Detail
-
getMap
<V> Map<String,V> getMap(String fieldName, org.apache.solr.common.SolrDocument document)
Extract aMap<String, Object>
from the passedSolrDocument
.Solr
DocumentObjectBinder
has native support for maps, unfortunately it only support maps for which all entries have the same type (and only String and primitive types). The point of this API is to provide binding for a generic Map of objects.This API imply that it exist in the schema dynamic fields of the form
<mapname>_*_string
(and<mapname>_*_boolean
,<mapname>_*_pint
, etc.). Can be done usingAbstractSolrCoreInitializer.addMapField(String)
.- Type Parameters:
V
- the type of the value in the map- Parameters:
fieldName
- the prefix of the fields containing the map datadocument
- the Solr document- Returns:
- the Map extracted from the Solr document
- See Also:
setMap(String, Map, SolrInputDocument)
-
setMap
void setMap(String fieldName, Map<String,?> fieldValue, org.apache.solr.common.SolrInputDocument document)
Set aMap<String, Object>
in the passedSolrDocument
.- Parameters:
fieldName
- the prefix of the fields containing the map datafieldValue
- the map to store in theSolrDocument
document
- the Solr document- See Also:
getMap(String, SolrDocument)
-
getMapFieldName
default String getMapFieldName(String key, String mapFieldName, Type type)
- Parameters:
key
- the key in the mapmapFieldName
- the name of the virtual map fieldtype
- the type of the value- Returns:
- the name of the Solr field
- Since:
- 13.9RC1
-
getId
String getId(org.apache.solr.common.SolrDocument document)
Extract the identifier of the document.- Parameters:
document
- the Solr document- Returns:
- the value associated with the passed field name in the document
-
get
<T> T get(String fieldName, org.apache.solr.common.SolrDocument document)
Extract from the document the value associated with the passed field name.- Type Parameters:
T
- the of the value to return- Parameters:
fieldName
- the name of the field in the documentdocument
- the Solr document- Returns:
- the value associated with the passed field name in the document
-
setId
void setId(Object fieldValue, org.apache.solr.common.SolrInputDocument document)
Set the identifier of the document.- Parameters:
fieldValue
- the id value to store in theSolrDocument
document
- the Solr document
-
set
void set(String fieldName, Object fieldValue, org.apache.solr.common.SolrInputDocument document)
Store in the document the value associated with the passed field name.- Parameters:
fieldName
- the name of the field in the documentfieldValue
- the value to store in theSolrDocument
document
- the Solr document
-
setAtomic
void setAtomic(String modifier, String fieldName, Object fieldValue, org.apache.solr.common.SolrInputDocument document)
Store in the document the value associated with the passed field name.- Parameters:
modifier
- the atomic update modifier to apply (set, add, add-distinct, remove, removeregex, inc)fieldName
- the name of the field in the documentfieldValue
- the value to store in theSolrDocument
document
- the Solr document- Since:
- 12.5RC1
-
setAtomic
default void setAtomic(String modifier, String fieldName, Object fieldValue, Type valueType, org.apache.solr.common.SolrInputDocument document)
Store in the document the value associated with the passed field name.- Parameters:
modifier
- the atomic update modifier to apply (set, add, add-distinct, remove, removeregex, inc)fieldName
- the name of the field in the documentfieldValue
- the value to store in theSolrDocument
valueType
- the type to use as reference to serialize the valuedocument
- the Solr document- Since:
- 12.10
-
set
void set(String fieldName, Collection<?> fieldValue, org.apache.solr.common.SolrInputDocument document)
Store in the document the values associated with the passed field name.The field is expected to be multivalued.
- Parameters:
fieldName
- the name of the field in the documentfieldValue
- the value to store in theSolrDocument
document
- the Solr document
-
setString
void setString(String fieldName, Object fieldValue, org.apache.solr.common.SolrInputDocument document)
Store in the document the value associated with the passed field name.If the value is not of type
String
it's converted automatically.- Parameters:
fieldName
- the name of the field in the documentfieldValue
- the value to store in theSolrDocument
document
- the Solr document
-
setString
void setString(String fieldName, Object fieldValue, Type valueType, org.apache.solr.common.SolrInputDocument document)
Store in the document the value associated with the passed field name.If the value is not of type
String
it's converted automatically.- Parameters:
fieldName
- the name of the field in the documentfieldValue
- the value to store in theSolrDocument
valueType
- the type to use as reference to serialize the valuedocument
- the Solr document- Since:
- 12.6
-
setString
default void setString(String fieldName, Collection<?> fieldValue, Type valueType, org.apache.solr.common.SolrInputDocument document)
- Parameters:
fieldName
- the name of the field in the documentfieldValue
- the value to store in theSolrDocument
valueType
- the type to use as reference to serialize the valuesdocument
- the Solr document- Since:
- 12.9RC1
-
toFilterQueryString
String toFilterQueryString(Object fieldValue)
Serialize the value into a value usable in a Solr filter query.- Parameters:
fieldValue
- the value of a field- Returns:
- the Solr query version of the passed value
-
toFilterQueryString
default String toFilterQueryString(Object fieldValue, Type valueType)
Serialize the value into a value usable in a Solr filter query.- Parameters:
fieldValue
- the value of a fieldvalueType
- the type to use as reference to serialize the value- Returns:
- the Solr query version of the passed value
- Since:
- 12.9RC1
-
toCompleteFilterQueryString
@Unstable default String toCompleteFilterQueryString(Object fieldValue)
Serialize the value into a string that is a complete query string, i.e., cannot be combined with other strings.For example, this serializes the empty string as "".
- Parameters:
fieldValue
- the value of a field- Returns:
- the Solr query version of the passed value
- Since:
- 13.10.7, 14.4.2, 14.5
-
toCompleteFilterQueryString
@Unstable default String toCompleteFilterQueryString(Object fieldValue, Type valueType)
Serialize the value into a string that is a complete query string, i.e., cannot be combined with other strings.For example, this serializes the empty string as "".
- Parameters:
fieldValue
- the value of a fieldvalueType
- the type to use as reference to serialize the value- Returns:
- the Solr query version of the passed value
- Since:
- 13.10.7, 14.4.2, 14.5
-
get
<T> T get(String fieldName, org.apache.solr.common.SolrDocument document, Type targetType)
Extract from the document the value associated with the passed field name.- Type Parameters:
T
- the of the value to return- Parameters:
fieldName
- the name of the field in the documentdocument
- the Solr documenttargetType
- the type of the value to return- Returns:
- the value associated with the passed field name in the document
-
get
<T> T get(String fieldName, org.apache.solr.common.SolrDocument document, T def)
Extract from the document the value associated with the passed field name.- Type Parameters:
T
- the of the value to return- Parameters:
fieldName
- the name of the field in the documentdocument
- the Solr documentdef
- the default value if none is available- Returns:
- the value associated with the passed field name in the document
- Since:
- 12.6
-
getCollection
default <T> Collection<T> getCollection(String fieldName, org.apache.solr.common.SolrDocument document, Type targetType)
Extract from the document the values associated with the passed field name.- Type Parameters:
T
- the of the value to return- Parameters:
fieldName
- the name of the field in the documentdocument
- the Solr documenttargetType
- the type of the value to return- Returns:
- the value associated with the passed field name in the document
- Since:
- 12.9RC1
-
getCollection
<T> Collection<T> getCollection(String fieldName, org.apache.solr.common.SolrDocument document)
Extract from the document the values associated with the passed field name.- Type Parameters:
T
- the of the value to return- Parameters:
fieldName
- the name of the field in the documentdocument
- the Solr document- Returns:
- the value associated with the passed field name in the document
-
getSet
<T> Set<T> getSet(String fieldName, org.apache.solr.common.SolrDocument document)
Extract from the document the values associated with the passed field name.- Type Parameters:
T
- the of the value to return- Parameters:
fieldName
- the name of the field in the documentdocument
- the Solr document- Returns:
- the value associated with the passed field name in the document
-
getList
<T> List<T> getList(String fieldName, org.apache.solr.common.SolrDocument document)
Extract from the document the values associated with the passed field name.- Type Parameters:
T
- the of the value to return- Parameters:
fieldName
- the name of the field in the documentdocument
- the Solr document- Returns:
- the value associated with the passed field name in the document
-
-