Portal Community

Activating Global Search

Search Behavior

BehaviorDetail
Minimum query length2 characters — shorter queries are ignored
Debounce delay300ms after last keystroke — prevents excessive API calls
Results per sectionDefault: top 5 per section — expandable to 20
Result rankingExact title match > partial title match > body/description match
Empty queryClears results — shows recent searches if any
Loading stateSpinner shown while API call is in progress (typically <200ms)

React Component Implementation

import { useState, useCallback } from 'react';
import { useDebouncedCallback } from 'use-debounce';
import { useSearchStore } from '../stores/searchStore';

function GlobalSearch() {
  const [query, setQuery] = useState('');
  const { results, setResults, isLoading, setLoading } = useSearchStore();

  const search = useDebouncedCallback(async (q: string) => {
    if (q.length < 2) { setResults(null); return; }
    setLoading(true);
    try {
      const data = await api.get(`/workdesk/search?q=${encodeURIComponent(q)}&limit=5`);
      setResults(data);
    } finally {
      setLoading(false);
    }
  }, 300);

  const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
    setQuery(e.target.value);
    search(e.target.value);
  };

  return (
    <div className="global-search">
      <input
        type="text"
        placeholder="Search tasks, workflows, notifications..."
        value={query}
        onChange={handleChange}
      />
      {isLoading && <Spinner />}
      {results && <SearchResults results={results} query={query} />}
    </div>
  );
}

Result Navigation

Clicking a search result navigates directly to that item:

Scoped Search

Global search can be scoped to a single section by appending a section parameter. This is useful when you know the result is in a specific section:

// Scope to tasks only
GET /api/workdesk/search?q=budget+review&section=tasks

// Scope to history only
GET /api/workdesk/search?q=payroll&section=history

// All sections (default)
GET /api/workdesk/search?q=budget+review
Recent Searches

WorkDesk stores the last 10 search queries in localStorage and shows them as suggestions when the search bar is focused with an empty query. This makes re-running recent searches one click away.