Semantic-Org/Semantic-UI · warning

Results must be an array to use maxResults setting

Error message

Results must be an array to use maxResults setting

What it means

In generateResults() (search.js:1003-1008), when settings.maxResults > 0 and the response results come back as a plain object (isProperObject) rather than an array, the module cannot slice/limit object results for the 'standard' type, so it logs error.maxResults. Arrays are sliced fine; object-shaped results with maxResults on the standard template are not supported.

Source

Thrown at src/definitions/modules/search.js:1306

    animating : 'animating',
    active    : 'active',
    empty     : 'empty',
    focus     : 'focus',
    hidden    : 'hidden',
    loading   : 'loading',
    results   : 'results',
    pressed   : 'down'
  },

  error : {
    source          : 'Cannot search. No source used, and Semantic API module was not included',
    noResults       : 'Your search returned no results',
    logging         : 'Error in debug logging, exiting.',
    noEndpoint      : 'No search endpoint was specified',
    noTemplate      : 'A valid template name was not specified.',
    oldSearchSyntax : 'searchFullText setting has been renamed fullTextSearch for consistency, please adjust your settings.',
    serverError     : 'There was an issue querying the server.',
    maxResults      : 'Results must be an array to use maxResults setting',
    method          : 'The method you called is not defined.'
  },

  metadata: {
    cache   : 'cache',
    results : 'results',
    result  : 'result'
  },

  regExp: {
    escape     : /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,
    beginsWith : '(?:\s|^)'
  },

  // maps api response attributes to internal representation
  fields: {
    categories      : 'results',     // array of categories (category view)
    categoryName    : 'name',        // name of category (category view)

View on GitHub (pinned to 597843ab84)

Solutions

  1. Return results as an array from your endpoint or local source so slicing works.
  2. If you must keep object results, set maxResults: 0 to disable limiting.
  3. Switch type to 'category' if you genuinely need grouped/object data (and handle limiting server-side).

Example fix

// before: results is an object {1:{...}} with maxResults
$('.ui.search').search({ type:'standard', maxResults: 5, apiSettings:{ url:'/api?q={query}' } });

// after: endpoint returns an array
$('.ui.search').search({ type:'standard', maxResults: 5, apiSettings:{ url:'/api?q={query}' } }); // server returns { results: [ ... ] }
Defensive patterns

Strategy: type-guard

Validate before calling

if (cfg.maxResults > 0 && cfg.type !== 'standard') {
  // fine for category; for standard ensure array results server-side
}
if (cfg.maxResults > 0) console.assert($.isArray(lastResponse), 'Results must be an array for maxResults');

Type guard

function resultsAreArray(resp){ return $.isArray(resp && resp.results); }

Prevention

When it happens

Trigger: settings.type is 'standard', settings.maxResults is set (>0), and the remote/local response returns results as a plain object (e.g. {id:{...}}) instead of an array. The branch at search.js:1004-1007 fires.

Common situations: Backend returns a keyed map instead of a list; switching response shape without disabling maxResults; using the standard template with a category-shaped payload.

Related errors


AI-assisted analysis of Semantic-Org/Semantic-UI@597843ab84 (2026-08-13). Data as JSON: /api/errors/cb48a29f8ecde9f6. Report an issue: GitHub.