Package org.dlese.dpc.index
Class VirtualSearchFieldMapper
java.lang.Object
org.dlese.dpc.index.VirtualSearchFieldMapper
Maps virtual search field/term pairs to Lucene Queries. For example, the field/term pair cats:cougar might
be mapped to the Lucene Query (cougar OR puma OR "mountain lion"). To define the mappings, the API can be
given one or more XML files that contain <virtualSearchField> elements that contain XML queries
parsed by the
XMLQueryParser class. See sample XML file . Mappings
can also be added or removed directly using the API. The API returns Queries for the given field/term
pairs, and a FieldExpansionQueryParser may be used to apply the
field/term mappings when supplied in regular Lucene query strings.- Author:
- John Weatherley
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionVirtualSearchFieldMapper(org.apache.lucene.queryParser.QueryParser parser) Constructor for the VirtualSearchFieldMapper object -
Method Summary
Modifier and TypeMethodDescriptionvoidaddVirtualFieldConfiguration(File xmlConfigFile) Adds all virtual field/term query definitions (virtualSearchField elements) contained in the given XML configuration file, replacing any previous definitions.voidaddVirtualFieldConfiguration(String xmlConfig) Adds all virtual field/term query definitions (virtualSearchField elements) contained in the given XML configuration String, replacing any previous definitions.voidaddVirtualFieldConfiguration(URL xmlConfig) Adds all virtual field/term query definitions (virtualSearchField elements) contained in the given XML configuration file, replacing any previous definitions.voidclear()Clears all field/term definitions that are defined.booleangetIsTermConfiguredForField(String virtualField, String virtualTerm) Determines whether the given virtual term is configured for the given field.intgetNumTermsConfiguredForField(String virtualField) Gets the number of virtual terms configured for a given virtual field.org.apache.lucene.search.QueryGets the Lucene Query that is defined for the given virtual field/term pair, or null if none avaialable.getQueryString(String virtualField, String virtualTerm) Gets the Lucene Query as a String for the given virtual field and term, or null if not avaialable.String[]Gets the virtual fields that are defined.String[]getVirtualTerms(String field) Gets the virtual terms that are defined for the given field, or null.booleanRemoves all term definitions that are defined for the given field.booleanRemoves the definition that is defined for the given field and term.voidSets the Query assigned for the given field and term, overwriting any previous definition.voidSets the Query assigned for the given field and term, overwriting any previous definition.toString()Outputs a String representation of the fields/terms/queries that are defined in this VirtulSearchFieldMapper.
-
Constructor Details
-
VirtualSearchFieldMapper
public VirtualSearchFieldMapper(org.apache.lucene.queryParser.QueryParser parser) Constructor for the VirtualSearchFieldMapper object- Parameters:
parser- The QueryParser used to parse Lucene queries that are defined in the configuration file
-
-
Method Details
-
getQuery
Gets the Lucene Query that is defined for the given virtual field/term pair, or null if none avaialable.- Parameters:
virtualField- The virtual search fieldvirtualTerm- The virtual search term- Returns:
- The Lucene Query, or null if none avaialable
-
getQueryString
Gets the Lucene Query as a String for the given virtual field and term, or null if not avaialable.- Parameters:
virtualField- The virtual search fieldvirtualTerm- The virtual search term- Returns:
- The Lucene Query as a String, or null if not avaialable
-
getNumTermsConfiguredForField
Gets the number of virtual terms configured for a given virtual field.- Parameters:
virtualField- The virtual search field- Returns:
- The number of virtual terms configured for this field or zero if the given field does not exist
-
getIsTermConfiguredForField
Determines whether the given virtual term is configured for the given field.- Parameters:
virtualField- The virtual search fieldvirtualTerm- The virtual search term- Returns:
- True if the given virtual field exists and the given virtual term is configured for that field
-
setQuery
Sets the Query assigned for the given field and term, overwriting any previous definition.- Parameters:
virtualField- The fieldvirtualTerm- The termquery- The new Query value for this field/term
-
setQuery
public void setQuery(String virtualField, String virtualTerm, String query) throws org.apache.lucene.queryParser.ParseException Sets the Query assigned for the given field and term, overwriting any previous definition. The query String provided must conform to the grammar understood by theQueryParserObject that was passed into the constructor.- Parameters:
virtualField- The fieldvirtualTerm- The termquery- The new Query value for this field/term- Throws:
org.apache.lucene.queryParser.ParseException- If error parsing the query String
-
remove
Removes the definition that is defined for the given field and term. After removal, subsequent calls togetQuery(java.lang.String, java.lang.String)orgetQueryString(java.lang.String, java.lang.String)for this field/term pair will return null.- Parameters:
virtualField- The fieldvirtualTerm- The term- Returns:
- True if a mapping existed for this field/term pair and was removed, otherwise false
-
remove
Removes all term definitions that are defined for the given field. After removal, subsequent calls togetQuery(java.lang.String, java.lang.String)orgetQueryString(java.lang.String, java.lang.String)will return null for all references to this field.- Parameters:
virtualField- The field to remove- Returns:
- True if one or more mappings existed for this field and were removed, otherwise false
-
clear
public void clear()Clears all field/term definitions that are defined. After calling this method, subsequent calls togetQuery(java.lang.String, java.lang.String)orgetQueryString(java.lang.String, java.lang.String)will return null for all calls. -
getVirtualFields
Gets the virtual fields that are defined.- Returns:
- The virtual fields
-
getVirtualTerms
Gets the virtual terms that are defined for the given field, or null.- Parameters:
field- The field- Returns:
- The virtual terms defined for the given field, or null
-
addVirtualFieldConfiguration
Adds all virtual field/term query definitions (virtualSearchField elements) contained in the given XML configuration String, replacing any previous definitions.- Parameters:
xmlConfig- The VirtualSearchFieldMapper configuration XML string- Throws:
Exception- If error parsing the String
-
addVirtualFieldConfiguration
Adds all virtual field/term query definitions (virtualSearchField elements) contained in the given XML configuration file, replacing any previous definitions.- Parameters:
xmlConfigFile- The VirtualSearchFieldMapper configuration XML file- Throws:
Exception- If error parsing or reading the file
-
addVirtualFieldConfiguration
Adds all virtual field/term query definitions (virtualSearchField elements) contained in the given XML configuration file, replacing any previous definitions.- Parameters:
xmlConfig- The URL to the VirtualSearchFieldMapper configuration XML file- Throws:
Exception- If error parsing or reading the url
-
toString
Outputs a String representation of the fields/terms/queries that are defined in this VirtulSearchFieldMapper.
-