0

I have integrated Solr with Magento EE. Solr logs whatever I search in Magento fronted search box.

I'd like to know if Magento will also use Solr engine if the search REST API is called?

Endpoints-

Product Details - GET- http://<magento_host>/rest/V1/products/:sku

Get Category - GET - http://<magento_host>//V1/categories/:categoryId

General Search API - GET

http://<magento_host>/rest/V1/products/?
searchCriteria[filter_groups][0][filters][0][field]=category_gear&
searchCriteria[filter_groups][0][filters][0][value]=86&
searchCriteria[filter_groups][0][filters][0][condition_type]=finset

and the API's mentioned here http://devdocs.magento.com/guides/v2.0/howdoi/webapi/search-criteria.html

4
  • Can you precise the search REST API for you ? Send me the endpoint. Commented May 18, 2017 at 7:19
  • @FranckGarnier Added endpoints for your reference.
    – blakcaps
    Commented May 18, 2017 at 9:25
  • For me, no these endpoints do not use the search engine. Commented May 18, 2017 at 9:45
  • @FranckGarnier Can you shed some more information how to check if endpoints hitting solr. Is this the default behavior of Magento endpoints even if search engine like solr installed
    – blakcaps
    Commented May 18, 2017 at 9:51

1 Answer 1

1
+50

The search API is located here :

vendor/magento/module-search/etc/webapi.xml

<route url="/V1/search" method="GET">
    <service class="Magento\Search\Api\SearchInterface" method="search"/>
    <resources>
        <resource ref="anonymous" />
    </resources>
</route>

vendor/magento/framework/Search/Search.php

/**
 * {@inheritdoc}
 */
public function search(SearchCriteriaInterface $searchCriteria)
{
    $this->requestBuilder->setRequestName($searchCriteria->getRequestName());

    $scope = $this->scopeResolver->getScope()->getId();
    $this->requestBuilder->bindDimension('scope', $scope);

    foreach ($searchCriteria->getFilterGroups() as $filterGroup) {
        foreach ($filterGroup->getFilters() as $filter) {
            $this->addFieldToFilter($filter->getField(), $filter->getValue());
        }
    }

    $this->requestBuilder->setFrom($searchCriteria->getCurrentPage() * $searchCriteria->getPageSize());
    $this->requestBuilder->setSize($searchCriteria->getPageSize());
    $request = $this->requestBuilder->create();
    $searchResponse = $this->searchEngine->search($request);

    return $this->searchResponseBuilder->build($searchResponse)
        ->setSearchCriteria($searchCriteria);
}

So you can use existing search defined in the search_request.xml files or build your own search requests.

Example for catalogsearch used on the Magento FO : vendor/magento/module-catalog-search/etc/search_request.xml

Then you can extend the SearchEngine module to add new search features such as autocomplete.

Moreover you can see that other API calls such as /V1/products/:sku do not use Search Engine but repository with Mysql request behind :

vendor/magento/module-catalog/etc/webapi.xml

<route url="/V1/products/:sku" method="GET">
    <service class="Magento\Catalog\Api\ProductRepositoryInterface" method="get"/>
    <resources>
        <resource ref="Magento_Catalog::products" />
    </resources>
</route>

vendor/magento/module-catalog/Model/ProductRepository.php

/**
 * {@inheritdoc}
 */
public function get($sku, $editMode = false, $storeId = null, $forceReload = false)
{
    $cacheKey = $this->getCacheKey([$editMode, $storeId]);
    if (!isset($this->instances[$sku][$cacheKey]) || $forceReload) {
        $product = $this->productFactory->create();

        $productId = $this->resourceModel->getIdBySku($sku);
        if (!$productId) {
            throw new NoSuchEntityException(__('Requested product doesn\'t exist'));
        }
        if ($editMode) {
            $product->setData('_edit_mode', true);
        }
        if ($storeId !== null) {
            $product->setData('store_id', $storeId);
        }
        $product->load($productId);
        $this->instances[$sku][$cacheKey] = $product;
        $this->instancesById[$product->getId()][$cacheKey] = $product;
    }
    return $this->instances[$sku][$cacheKey];
}

And by the way I recommended ElasticSearch with Magento EE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.