PHP code example of pimcore / advanced-object-search
1. Go to this page and download the library: Download pimcore/advanced-object-search library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pimcore / advanced-object-search example snippets
/**
* @var \AdvancedObjectSearchBundle\Service $service
*/
$service = $this->get("AdvancedObjectSearchBundle\Service");
$service->updateMapping(ClassDefinition::getByName("Product"));
/**
* @var \AdvancedObjectSearchBundle\Service $service
*/
$service = $this->get("AdvancedObjectSearchBundle\Service");
$objects = Product::getList();
foreach($objects as $object) {
$service->doUpdateIndexData($object);
}
/**
* @var \AdvancedObjectSearchBundle\Service $service
*/
$service = $this->get("AdvancedObjectSearchBundle\Service");
//filter for relations via ID
$results = $service->doFilter(3,
[
new FilterEntry(
"objects",
[
"type" => "object",
"id" => 75
],
BoolQuery::SHOULD
)
],
""
);
//filter for relations via sub query
$results = $service->doFilter(3,
[
[
"fieldname" => "objects",
"filterEntryData" => [
"type" => "object",
"className" => "Customer",
"filters" => [
[
"fieldname" => "firstname",
"filterEntryData" => "tom"
]
]
]
],
],
""
);
// full text search query without filters
$results = $service->doFilter(3,
[],
"sony"
);
// filter for several attributes - e.g. number field, input, localized fields
$results = $service->doFilter(3,
[
[
"fieldname" => "price",
"filterEntryData" => 50.77
],
[
"fieldname" => "price2",
"filterEntryData" => [
"gte" => 50.77,
"lte" => 50.77
]
],
[
"fieldname" => "keywords",
"filterEntryData" => "test2",
"operator" => BoolQuery::SHOULD
],
[
"fieldname" => "localizedfields",
"filterEntryData" => [
"en" => [
"fieldname" => "locname",
"filterEntryData" => "englname"
]
]
],
[
"fieldname" => "localizedfields",
"filterEntryData" => [
"de" => [
"fieldname" => "locname",
"filterEntryData" => "deutname"
]
]
],
new FilterEntry("keywords", "testx", BoolQuery::SHOULD)
],
""
);