Interface FulltextSearchBuilder
- All Known Implementing Classes:
EnterpriseFulltextSearchBuilder
,FulltextSearchBuilderImpl
Procedure in the build methods
- The
searchInput
issplit
into words. - The target fields on the
targetModel
are collected. Which fields are included in the search depends on thesearchScope
. The fields can be configured in the entity model xml. It is also possible to follow more relations . - Each word from the search input is then offered to every participating field. Those fields can decide themselves if they include the term or not, for example depending on data type. A numeric field probably ignores an alpha string. The search fields are concatenated as an AND search, that is every term from the user input must match in at least one field - or be ignored by all fields.
How to use
Inject theFulltextSearchBuilderFactory
and call FulltextSearchBuilderFactory.fulltext()
.-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
What kind of fulltext search it is:FulltextSearchBuilder.SearchScope.FULLTEXT
,FulltextSearchBuilder.SearchScope.RELATION
orFulltextSearchBuilder.SearchScope.REMOTEFIELD
. -
Method Summary
Modifier and TypeMethodDescriptionbuild
(EntityModel queryEntityModel, @Nullable FulltextSearchBuilder.SearchScope searchScope, String searchInput, String fieldPath, FieldModel fieldModel, @Nullable EntityModel entityModel) build
(EntityModel rootModel, String searchInput, EntityModel targetModel, FulltextSearchBuilder.SearchScope searchScope) Appends criteria on the query to look for the given input on the fields configured on the entity for the corresponding SearchScope, for example 'fulltext'.build
(EntityModel rootModel, String searchInput, EntityModel targetModel, FulltextSearchBuilder.SearchScope searchScope, String fieldPrefix) Overloaded method with a fieldPrefix to use in the query.build
(EntityModel queryEntityModel, String searchInput, String fieldPath, FieldModel fieldModel) Appends criteria on the query to look for the given input in the field specified.build
(EntityModel queryEntityModel, String searchInput, Map<String, FieldModel> queryFields) Appends criteria on the query to look for the given input in the fields specified.build
(EntityModel queryEntityModel, String searchInput, Map<String, FieldModel> queryFields, @Nullable EntityModel entityModel)
-
Method Details
-
build
Optional<Condition> build(EntityModel rootModel, String searchInput, EntityModel targetModel, FulltextSearchBuilder.SearchScope searchScope) Appends criteria on the query to look for the given input on the fields configured on the entity for the corresponding SearchScope, for example 'fulltext'.Example: You are building a query (eg "find Address") and need to join in a fulltext search on that same entity for a user specified search term (eg "8021 zurich").
See
class header
.- Parameters:
searchInput
- The user-provided fulltext search.targetModel
- The target entity to join- Returns:
true
if something was appended,false
if not (for example because the query terms were considered too short by all fields involved).
-
build
Optional<Condition> build(EntityModel rootModel, String searchInput, EntityModel targetModel, FulltextSearchBuilder.SearchScope searchScope, String fieldPrefix) Overloaded method with a fieldPrefix to use in the query.This is the method to use when the targetModel is not the same as the main one used in the query
Example: You are building a query (eg "find User") and need to join in a fulltext search on a related entity (eg "Address") for a user specified search term (eg "8021 zurich").
See
class header
.- Parameters:
searchInput
- The user-provided fulltext search.targetModel
- The target entity to joinfieldPrefix
- Must end with a dot (the separator). Example: "myRelation."- Returns:
true
if something was appended,false
if not (for example because the query terms were considered too short by all fields involved).- See Also:
-
build
Optional<Condition> build(EntityModel queryEntityModel, String searchInput, Map<String, FieldModel> queryFields) Appends criteria on the query to look for the given input in the fields specified. Example:
This means: all parts of the searchInput must occur in at least one of the fields. So:CriterionOrCloseBracket q = ...; FulltextSearchBuilder fsb = fulltextFactory.fulltext(); QueryStatementHolder builder = new QueryStatementHolder(q); Map<String, FieldModel> fieldsToSearch = new HashMap<String, FieldModel>(); fieldsToSearch.put("zip_c", addressEntityModel.getFieldByName("zip_c")); fieldsToSearch.put("city_c", addressEntityModel.getFieldByName("city_c")); if ( fsb.build( builder, "8021 zurich", fieldsToSearch ) ) { q = builder.getCriterion(); }
- all parts of searchInput are mandatory (AND search)
- it does not matter in which field(s) (fields joined with OR)
See
class header
.- Parameters:
queryEntityModel
- The model of the query you're buildingsearchInput
- The user-provided fulltext search.queryFields
- The fields to include in the search. The key is the path to the field, which may go through relations.- Returns:
true
if something was appended,false
if not (for example because the searchInput terms were considered too short by all fields involved).- See Also:
-
build
Optional<Condition> build(EntityModel queryEntityModel, String searchInput, Map<String, FieldModel> queryFields, @Nullable @Nullable EntityModel entityModel) -
build
Optional<Condition> build(EntityModel queryEntityModel, String searchInput, String fieldPath, FieldModel fieldModel) Appends criteria on the query to look for the given input in the field specified.Example:
CriterionOrCloseBracket q = ...; FulltextSearchBuilder fsb = fulltextFactory.fulltext(); QueryStatementHolder builder = new QueryStatementHolder(q); if ( fsb.build( builder, "zürich höngg", "relUser_Address.city_c", addressEntityModel.getFieldByName("city_c") ) ) { q = builder.getCriterion(); }
See
class header
.- Parameters:
searchInput
- The user-provided fulltext search.fieldPath
- The path to the field, may go through relations(s).fieldModel
- The field's model.- Returns:
true
if something was appended,false
if not (for example because the searchInput terms were considered too short by the field).- See Also:
-
build
Optional<Condition> build(EntityModel queryEntityModel, @Nullable @Nullable FulltextSearchBuilder.SearchScope searchScope, String searchInput, String fieldPath, FieldModel fieldModel, @Nullable @Nullable EntityModel entityModel) - See Also:
-