LocalParamsPatternBuilder
A pattern builder that allows to create index patterns that use the local parameter syntax of Solr.
Example for the local parameter syntax: {!lucene q.op=AND df=text}foo bar
The builder provides functions to specify the query parser, set the required parameters and the pattern that will be used. Via the special setter setRawIndexFieldParam it is possible to reference the native index field of the solr index used by the specified index field.
The default query parser type is edismax which is the default parser used by the indexsearch.
Methods
asNestedPattern
asNestedPattern():
NestedPattern
Wraps this builder in to NestedPattern term object that can be appended to a pattern config instance.
Returns
a new NestedPattern instance that holds pattern of this builder.
getParam
getParam(
pKey):string
Returns the value of an already specified local parameter.
If the parameter contains multiple values the first in the list is returned.
Parameters
string | number | booleanthe name of the parameter.
Returns
stringthe associated value for the given parameter, or NULL if the parameter does not exist or has no value associated with it.
getParams
getParams(
pKey):string[]
Returns a list of the values that ar associated with the specified local parameter.
Parameters
string | number | booleanthe name of the parameter.
Returns
string[]the associated values for the given parameter as an array, or an empty array if the parameter does not exist or has no value associated with it.
getPattern
getPattern():
string
Returns
stringthe index pattern that will be executed by the specified query parser.
getType
getType():
string
Returns
stringthe type of query parser that will be used to run the pattern.
isEmpty
isEmpty():
boolean
Checks if the join query contains no patten and is thus considered empty.
Returns
booleantrue, if the builder contains no pattern.
setParam
setParam(
pKey,pValue):LocalParamsPatternBuilder
Sets the value for the specified parameter.
All previously set values for the parameter will be overridden.
Parameters
string | number | booleanthe name of the parameter.
string | number | booleanthe associated value.
Returns
LocalParamsPatternBuildersetParams
setParams(
pKey,pValues):LocalParamsPatternBuilder
Sets the values for the specified parameter.
All previously set values for the parameter will be overridden.
Parameters
string | number | booleanthe name of the parameter.
string[]the associated values.
Returns
LocalParamsPatternBuildersetPattern
setPattern(
pPattern):LocalParamsPatternBuilder
Sets the index pattern that will be executed by the specified query parser.
Parameters
string | number | booleanthe index pattern as string.
Returns
LocalParamsPatternBuildersetRawIndexFieldParam
setRawIndexFieldParam(
pKey,pIndexGroup,pIndexField):LocalParamsPatternBuilder
A special setter that allows to reference an index field in a parameter.
The setter will add a special placeholder for the index field as value. When the final pattern is built the placeholder will be replaced with the native index field name of the solr index.
Parameters
string | number | booleanthe name of the parameter.
string | number | booleanthe name of the index group the field belongs to. Can not be NULL or empty.
string | number | booleanthe name of the index field. Can not be NULL or empty.
Returns
LocalParamsPatternBuilderThrows
May throw an exception.
Example
// Constructs a lucene pattern that uses a reference for the contact_id field.
var builder = indexsearch.createLocalParamsPattern()
.setType("lucene")
.setRawIndexFieldParam("df", "Organisation", "contact_id"); // Add a reference for the contact_id field.
.setPattern("*:*");
// The getter will always return the placeholder
var placeholder = builder getParam("df"); // -> $$RIF.Organisation.contact_id$$
// During the build of the resulting pattern the native field will be inserted for the placeholder.
// -> {!lucene df=contact_id_value_idx_sto_string}*:*
var pattern = indexsearch.buildPattern(builder);
setType
setType(
pType):LocalParamsPatternBuilder
Sets the type of query parser that will be used to run the pattern.
Parameters
string | number | booleanthe type of the query parser.
Returns
LocalParamsPatternBuilderExample
<code>
// The example constructs a pattern that uses local params.
// The resulting pattern will use the lucene query parser of the index to search in a specific index field.
// Note: The pattern must be converted into a nested Query in order to use it as the actual pattern and not as filter.
// The pattern will search all organisations that start with 'A' and also contain 'GmbH' in their name.
// -> {!lucene q.op=AND df=name_value_idx_sto_textnostopwords}A* GmbH
// Create the local parameter pattern builder
var localParamsBuilder = indexsearch.createLocalParamsPattern()
.setType("lucene") // Specify the requested query parser.
.setParam("q.op", indexsearch.OPERATOR_AND) // Set the parameter for the default operator.
.setRawIndexFieldParam("df", "Organisation", "name_value") // Specify an index field for a parameter.
.setPattern("A* GmbH"); // Set the pattern used by the specified parser.
// Construct the embedded pattern used for the search
// -> +_query_:"{!lucene q.op=AND df=name_value_idx_sto_textnostopwords}A* GmbH"
var pattern = indexsearch.buildPattern(
indexsearch.createPatternConfig()
.plus(localParamsBuilder.asNestedPattern()));
// Create an index query for the pattern limited to search only for organisations.
var indexQuery = indexsearch.createIndexQuery()
.setPattern(pattern)
.setIndexGroups(["Organisation"]);
indexsearch.searchIndex(indexQuery);
</code>