GroupTerm
A group term for the index search. As all term typs this type supports the standard functions for setting the field name (entity and index) and the search weighting (boost). A group term allows to group terms to form a sub-query. This is very useful to control the Boolean logic for a query. This term object works similar to the IndexPatternConfiguration allowing to append term objects with different operators.
- Sub-query: Create a simple sup-query by simply adding terms without defining a field name for the group. The following term searches for either "Lisa" or "Sommer" and "MeineFirma" (
( Lisa OR Sommer ) AND meineFirma).
Example
<code>
// Assume that the followeing terms are defined fistname['Lisa'], lastname['Sommer']
// and orgName['meineFirma']
// '( Lisa OR Sommer )'
var group = indexsearch.createGroupTerm().or(firstname).or(lastname);
// '( Lisa OR Sommer ) AND meineFirma'
var patternConf = indexsearch.createPatternConfig().or(group).and(orgName);
</code>
The grouped terms can be specified with field names.
Example
<code>
// Assume that the followeing terms are defined fistname['firstname_value:Lisa'],
// lastname['lastname_value:Sommer'] and orgName['name_value:meineFirma']
// '( firstname_value:Lisa OR lastname_value:Sommer )'
var group = indexsearch.createGroupTerm().or(firstname).or(lastname);
// '( firstname_value:Lisa OR lastname_value:Sommer ) AND name_value:meineFirma'
var patternConf = indexsearch.createPatternConfig().or(group).and(orgName);
</code>
- Grouping clauses within a index field: To apply two or more Boolean operators to a single index field in a search, add the Terms (without a field name) for the desired field to a single group and set the field name of the group term to the desired field. For example, the following group searches for a firstname field that matches "L*" but not "Lisa" (
firstname_value:( +L* -Lisa )).
Example
<code>
// Assume that the followeing terms are defined prefixTerm['L*'] and singleName['Lisa']
// '( +L* -Lisa )'
var group = indexsearch.createGroupTerm().plus(prefixTerm).minus(singleName);
// Specify the field for the hole group.
group.setEntityField("Person_entity.FIRSTNAME");
// 'firstname_value:( +L* -Lisa )'
var patternConf = indexsearch.createPatternConfig().or(group);
</code>
This term object provides an isEmpty() method, that will return true if no terms where added. NOTE: Do not add empty group terms to an IndexPatternConfiguration or another group term. This can cause the resulting pattern to fail. Example:
Methods
and
and(
pTerm):GroupTerm
Adds the term to the end of the pattern using the operator AND. If it is the first term of the pattern, it is added with the leading operator +. AND requires that this and the previous term be present for a match.
Parameters
IIndexTermThe term to be appended.
Returns
GroupTermgetBoost
getBoost():
number
Returns the boost factor for this therm. The index search provides the relevance level of matching documents based on the terms found. Boosting allows you to control the relevance of a result document by boosting its term. The higher the boost factor, the more relevant the term will be. The default boost factor for each term is 1.0. The boost factor must always be a positiv value grater the 0.0.
Returns
numberThe boost factor of this term.
getEntityField
getEntityField():
string
Returns
stringThe defined entity field in which to search for the value. null if not set.
getIndexField
getIndexField():
string
Returns
stringThe defined index field in which to search for the value. null if not set.
isEmpty
isEmpty():
boolean
Returns
booleantrue if the group term does not contain any terms.
minus
minus(
pTerm):GroupTerm
Adds the term to the end of the pattern using the leading operator -. - prohibits this term. The - operator is functionally similar to the Boolean operator !
Parameters
IIndexTermThe term to be appended.
Returns
GroupTermnot
not(
pTerm):GroupTerm
Adds the term to the end of the pattern using the operator NOT. If it is the first term of the pattern, it is added with the leading operator -. NOT requires this term to be not present.
Parameters
IIndexTermThe term to be appended.
Returns
GroupTermor
or(
pTerm):GroupTerm
Adds the term to the end of the pattern using the operator OR. If it is the first term of the pattern, it is added without a leading operator. OR requires that either this or the previous term (or both terms) be present for a match.
Parameters
IIndexTermThe term to be appended.
Returns
GroupTermplus
plus(
pTerm):GroupTerm
Adds the term to the end of the pattern using the leading operator +. + requires this term to be present.
Parameters
IIndexTermThe term to be appended.
Returns
GroupTermsetBoost
setBoost(
pBoost):GroupTerm
Specifies the boost factor for this therm. The index search provides the relevance level of matching documents based on the terms found. Boosting allows you to control the relevance of a result document by boosting its term. The higher the boost factor, the more relevant the term will be. The implicit default boost factor for each term is 1.0. To increase the relevance specify a value greater then 1.0, e.g. 1.5. To decrease the relevance specify a value lower then 1.0, e.g. 0.5. The boost factor must always be a positiv value grater the 0.0.
Parameters
numberthe boost factor of this term.
Returns
GroupTermsetEntityField
setEntityField(
pEntityField):GroupTerm
Specifies the entity field in whose corresponding index field to search for the value. If not set, the value of the term is searched in all search fields specified in the IndexQuery. The names of the entity field must start with the defining entity, e.g. person_entity.FIRSTNAME. You can specify whether the index field defined for value or displayValue should be used, e.g. person_entity.FIRSTNAME.displayValue. If not specified, the index field defined for value is returned. The index field is looked up when calling searchIndex. The search fails if no index field can be determined for the specified entity field.
Parameters
string | number | booleanthe name of the entity field.
Returns
GroupTermsetIndexField
setIndexField(
pIndexFieldName):GroupTerm
Specifies the index field in which to search for the value. If not set, the value of the term is searched in all search fields specified in the IndexQuery.
Parameters
string | number | booleanthe name of the index field.
Returns
GroupTermExample
<code>
import("system.indexsearch");
var patternConf = indexsearch.createPatternConfig();
var a = indexsearch.createTerm("A");
var b = indexsearch.createTerm("B");
var c = indexsearch.createTerm("C");
var group = indexsearch.createGroupTerm();
// Add terms (a & b) to the group.
// '( A B )'
group.or(a).or(b);
// specifies a field and a boost for the group term.
// 'field_value:( A B )^1.3'
term.setEntityField("entityName.FIELD.value")
.setBoost(1.3);
// Add the group to a pattern configuration.
// '+( A B ) +C'
patternConf.plus(group).plus(c);
// result => +field_value:( A B )^1.3 +C
var pattern = indexsearch.buildPatternString(patternConf);
</code>