Skip to main content

Global Search

Resources can provide global search results for their model.

By default, a resource participates in global search when the current user can viewAny the model:

public function isGlobalSearchEnabled(): bool
{
return Gate::allows('viewAny', $this->modelClass());
}

Qore searches text-like, filterable index fields and excludes password fields.

The result query starts from optionsQuery(). That method defaults to indexQuery(), but can be overridden when global search, relation options and attach-existing choices should share different scoping, ordering or eager loading than the index table.

Search Fields

Override getGlobalSearchFields() when a resource needs a smaller or broader search surface:

use Qore\Next\System\Field\Field;

/**
* @return list<Field>
*/
public function getGlobalSearchFields(): array
{
return [
$this->getFieldOrFail('name'),
$this->getFieldOrFail('email'),
];
}

The fields are applied through their field filter logic. That keeps search behaviour close to the field that knows how its value should be queried.

Result Node

Each result can render a custom node. Use this when the default icon, title and resource label do not give enough context.

The default result node uses modelTitle() as the title and modelDescription() as the optional second line. When modelDescription() returns null, Qore falls back to the resource singular label.

public function modelDescription(Model $model): ?string
{
return $model->email;
}
use Illuminate\Database\Eloquent\Model;
use Qore\Next\System\Node\Flex\FlexAlignType;
use Qore\Next\System\Node\Node;
use Qore\Next\System\Nodes\FlexNode;
use Qore\Next\System\Nodes\IconNode;
use Qore\Next\System\Nodes\TextNode;

public function globalSearchNode(Model $model): Node
{
return (new FlexNode)
->setAlign(FlexAlignType::CENTER)
->setGap(12)
->addChild(new IconNode($this->icon(), 16))
->addChild(new TextNode($this->modelTitle($model)));
}

Qore serializes this node through NodeManager, just like a page node. The result also includes the resource detail URL as navigate_url.

Result Payload

globalSearchResult() returns:

  • a stable result ID;
  • the resource detail URL;
  • a node endpoint for lazy rendering;
  • the first node response data.

Prefer overriding globalSearchNode() before overriding globalSearchResult(). The node method keeps the search contract intact while letting you customize the visible result.