Class FulltextSearchBuilderImpl

java.lang.Object
ch.tocco.nice2.persist.entity.impl.fulltext.FulltextSearchBuilderImpl
All Implemented Interfaces:
FulltextSearchBuilder

public class FulltextSearchBuilderImpl extends Object implements FulltextSearchBuilder
  • Constructor Details

    • FulltextSearchBuilderImpl

      public FulltextSearchBuilderImpl(org.slf4j.Logger log, List<String> excludedFieldTypes)
  • Method Details

    • build

      public Optional<Condition> build(EntityModel rootModel, String searchInput, EntityModel targetModel, FulltextSearchBuilder.SearchScope searchScope)
      Description copied from interface: FulltextSearchBuilder
      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.

      Specified by:
      build in interface FulltextSearchBuilder
      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

      public Optional<Condition> build(EntityModel rootModel, String searchInput, EntityModel targetModel, FulltextSearchBuilder.SearchScope searchScope, String fieldPrefix)
      Description copied from interface: FulltextSearchBuilder
      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.

      Specified by:
      build in interface FulltextSearchBuilder
      Parameters:
      searchInput - The user-provided fulltext search.
      targetModel - The target entity to join
      fieldPrefix - 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

      public Optional<Condition> build(EntityModel queryEntityModel, String searchInput, Map<String,FieldModel> queryFields)
      Description copied from interface: FulltextSearchBuilder
      Appends criteria on the query to look for the given input in the fields specified. Example:
      
       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();
       }
       
      This means: all parts of the searchInput must occur in at least one of the fields. So:
      • all parts of searchInput are mandatory (AND search)
      • it does not matter in which field(s) (fields joined with OR)

      See class header.

      Specified by:
      build in interface FulltextSearchBuilder
      Parameters:
      queryEntityModel - The model of the query you're building
      searchInput - 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

      public Optional<Condition> build(EntityModel queryEntityModel, String searchInput, Map<String,FieldModel> queryFields, @Nullable @Nullable EntityModel entityModel)
      Specified by:
      build in interface FulltextSearchBuilder
    • build

      public Optional<Condition> build(EntityModel queryEntityModel, String searchInput, String fieldPath, FieldModel fieldModel)
      Description copied from interface: FulltextSearchBuilder
      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.

      Specified by:
      build in interface FulltextSearchBuilder
      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

      public Optional<Condition> build(EntityModel queryEntityModel, @Nullable @Nullable FulltextSearchBuilder.SearchScope searchScope, String searchInput, String fieldPath, FieldModel fieldModel, @Nullable @Nullable EntityModel entityModel)
      Specified by:
      build in interface FulltextSearchBuilder
      See Also: