Skip to content

Commit

Permalink
Merge pull request #930 from algolia/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Jan Petr authored Oct 24, 2017
2 parents 2201ddd + e1767d5 commit c91305c
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 18 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
## CHANGE LOG

### 1.12.0

Since this release, the extension is **Enterprise Edition compliant**!

## FEATURES
- Experimental feature to prevent backend rendering of category and search results pages (#886)
- Use very carefully and read [documentation](https://community.algolia.com/magento/doc/m1/prevent-backend-rendering/) before enabling it
- Introduced events and developer attributes to force add / remove product(s) to / from Algolia (#922)
- Added to option to turn off administration top bar with information about queue (#920)

## UPDATES
- Changed some links in the configuration

## FIXES
- Fixed failing database migration for creation of queue log table (#927)

### 1.11.1

- Query rules are preserved during reindex with indexing queue enabled (#913)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Algolia Search for Magento 1.6+
==================

![Latest version](https://img.shields.io/badge/latest-1.11.1-green.svg)
![Latest version](https://img.shields.io/badge/latest-1.12.0-green.svg)

[![Build Status](https://travis-ci.org/algolia/algoliasearch-magento.svg?branch=master)](https://travis-ci.org/algolia/algoliasearch-magento)
![PHP >= 5.3](https://img.shields.io/badge/php-%3E=5.3-green.svg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ public function getConfigurationUrl()
return $this->getUrl('adminhtml/system_config/edit/section/algoliasearch');
}

public function showNotification()
{
/** @var Algolia_Algoliasearch_Helper_Config $config */
$config = Mage::helper('algoliasearch/config');

return $config->showQueueNotificiation();
}

public function getQueueInfo()
{
/** @var Algolia_Algoliasearch_Helper_Config $config */
Expand Down
16 changes: 10 additions & 6 deletions app/code/community/Algolia/Algoliasearch/Helper/Algoliahelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class Algolia_Algoliasearch_Helper_Algoliahelper extends Mage_Core_Helper_Abstra
/** @var Algolia_Algoliasearch_Helper_Config */
protected $config;

/** @var int */
protected $maxRecordSize = 20000;

/** @var array */
protected $potentiallyLongAttributes = array('description', 'short_description', 'meta_description', 'content');

/** @var string */
private $lastUsedIndexName;

Expand Down Expand Up @@ -287,26 +293,24 @@ private function prepareRecords(&$objects, $indexName)
if (!empty($modifiedIds)) {
/** @var Mage_Adminhtml_Model_Session $session */
$session = Mage::getSingleton('adminhtml/session');
$session->addWarning('Algolia reindexing : You have some records ('.implode(',', $modifiedIds).') that are too big. They have either been truncated or skipped');
$session->addWarning('Algolia reindexing : You have some records ('.implode(',', $modifiedIds).') that are too big. They have either been truncated or skipped.');
}
}

public function handleTooBigRecord(&$object)
{
$longAttributes = array('description', 'short_description', 'meta_description', 'content');

$size = mb_strlen(json_encode($object));

if ($size > 20000) {
foreach ($longAttributes as $attribute) {
if ($size > $this->maxRecordSize) {
foreach ($this->potentiallyLongAttributes as $attribute) {
if (isset($object[$attribute])) {
unset($object[$attribute]);
}
}

$size = mb_strlen(json_encode($object));

if ($size > 20000) {
if ($size > $this->maxRecordSize) {
$object = false;
}
}
Expand Down
37 changes: 37 additions & 0 deletions app/code/community/Algolia/Algoliasearch/Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ class Algolia_Algoliasearch_Helper_Config extends Mage_Core_Helper_Abstract
const CUSTOMER_GROUPS_ENABLE = 'algoliasearch/advanced/customer_groups_enable';
const MAKE_SEO_REQUEST = 'algoliasearch/advanced/make_seo_request';
const REMOVE_BRANDING = 'algoliasearch/advanced/remove_branding';
const SHOW_QUEUE_NOTIFICATION = 'algoliasearch/advanced/show_queue_notification';
const AUTOCOMPLETE_SELECTOR = 'algoliasearch/advanced/autocomplete_selector';
const INDEX_PRODUCT_ON_CATEGORY_PRODUCTS_UPDATE = 'algoliasearch/advanced/index_product_on_category_products_update';
const INDEX_ALL_CATEGORY_PRODUCTS_ON_CATEGORY_UPDATE = 'algoliasearch/advanced/index_all_category_product_on_category_update';
const PREVENT_BACKEND_RENDERING = 'algoliasearch/advanced/prevent_backend_rendering';
const BACKEND_RENDERING_ALLOWED_USER_AGENTS = 'algoliasearch/advanced/backend_rendering_allowed_user_agents';

const SHOW_OUT_OF_STOCK = 'cataloginventory/options/show_out_of_stock';
const LOGGING_ENABLED = 'algoliasearch/credentials/debug';
Expand Down Expand Up @@ -244,6 +247,11 @@ public function isRemoveBranding($storeId = null)
return Mage::getStoreConfigFlag(self::REMOVE_BRANDING, $storeId);
}

public function showQueueNotificiation($storeId = null)
{
return Mage::getStoreConfigFlag(self::SHOW_QUEUE_NOTIFICATION, $storeId);
}

public function getMaxValuesPerFacet($storeId = null)
{
return Mage::getStoreConfig(self::MAX_VALUES_PER_FACET, $storeId);
Expand Down Expand Up @@ -633,6 +641,35 @@ public function getExtraSettings($section, $storeId = null)
return trim(Mage::getStoreConfig(constant('self::'.$constant), $storeId));
}

public function preventBackendRendering($storeId = null)
{
$preventBackendRendering = Mage::getStoreConfigFlag(self::PREVENT_BACKEND_RENDERING, $storeId);

if ($preventBackendRendering === false) {
return false;
}

$userAgent = mb_strtolower($_SERVER['HTTP_USER_AGENT'], 'utf-8');

$allowedUserAgents = Mage::getStoreConfig(self::BACKEND_RENDERING_ALLOWED_USER_AGENTS, $storeId);
$allowedUserAgents = trim($allowedUserAgents);

if ($allowedUserAgents === '') {
return true;
}

$allowedUserAgents = explode("\n", $allowedUserAgents);

foreach ($allowedUserAgents as $allowedUserAgent) {
$allowedUserAgent = mb_strtolower($allowedUserAgent, 'utf-8');
if (strpos($userAgent, $allowedUserAgent) !== false) {
return false;
}
}

return true;
}

private function getCustomRanking($configName, $storeId = null)
{
$attrs = unserialize(Mage::getStoreConfig($configName, $storeId));
Expand Down
13 changes: 11 additions & 2 deletions app/code/community/Algolia/Algoliasearch/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,16 @@ protected function getProductsRecords($storeId, $collection, $potentiallyDeleted
unset($potentiallyDeletedProductsIds[$productId]);
}

Mage::dispatchEvent('algolia_before_product_availability_check', array('product' => $product, 'store' => $storeId));

if ($product->getData('algolia__noIndex') === true) {
$productsToRemove[$productId] = $productId;
}

if ($product->getData('algolia__alwaysIndex') === true) {
$productsToIndex[$productId] = $this->product_helper->getObject($product);
}

if (isset($productsToIndex[$productId]) || isset($productsToRemove[$productId])) {
continue;
}
Expand All @@ -489,8 +499,7 @@ protected function getProductsRecords($storeId, $collection, $potentiallyDeleted
continue;
}

$productObject = $this->product_helper->getObject($product);
$productsToIndex[$productId] = $productObject;
$productsToIndex[$productId] = $this->product_helper->getObject($product);
}

$productsToRemove = array_merge($productsToRemove, $potentiallyDeletedProductsIds);
Expand Down
4 changes: 4 additions & 0 deletions app/code/community/Algolia/Algoliasearch/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public function useAlgoliaSearchPopup(Varien_Event_Observer $observer)
} else {
$observer->getLayout()->getUpdate()->addHandle('algolia_search_handle_no_topsearch');
}

if ($this->config->preventBackendRendering() === true) {
$observer->getLayout()->getUpdate()->addHandle('algolia_search_handle_prevent_backend_rendering');
}
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion app/code/community/Algolia/Algoliasearch/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<Algolia_Algoliasearch>
<version>1.11.1</version>
<version>1.12.0</version>
</Algolia_Algoliasearch>
</modules>
<frontend>
Expand Down Expand Up @@ -246,9 +246,13 @@
<partial_update>0</partial_update>
<make_seo_request>1</make_seo_request>
<remove_branding>0</remove_branding>
<show_queue_notification>1</show_queue_notification>
<autocomplete_selector>.algolia-search-input</autocomplete_selector>
<index_product_on_category_products_update>1</index_product_on_category_products_update>
<index_all_category_product_on_category_update>0</index_all_category_product_on_category_update>
<prevent_backend_rendering>0</prevent_backend_rendering>
<backend_rendering_allowed_user_agents>Googlebot
Bingbot</backend_rendering_allowed_user_agents>
</advanced>
<product_map>
<!--
Expand Down
49 changes: 44 additions & 5 deletions app/code/community/Algolia/Algoliasearch/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<algoliasearch translate="label" module="algoliasearch">
<label>
<![CDATA[
Algolia Search 1.11.1
Algolia Search 1.12.0
<style>
.algoliasearch-admin-menu span {
padding-left: 38px !important;
Expand Down Expand Up @@ -939,7 +939,7 @@
<table>
<tr>
<td>Synonyms documentation:</td>
<td><a target="_blank" href="https://www.algolia.com/doc/synonyms/?utm_source=magento&utm_medium=extension&utm_campaign=magento_1&utm_term=shop-owner&utm_content=doc-link">https://www.algolia.com/doc/synonyms</a></td>
<td><a target="_blank" href="https://www.algolia.com/doc/guides/textual-relevance/synonyms/?utm_source=magento&utm_medium=extension&utm_campaign=magento_1&utm_term=shop-owner&utm_content=doc-link">https://www.algolia.com/doc/guides/textual-relevance/synonyms/</a></td>
</tr>
</table>
<br>
Expand Down Expand Up @@ -975,7 +975,7 @@
Synonyms are defined by a comma-separated list of words that should be considered equivalent by the Algolia engine.<br>
For instance: <code>tv, television, tv set</code><br>
Using that set, if a record contains “television” and a user searches for “TV”, this record will be returned.<br>
Documentation: <a href="https://www.algolia.com/doc/synonyms#synonyms" target="_blank">https://www.algolia.com/doc/synonyms#synonyms</a>
Documentation: <a href="https://www.algolia.com/doc/guides/textual-relevance/synonyms/#regular-synonyms" target="_blank">https://www.algolia.com/doc/guides/textual-relevance/synonyms/#regular-synonyms</a>
]]>
</comment>
</synonyms>
Expand All @@ -992,7 +992,7 @@
One-way synonyms allow you to define alternative words for a search term, which are not synonyms to each others.<br>
Let’s take an example: when a user searches for “tablet”, you want him to be able to find iPads and Galaxy Note tablets alike, but you might not want Android tablets to show up when he searches for “iPad”.<br>
To do this, you’d define a one-way synonyms set between <code>tablet</code> (as input) and <code>ipad, galaxy note</code> (as synonyms). When the user types in “tablet”, records containing “iPad” and “Galaxy Note” will be returned. However records containing only “tablet” or “Galaxy Note” won’t be returned if he searches for “iPad”.<br>
Documentation: <a href="https://www.algolia.com/doc/synonyms#one-way-synonyms" target="_blank">https://www.algolia.com/doc/synonyms#one-way-synonyms</a>
Documentation: <a href="https://www.algolia.com/doc/guides/textual-relevance/synonyms/#one-way-synonyms" target="_blank">https://www.algolia.com/doc/guides/textual-relevance/synonyms/#one-way-synonyms</a>
<br>
<br>
Algolia offers more synonymys’ types - placeholders and alternative corrections. These types can be managed directly from your <a href="https://www.algolia.com/dashboard" target="_blank">Algolia’s dashboard</a>.
Expand Down Expand Up @@ -1093,6 +1093,15 @@
<show_in_store>1</show_in_store>
<comment>Choose here if the algolia logo is added to the drop-down template.</comment>
</remove_branding>
<show_queue_notification translate="label comment">
<label>Show queue information panel in administration header</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>45</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</show_queue_notification>
<autocomplete_selector translate="label comment">
<label>Search input DOM Selector</label>
<frontend_type>text</frontend_type>
Expand Down Expand Up @@ -1134,6 +1143,36 @@
]]>
</comment>
</index_all_category_product_on_category_update>
<prevent_backend_rendering translate="label comment">
<label>Prevent backend rendering?</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>90</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment>
<![CDATA[
<span class="algolia-config-warning">&#9888;</span>
By preventing your store from backend rendering you might break your SEO and accessibility of your store by search crawlers. Please, read documentation before you turn the backend rendering off:
<a target="_blank" href="https://community.algolia.com/magento/doc/m1/prevent-backend-rendering/?utm_source=magento&utm_medium=extension&utm_campaign=magento_1&utm_term=shop-owner&utm_content=doc-link">Prevent Backend Rendering documentation</a>
]]>
</comment>
</prevent_backend_rendering>
<backend_rendering_allowed_user_agents translate="label comment">
<label>Allow backend rendering for User Agents:</label>
<frontend_type>textarea</frontend_type>
<sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment>
<![CDATA[
To specify multiple User-Agents, please put one User-Agent per line.
]]>
</comment>
<depends><prevent_backend_rendering>1</prevent_backend_rendering></depends>
</backend_rendering_allowed_user_agents>
</fields>
</advanced>
<advanced_settings translate="label">
Expand All @@ -1153,7 +1192,7 @@
Example: <code>{"exactOnSingleWordQuery":"word"}</code>
</p>
<p>List of possible settings: <a href="https://www.algolia.com/doc/api-client/default/settings/#index-settings-parameters" target="_blank">https://www.algolia.com/doc/api-client/default/settings/#index-settings-parameters</a></p>
<p>List of possible settings: <a href="https://www.algolia.com/doc/api-reference/settings-api-parameters/#index-settings-parameters" target="_blank">https://www.algolia.com/doc/api-reference/settings-api-parameters/#index-settings-parameters</a></p>
<p><span class="algolia-config-warning">&#9888;</span> Edit extra settings only when you're sure what you're doing. Bad settings can effect your search functionality and have a bad impact on your relevance.</p>
]]>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

// This migration is the same to 1.11.1
// That one didn't work when migrating from newer versions then 1.7.1

/** @var Mage_Core_Model_Resource_Setup $installer */
$installer = $this;
$installer->startSetup();

$tableName = $installer->getTable('algoliasearch/queue');

$installer->getConnection()->addColumn($tableName, 'created', array(
'type' => Varien_Db_Ddl_Table::TYPE_DATETIME,
'after' => 'job_id',
'nullable' => true,
'comment' => 'Time of job creation',
));

$installer->run("
CREATE TABLE IF NOT EXISTS `{$tableName}_log` (
`id` INT(20) NOT NULL auto_increment,
`started` DATETIME NOT NULL,
`duration` INT(20) NOT NULL,
`processed_jobs` INT NOT NULL,
`with_empty_queue` INT(1) NOT NULL,
PRIMARY KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8 AUTO_INCREMENT=1;
");

$installer->endSetup();
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

/** @var Algolia_Algoliasearch_Block_Adminhtml_Notifications $this */

if ($this->showNotification() === false) {
return;
}

$queueInfo = $this->getQueueInfo();

?>
Expand Down
22 changes: 22 additions & 0 deletions app/design/frontend/base/default/layout/algoliasearch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,26 @@
<block type="core/template" template="algoliasearch/autocomplete.phtml" name="algolia-autocomplete"/>
</reference>
</algolia_search_handle_no_topsearch>

<algolia_search_handle_prevent_backend_rendering>
<reference name="left_first">
<action method="unsetChild"><name>catalog.leftnav</name></action>
<action method="unsetChild"><name>catalogsearch.leftnav</name></action>
</reference>

<reference name="left">
<action method="unsetChild"><name>tags_popular</name></action>
</reference>

<reference name="content">
<action method="unsetChild"><name>category.products</name></action>
<action method="unsetChild"><name>search.result</name></action>
</reference>

<reference name="right">
<action method="unsetChild"><name>right.reports.product.viewed</name></action>
<action method="unsetChild"><name>left.reports.product.viewed</name></action>
<action method="unsetChild"><name>right.poll</name></action>
</reference>
</algolia_search_handle_prevent_backend_rendering>
</layout>
2 changes: 1 addition & 1 deletion app/etc/modules/Algolia_Algoliasearch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Algolia_Algoliasearch>
<active>true</active>
<codePool>community</codePool>
<version>1.11.1</version>
<version>1.12.0</version>
</Algolia_Algoliasearch>
</modules>
</config>
Loading

0 comments on commit c91305c

Please sign in to comment.