ePages 7.3.0 - DE_EPAGES/RemoteSearch/API/RemoteSearchImpl.pm

Package DE_EPAGES::RemoteSearch::API::RemoteSearchImpl

High level API used by scripts from the RemoteSearch cartridge

Base
Exporter
@EXPORT_OK
DropAllSearchIndexes
GetOrCreateSearchIndex
IsRemoteSearchActive
MarkShopDirty
RunIfRemoteSearchInitialized
SearchProducts
SearchProductsSqlFallback
UpdateSearchStatistics
GetDestinctSelections
UseSearchInCategoryContext
GetPageSizeForSearch

Functions

DropAllSearchIndexes
GetDestinctSelections
GetOrCreateSearchIndex
GetPageSizeForSearch
IsRemoteSearchActive
MarkShopDirty
RunIfRemoteSearchInitialized
SearchProducts
SearchProductsSqlFallback
UpdateSearchStatistics
UseSearchInCategoryContext

DropAllSearchIndexes

Resets search info on shop and tries to delete the index from the remote search, if needed.

Syntax
DropAllSearchIndexes( $Shop );
DropAllSearchIndexes( $Shop, $DropRemote );
Input
$Shop (object)
Shop
$DropRemote (boolean)
(optional, default: false; set to true, if you want to remove the remote index

GetDestinctSelections

This function filters facet part of search result from function SearchProducts, and return only unique selections or an empty string. For example: Customer is looking for shirt with color black or white, in size XL and should have one pocket. This would result in {"size":"XL", "NumberPockets":"one"}. Color is omitted because more then one value is selected for this facet.

Syntax
GetDestinctSelections( $aFacets );
Example
my $JSONDestinct = GetDestinctSelections( $hResponse->{facets} );
Input
$aFacets (array. ref.)
$hResponse->{facets} from SearchProducts
Return
$JSONDestinct (JSON string)
key value string in JSON format

GetOrCreateSearchIndex

Creates (if necessary) and returns SearchIndex object. Does not set the remote call to index the shop. Use DE_EPAGES::RemoteSearch::API::Object::IndexManager for that.

Syntax
my $SearchIndex = GetOrCreateSearchIndex( $Shop );
Input
$Shop (DE_EPAGES::Shop::API::Object::Shop)
Shop object
Return
$SearchIndex (DE_EPAGES::RemoteSearch::API::Object::SearchIndex)
search index

GetPageSizeForSearch

Return PagerSettings for product search

Syntax
$PageSize = GetPageSizeForSearch( $Shop );
Input
$Shop (DE_EPAGES::Shop::API::Object::Shop)
shop object
Return
$PageSize (integer)
number of products per page

IsRemoteSearchActive

Check if remote search can be used for the shop

Syntax
my $IsUseable = IsRemoteSearchActive( $Shop );
Input
$Shop (DE_EPAGES::Shop::API::Object::Shop)
Shop object
Return
$IsActive (Boolean)
Returns true if System and $Shop flagged have set RemoteSearchEnabled

MarkShopDirty

Mark (existing) search index of $Shop as dirty.

Syntax
MarkShopDirty( $Shop );
Input
$Shop (object DE_EPAGES::Shop::API::Object::Shop)
shop object

RunIfRemoteSearchInitialized

Runs code if remote search is active and RemoteSearchIndex object has been created. Passes RemoteProductSearchIndex object into the sub. Non-fatal Errors get turned into Warnings.

Syntax
RunIfRemoteSearchInitialized( $Shop, $cSub );
Example
RunIfRemoteSearchActive($Shop, sub {
    my ($Search) = @_;
    $Search->updateItems([ $Product ]);
});
Input
$Shop (DE_EPAGES::Shop::API::Object::Shop)
shop
$cSub (ref.code)
code ref

SearchProducts

Execute product search in $Shop. See DE_EPAGES::RemoteSearch::API::Object::SearchParamBuilder for configuration options.

Syntax
SearchProducts( $Shop, $ParamBuilder );
Input
$Shop (DE_EPAGES::Shop::API::Object::Shop)
shop which should be searched
$ParamBuilder (DE_EPAGES::RemoteSearch::API::Object::SearchParamBuilder)
all setttings for search
Return
$ReturnVariable (ref.hash.)
result with object ids and facets data

SearchProductsSqlFallback

This method is deprecated and may be removed in near future!
Construct an PagerSearch, which can execute a product search with SQL. Use of this method should limited to fallback solution if SearchProducts is failing. Keep in mind the SQL fallback execute strict *PATTERN* search, which will lead to heavy load on database and may take long time to yield a result.

Syntax
$Pager = SearchProductsSqlFallback( $Shop, $ParamBuilder );
Input
$Servlet (object)
Servlet of current context
$ParamBuilder (DE_EPAGES::RemoteSearch::API::Object::SearchParamBuilder)
Search options
Return
$Pager (DE_EPAGES::Search::API::Object::PagerSearch)
Pager which can execute an SQL search

UpdateSearchStatistics

Registers the user's search query at our search statistics.

Search services automatically provides a fallback if a query yields to no results. If fallback search kicks in, the results are registered against fallback term.

Syntax
UpdateSearchStatistics( $Shop, $Query, $Results, $Fallback);
Input
$Shop (DE_EPAGES::Shop::API::Object::Shop)
current shop
$Query (string)
user input
$Results (int)
number of results
$Fallback (string)
fallback query, if used (optional)

UseSearchInCategoryContext

The display of search setting tab in MBO is controlled with shop feature 'DetailedSearch'. It is desireable to execute advanced searches only if Merchant can configure them.

Syntax
UseSearchInCategoryContext( $Shop );
Input
$Shop (DE_EPAGES::Shop::API::Object::Shop)
shop object
Return
$HasSettingTab (boolean)
result of $Shop->featureMaxValue('DetailedSearch')