Class Extensions
- java.lang.Object
-
- org.apache.lucene.queryparser.ext.Extensions
-
public class Extensions extends Object
TheExtensions
class represents an extension mapping to associateParserExtension
instances with extension keys. An extension key is a string encoded into a Lucene standard query parser field symbol recognized byExtendableQueryParser
. The query parser passes each extension field token tosplitExtensionField(String, String)
to separate the extension key from the field identifier.In addition to the key to extension mapping this class also defines the field name overloading scheme.
ExtendableQueryParser
uses the given extension to split the actual field name and extension key by callingsplitExtensionField(String, String)
. To change the order or the key / field name encoding scheme users can subclassExtensions
to implement their own.- See Also:
ExtendableQueryParser
,ParserExtension
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Extensions.Pair<Cur,Cud>
This class represents a generic pair.
-
Field Summary
Fields Modifier and Type Field Description static char
DEFAULT_EXTENSION_FIELD_DELIMITER
The default extension field delimiter character.
-
Constructor Summary
Constructors Constructor Description Extensions()
Creates a newExtensions
instance with theDEFAULT_EXTENSION_FIELD_DELIMITER
as a delimiter character.Extensions(char extensionFieldDelimiter)
Creates a newExtensions
instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(String key, ParserExtension extension)
Adds a newParserExtension
instance associated with the given key.String
buildExtensionField(String extensionKey)
Builds an extension field string from a given extension key and the default query field.String
buildExtensionField(String extensionKey, String field)
Builds an extension field string from a given extension key and the extensions field.String
escapeExtensionField(String extfield)
Escapes an extension field.ParserExtension
getExtension(String key)
Returns theParserExtension
instance for the given key ornull
if no extension can be found for the key.char
getExtensionFieldDelimiter()
Returns the extension field delimiterExtensions.Pair<String,String>
splitExtensionField(String defaultField, String field)
Splits a extension field and returns the field / extension part as aExtensions.Pair
.
-
-
-
Field Detail
-
DEFAULT_EXTENSION_FIELD_DELIMITER
public static final char DEFAULT_EXTENSION_FIELD_DELIMITER
The default extension field delimiter character. This constant is set to ':'- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Extensions
public Extensions()
Creates a newExtensions
instance with theDEFAULT_EXTENSION_FIELD_DELIMITER
as a delimiter character.
-
Extensions
public Extensions(char extensionFieldDelimiter)
Creates a newExtensions
instance- Parameters:
extensionFieldDelimiter
- the extensions field delimiter character
-
-
Method Detail
-
add
public void add(String key, ParserExtension extension)
Adds a newParserExtension
instance associated with the given key.- Parameters:
key
- the parser extension keyextension
- the parser extension
-
getExtension
public final ParserExtension getExtension(String key)
Returns theParserExtension
instance for the given key ornull
if no extension can be found for the key.- Parameters:
key
- the extension key- Returns:
- the
ParserExtension
instance for the given key ornull
if no extension can be found for the key.
-
getExtensionFieldDelimiter
public char getExtensionFieldDelimiter()
Returns the extension field delimiter- Returns:
- the extension field delimiter
-
splitExtensionField
public Extensions.Pair<String,String> splitExtensionField(String defaultField, String field)
Splits a extension field and returns the field / extension part as aExtensions.Pair
. This method tries to split on the first occurrence of the extension field delimiter, if the delimiter is not present in the string the result will contain anull
value for the extension key and the given field string as the field value. If the given extension field string contains no field identifier the result pair will carry the given default field as the field value.- Parameters:
defaultField
- the default query fieldfield
- the extension field string- Returns:
- a
Extensions.Pair
with the field name as theExtensions.Pair.cur
and the extension key as theExtensions.Pair.cud
-
escapeExtensionField
public String escapeExtensionField(String extfield)
Escapes an extension field. The default implementation is equivalent toQueryParserBase.escape(String)
.- Parameters:
extfield
- the extension field identifier- Returns:
- the extension field identifier with all special chars escaped with a backslash character.
-
buildExtensionField
public String buildExtensionField(String extensionKey)
Builds an extension field string from a given extension key and the default query field. The default field and the key are delimited with the extension field delimiter character. This method makes no assumption about the order of the extension key and the field. By default the extension key is appended to the end of the returned string while the field is added to the beginning. Special Query characters are escaped in the result.Note:
Extensions
subclasses must maintain the contract betweenbuildExtensionField(String)
andsplitExtensionField(String, String)
where the latter inverts the former.
-
buildExtensionField
public String buildExtensionField(String extensionKey, String field)
Builds an extension field string from a given extension key and the extensions field. The field and the key are delimited with the extension field delimiter character. This method makes no assumption about the order of the extension key and the field. By default the extension key is appended to the end of the returned string while the field is added to the beginning. Special Query characters are escaped in the result.Note:
Extensions
subclasses must maintain the contract betweenbuildExtensionField(String, String)
andsplitExtensionField(String, String)
where the latter inverts the former.- Parameters:
extensionKey
- the extension keyfield
- the field to apply the extension on.- Returns:
- escaped extension field identifier
- See Also:
to use the default query field
-
-