useSearch

The hook for searching your data and applying selections

Basic Example

import { useSearch } from "@motor-js/engine"

const Search = () => {

  const [options, setOptions] = useState([]);
  const [searchValue, setSearchValue] = useState("");
  const [qCount, setQCount] = useState(10);
  const [qGroupItemCount, setQGroupOptions] = useState(10);

  const { 
    groupResults,
    flatResults,
    groupselect,
    flatSelect,
  } = useSearch({ 
    searchValue,
    qCount,
    qGroupItemCount
  })

    return (
    <div></div>
    );

};

Search Options

The following options can be passed into the hook

  • searchValue: string

    • Required

    • The string you are searching your Qlik application for

  • qCount: number

    • Required

    • The maximum number of dimensions returned from the search results

  • qGroupItemCount: number

    • Required

    • The maximum number of values for each dimension returned from the search results

Search Properties

The following properties are returned from the hook

  • groupResults: array<groupResult>

    • An array of groupedResult objects, containing the search results grouped by dimension

  • flatResults: array<flatResult>

    • An array of flatResult objects, containing a flattened list of the search results. Each dimension value will be returned in a separate object

  • groupSelect: Function(id)

    • A function to apply selections against the Qlik engine

    • To be used with groupResults

    • Pass the id returned from the groupResult you wish to select. This will be the id of the dimension

    • Function will select all matching search items for that dimension

  • flatSelect: Function(dimension<string>, value<string>)

    • A function to apply selections against the Qlik engine

    • To be used with flatResults

    • Pass the dimension and value that you wish to select, both should be a string

groupResult Properties

The following properties are returned in each instance of the groupResults array

  • dimension: string

    • The dimension name returned from the search

  • value: Array<groupResultItems>

    • The an array of dimension values returned from the search

groupResultItem Properties

The following properties are returned in each instance of the groupResultItem array

  • qRanges

    • An object containing the character positions matched in the search result

  • qItem

    • The dimension value returned from the search

flatResult Properties

The following properties are returned in each instance of the flatResults array

  • dimension: string

    • The dimension name returned from the search

  • value: string

    • The dimension value returned from the search

Last updated