CIOSearchQueryBuilder

public class CIOSearchQueryBuilder

Request builder for creating an search query.

  • Create a Search request query builder

    Declaration

    Swift

    public init(query: String)

    Parameters

    query

    The user typed query to return results for

  • Add additional filters

    Declaration

    Swift

    public func setFilters(_ filters: CIOQueryFilters) -> CIOSearchQueryBuilder
  • Add a sort option

    Declaration

    Swift

    public func setSortOption(_ sortOption: CIOSortOption) -> CIOSearchQueryBuilder
  • Add a page number

    Declaration

    Swift

    public func setPage(_ page: Int) -> CIOSearchQueryBuilder
  • Add the number of results to return per page

    Declaration

    Swift

    public func setPerPage(_ perPage: Int) -> CIOSearchQueryBuilder
  • Add the number of results to return per page

    Declaration

    Swift

    public func setSection(_ section: String) -> CIOSearchQueryBuilder
  • Add a list of hidden metadata fields to return

    Declaration

    Swift

    public func setHiddenFields(_ hiddenFields: [String]) -> CIOSearchQueryBuilder
  • Add a list of hidden facets to return

    Declaration

    Swift

    public func setHiddenFacets(_ hiddenFacets: [String]) -> CIOSearchQueryBuilder
  • Add a groups sort option

    Declaration

    Swift

    public func setGroupsSortOption(_ groupsSortOption: CIOGroupsSortOption) -> CIOSearchQueryBuilder
  • Add the pre filter expression

    Declaration

    Swift

    public func setPreFilterExpression(_ preFilterExpression: String) -> CIOSearchQueryBuilder
  • Add a variations map to return per variation

    Declaration

    Swift

    public func setVariationsMap(_ variationsMap: CIOQueryVariationsMap) -> CIOSearchQueryBuilder
  • Build the request object with all of the provided data

    Usage Example:

    let facetFilters = [(key: "Nutrition", value: "Organic"),
                        (key: "Nutrition", value: "Natural"),
                        (key: "Brand", value: "Kraft Foods")]
    
    let preFilterExpression = "{\"or\":[{\"and\":[{\"name\":\"group_id\",\"value\":\"electronics-group-id\"},{\"name\":\"Price\",\"range\":[\"-inf\",200.0]}]},{\"and\":[{\"name\":\"Type\",\"value\":\"Laptop\"},{\"not\":{\"name\":\"Price\",\"range\":[800.0,\"inf\"]}}]}]}"
    
    let query = CIOSearchQueryBuilder(query: "blue")
       .setFilters(CIOQueryFilters(groupFilter: nil, facetFilters: facetFilters))
       .setPage(2)
       .setPerPage(40)
       .setSection("Products")
       .setHiddenFields(["hidden_price_field", "color_swatches"])
       .setHiddenFacets(["hidden_facet"])
       .setPreFilterExpression(preFilterExpression)
       .build()
    
    constructor.search(forQuery: query, completionHandler: { ... })
    

    Declaration

    Swift

    public func build() -> CIOSearchQuery