Skip to main content
Version: 2025.1

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

pKey
string | number | boolean

the name of the parameter.

Returns

string

the 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

pKey
string | number | boolean

the 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

string

the index pattern that will be executed by the specified query parser.


getType

getType(): string

Returns

string

the 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

boolean

true, 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

pKey
string | number | boolean

the name of the parameter.

pValue
string | number | boolean

the associated value.

Returns

LocalParamsPatternBuilder

setParams

setParams(pKey, pValues): LocalParamsPatternBuilder

Sets the values for the specified parameter.

All previously set values for the parameter will be overridden.

Parameters

pKey
string | number | boolean

the name of the parameter.

pValues
string[]

the associated values.

Returns

LocalParamsPatternBuilder

setPattern

setPattern(pPattern): LocalParamsPatternBuilder

Sets the index pattern that will be executed by the specified query parser.

Parameters

pPattern
string | number | boolean

the index pattern as string.

Returns

LocalParamsPatternBuilder

setRawIndexFieldParam

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

pKey
string | number | boolean

the name of the parameter.

pIndexGroup
string | number | boolean

the name of the index group the field belongs to. Can not be NULL or empty.

pIndexField
string | number | boolean

the name of the index field. Can not be NULL or empty.

Returns

LocalParamsPatternBuilder

Throws

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

pType
string | number | boolean

the type of the query parser.

Returns

LocalParamsPatternBuilder

Example

<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.
// -&gt; {!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
// -&gt; +_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>