pimcore / advanced-object-search

Advanced Object Search community bundle provides advanced object search in Pimcore backend powered by OpenSearch.
Other
39 stars 45 forks source link

title: Advanced Object Search

Pimcore Advanced Object Search via OpenSearch or Elasticsearch

Advanced Object Search bundle provides advanced object search in Pimcore backend powered by search index technology (OpenSearch or Elasticsearch).

Integration into Pimcore

Installation and Configuration

Follow Installation instructions.

Configure Search Client

Setup search client configuration in your Symfony configuration files (e.g. config.yaml). See OpenSearch Client Setup or Elasticsearch Client Setup for more information.

Configure Advanced Object Search

Before starting, setup at least following configuration in symfony configuration tree:

advanced_object_search:
    # Prefix for index names
    index_name_prefix: 'advanced_object_search_'

For further configuration options follow the docs and the inline description of the configuration tree.

Initial Indexing

Call Pimcore command advanced-object-search:update-mapping for creating mappings and advanced-object-search:re-index for indexing data for the first time.

GUI

GUI for creating searches against search index with

Screen

Plugin Hooks

Following event listeners are called automatically

Pimcore Console

Functions in Pimcore console.

For details see documentation directly in Pimcore console.

Pimcore Maintenance & Symfony Messenger

By default, with every Pimcore maintenance call, 500 entries of update queue are processed. As an alternative, you also can activate symfony messenger to process the update queue. For that, just activate it as follows.

 advanced_object_search:
    messenger_queue_processing:
        activated: true

If activated, the processing is kicked off automatically with the advancedobjectsearch_update_queue maintenance task.

Messages are dispatched via pimcore_index_queues transport. So make sure, you have workers processing this transport when activating the messenger based queue processing.

API Methods

Create Mapping for data object classes

Per data object class one index with one document type is created.

<?php
/**
* @var \AdvancedObjectSearchBundle\Service $service
 */
$service = $this->get("AdvancedObjectSearchBundle\Service");
$service->updateMapping(ClassDefinition::getByName("Product"));

Update index data

On data object save or via script:

<?php
/**
* @var \AdvancedObjectSearchBundle\Service $service
 */
$service = $this->get("AdvancedObjectSearchBundle\Service");

$objects = Product::getList();
foreach($objects as $object) {
    $service->doUpdateIndexData($object);
}

Search/Filter for data

<?php
/**
* @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)
    ],
    ""
);

Not Supported Data Types

Currently following data types are not supported - but can be added if needed in future versions:

Integrate new Data Type

Extend Filters in the Result Tab

If you want custom filters in the result tab directly without having to create a new advanced object search every time read here on how to extend the result tab with custom filters.