- ⌂ search
- Methods
- Static Methods
io_comand_search\search
Perform keyword searches on a COMAND repository with facets, custom search rules, etc.
Simple Example
The following example will search the entire repository based on a simple keyword string.
// Perform a simple keyword search on the entire repository.
$repo = comand::repo();
$results = \io_comand_search\search::search($repo, "Content Type");
foreach($results as $result) {
echo("$result\n");
}
Advanced Example
The following example will search all objects that are of or extend the Web Page Content Type.
// Perform a faceted search on Web Pages with custom search rules.
$repo = comand::repo();
$default_rules = \io_comand_search\search::default_rules();
$results = \io_comand_search\search::search($repo, 'treatments', [
'select' => ['Title', '.Summary()'],
'from' => ['WebPage+'],
'where' => ["Status='active'", "Tags.Title='Health'"],
'limit' => 12,
'rules' => array_merge_recursive($default_rules, [
'fields' => ['Title', '.Description()'],
'keyword' => [
'matches_title' => [
'where' => function($var) {
return $var['field'] . ' ILIKE ' . $var['keyword_like_filter'];
},
'condition' => function($vars) {
return $var['field'] . ' ILIKE ' . $var['keyword_like_filter'];
},
'score' => function($var) {
return 1;
},
'weight' => function($var) { return 100; }
]
]
])
]);
foreach($results as $result) {
echo("$result\n");
}