AndyJames
2/10/2020 - 4:25 PM

CMS Search API

<script>
FlowSearch.onReady().then((app) => {
  const indexes = {
    // listings: {
    INDEX_NAME_HERE: {
      enableUrlParams: false, // Can only work with one index!
      fsId: 'FLOWAPPS-INSTANCE-ID',
      // Initial Search Settings
      // Sort and Order
      orderBy: 'name.keyword',//Index must have name field
      sortBy: 'desc',
      from: 0,
      size: 50,
      filters: {
        // Add Filters Here
        // See Example Filters Snippet Below
      },
      pagination: {
        size: 50,
        fromSize: 50,
        currentSize: 0,
        currentPage: 1,
      },
      // Core
      searchResults: null,
      searchQueries: [],
      searching: false,
      searchResultsCount: null,
      hasSearchResults: true,
      searchResultsTotal: null,
      aggs: {},
    },
  };
  app.addIndexes(indexes);
});
</script>
// Here are some example of filters to setup
// Add any of thse filters to the filters{} object in -> FlowSearch onReady - Main Script

//NB! Minimum setup for a filter
// Must have field and component

// Component Types: numberFilter, dateFilter, buttonRangeFilter, filterSearch, isAvailable, textSearch, buttonFilterSingle, buttonFilterMulti, checkBoxFilterMulti, checkBoxFilterSingle
//IMPORTANT: In all snippets you will see FILTER_NAME_HERE this is the name you specify here:
FILTER_NAME_HERE: {
  field: 'FIELDNAME',
  component: 'COMPONENT_NAME',
},

eg:

siteSearch: {
  field: 'FIELDNAME',
  component: 'COMPONENT_NAME',
},

//Extra optional fields
siteSearch: {
  field: 'FIELDNAME',
  component: 'COMPONENT_NAME',
  //Optional
  action: 'filter', // advanced
  type: 'term', // !!Important - use terms if multi true or term if false - advanced
  id: 'amenities-filter',// Provide custom id - advanced
  size: 10,// Number of filter results to return
  orderBy: '_term', // _count
  orderSortBy: 'desc', // desc
}

//Normal Site Search
siteSearch: {
  field: 'name, description, propertyType, summary',
  component: 'textSearch'
},

//EqualTo number filter
dailyPriceEq: {
  field: 'dailyPrice',
  evaluation: 'EqualTo',
  component: 'numberFilter',
},

//EqualTo date filter
createdOn: {
  field: 'createdOn',
  evaluation: 'EqualTo',
  component: 'dateFilter',
},

//buttonRangeFilter
dailyPriceRanges: {
  component: 'buttonRangeFilter',
  field: 'dailyPrice',
  rangeGroups: [
    {
      label: '$50 to $75',
      evaluation: {
        lte: '75',
        gte: '50',
      },
    },
    {
      label: '$75 to $100',
      evaluation: {
        lte: '100',
        gte: '75',
      },
    },
    {
      label: '$101 to $200',
      evaluation: {
        lte: '200',
        gte: '101',
      },
    },
    {
      label: '$201 to $500',
      evaluation: {
        lte: '500',
        gte: '201',
      },
    },
    {
      label: '$500+',
      evaluation: {
        gt: '500',
      },
    },
  ],
},

// filterSearch filter
property: {
  field: 'propertyType',
  component: 'filterSearch',
  size: 10,
  orderBy: '_count', // _count
  sortBy: 'asc', // desc
},

// App search filter
appSearch: {
  field: 'name, description, propertyType, summary',
  component: 'textSearch',
},

// Is Available / checks for true/false
isAvailable: {
  field: 'isAvailable',
  component: 'isSetFilter',
},

// buttonFilterSingle
amenities: {
  field: 'amenities',
  component: 'buttonFilterSingle',
},

// checkBoxFilterMulti
facilities: {
  field: 'facilities',
  component: 'checkBoxFilterMulti',
  size: 20,
},