Skip to content

Commit 747137b

Browse files
committed
Merge branch 'tests'
2 parents 8370ba1 + 5c2d798 commit 747137b

File tree

11 files changed

+92
-83
lines changed

11 files changed

+92
-83
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
This is a free extension to integrate Solr as a product search in an online store running on Magento Community
55
Edition 1.7 - 1.9.
66

7+
## Build Status (master)
8+
9+
[![wercker status](https://app.wercker.com/status/2ae00efb6f4d235c8685de56bb4dafc6/m/master "wercker status")](https://app.wercker.com/project/byKey/2ae00efb6f4d235c8685de56bb4dafc6)
10+
711
## Features
812

913
### Fast Search Results

src/app/code/community/IntegerNet/Solr/Model/Bridge/LazyCategoryIterator.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class IntegerNet_Solr_Model_Bridge_LazyCategoryIterator implements CategoryItera
4242
*/
4343
protected $_collectionIterator;
4444

45+
/**
46+
* @var IntegerNet_Solr_Model_Resource_Db
47+
*/
48+
protected $_dbResource;
49+
4550
/**
4651
* @link http://php.net/manual/en/outeriterator.getinneriterator.php
4752
* @return Iterator The inner iterator for the current entry.
@@ -63,6 +68,7 @@ public function __construct($_storeId, $_categoryIdFilter, $_categorySize)
6368
$this->_storeId = $_storeId;
6469
$this->_categoryIdFilter = $_categoryIdFilter;
6570
$this->_categorySize = $_categorySize;
71+
$this->_dbResource = Mage::getResourceModel('integernet_solr/db');
6672
}
6773

6874
/**
@@ -92,6 +98,7 @@ public function valid()
9298
} elseif ($this->_currentCategory < $this->_collection->getLastPageNumber()) {
9399
$this->_currentCategory++;
94100
$this->_collection = self::getCategoryCollection($this->_storeId, $this->_categoryIdFilter, $this->_categorySize, $this->_currentCategory);
101+
$this->_dbResource->disconnectMysql();
95102
$this->_collectionIterator = $this->_collection->getIterator();
96103
$this->getInnerIterator()->rewind();
97104
return $this->getInnerIterator()->valid();
@@ -106,6 +113,7 @@ public function rewind()
106113
{
107114
$this->_currentCategory = 1;
108115
$this->_collection = self::getCategoryCollection($this->_storeId, $this->_categoryIdFilter, $this->_categorySize, $this->_currentCategory);
116+
$this->_dbResource->disconnectMysql();
109117
$this->_collectionIterator = $this->_collection->getIterator();
110118
$this->_collectionIterator->rewind();
111119
}

src/app/code/community/IntegerNet/Solr/Model/Bridge/LazyPageIterator.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class IntegerNet_Solr_Model_Bridge_LazyPageIterator implements PageIterator, Out
4242
*/
4343
protected $_collectionIterator;
4444

45+
/**
46+
* @var IntegerNet_Solr_Model_Resource_Db
47+
*/
48+
protected $_dbResource;
49+
4550
/**
4651
* @link http://php.net/manual/en/outeriterator.getinneriterator.php
4752
* @return Iterator The inner iterator for the current entry.
@@ -63,6 +68,7 @@ public function __construct($_storeId, $_pageIdFilter, $_pageSize)
6368
$this->_storeId = $_storeId;
6469
$this->_pageIdFilter = $_pageIdFilter;
6570
$this->_pageSize = $_pageSize;
71+
$this->_dbResource = Mage::getResourceModel('integernet_solr/db');
6672
}
6773

6874
/**
@@ -92,6 +98,7 @@ public function valid()
9298
} elseif ($this->_currentPage < $this->_collection->getLastPageNumber()) {
9399
$this->_currentPage++;
94100
$this->_collection = self::getPageCollection($this->_storeId, $this->_pageIdFilter, $this->_pageSize, $this->_currentPage);
101+
$this->_dbResource->disconnectMysql();
95102
$this->_collectionIterator = $this->_collection->getIterator();
96103
$this->getInnerIterator()->rewind();
97104
return $this->getInnerIterator()->valid();
@@ -106,6 +113,7 @@ public function rewind()
106113
{
107114
$this->_currentPage = 1;
108115
$this->_collection = self::getPageCollection($this->_storeId, $this->_pageIdFilter, $this->_pageSize, $this->_currentPage);
116+
$this->_dbResource->disconnectMysql();
109117
$this->_collectionIterator = $this->_collection->getIterator();
110118
$this->_collectionIterator->rewind();
111119
}

src/app/code/community/IntegerNet/Solr/Model/Bridge/LazyProductIterator.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class IntegerNet_Solr_Model_Bridge_LazyProductIterator implements PagedProductIt
4343
*/
4444
protected $_collectionIterator;
4545

46+
/**
47+
* @var IntegerNet_Solr_Model_Resource_Db
48+
*/
49+
protected $_dbResource;
50+
4651
/**
4752
* @link http://php.net/manual/en/outeriterator.getinneriterator.php
4853
* @return Iterator The inner iterator for the current entry.
@@ -61,6 +66,7 @@ public function __construct($_storeId, ProductIdChunks $productIdChunks)
6166
$this->_bridgeFactory = Mage::getModel('integernet_solr/bridge_factory');
6267
$this->_storeId = $_storeId;
6368
$this->_productIdChunks = $productIdChunks;
69+
$this->_dbResource = Mage::getResourceModel('integernet_solr/db');
6470
}
6571

6672
/**
@@ -100,6 +106,7 @@ public function valid()
100106
} elseif ($this->_currentChunkId < sizeof($this->_productIdChunks) - 1) {
101107
$this->_currentChunkId++;
102108
$this->_collection = self::getProductCollection($this->_storeId, $this->_productIdChunks, $this->_currentChunkId);
109+
$this->_dbResource->disconnectMysql();
103110
$this->_collectionIterator = $this->_collection->getIterator();
104111
$this->getInnerIterator()->rewind();
105112
return $this->validInner();
@@ -114,6 +121,7 @@ public function rewind()
114121
{
115122
$this->_currentChunkId = 0;
116123
$this->_collection = self::getProductCollection($this->_storeId, $this->_productIdChunks, $this->_currentChunkId);
124+
$this->_dbResource->disconnectMysql();
117125
$this->_collectionIterator = $this->_collection->getIterator();
118126
$this->_collectionIterator->rewind();
119127
}
@@ -182,6 +190,7 @@ private function validInner()
182190
{
183191
$valid = $this->getInnerIterator()->valid();
184192
if (! $valid) {
193+
$this->_dbResource->disconnectMysql();
185194
call_user_func($this->_pageCallback, $this);
186195
}
187196
return $valid;
@@ -228,5 +237,4 @@ public function subset($ids)
228237
return $this->_bridgeFactory->createProductIterator($dataCollection);
229238
}
230239

231-
232240
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* integer_net Magento Module
4+
*
5+
* @category IntegerNet
6+
* @package IntegerNet_Solr
7+
* @copyright Copyright (c) 2016 integer_net GmbH (http://www.integer-net.de/)
8+
* @author Fabian Schmengler <fs@integer-net.de>
9+
*/
10+
class IntegerNet_Solr_Model_Resource_Db
11+
{
12+
/**
13+
* Close all open MySQL connections (will be automatically reopened by Magento if used)
14+
*
15+
* Can be called during indexing to prevent wait timeout
16+
*/
17+
public function disconnectMysql()
18+
{
19+
/** @var Zend_Db_Adapter_Abstract $connection */
20+
foreach (Mage::getSingleton('core/resource')->getConnections() as $name => $connection) {
21+
if ($connection instanceof Zend_Db_Adapter_Abstract) {
22+
$connection->closeConnection();
23+
}
24+
}
25+
}
26+
}

src/app/code/community/IntegerNet/Solr/Model/Result.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010
use IntegerNet\Solr\Query\Params\FilterQueryBuilder;
1111
use IntegerNet\Solr\Request\HasFilter;
12-
use IntegerNet\Solr\Request\Request;
1312

1413
class IntegerNet_Solr_Model_Result
1514
{
@@ -24,11 +23,11 @@ class IntegerNet_Solr_Model_Result
2423
/**
2524
* @var $_solrResult null|\IntegerNet\Solr\Resource\SolrResponse
2625
*/
27-
protected $_solrResult = null;
26+
protected $_solrResult;
2827

2928
protected $activeFilterAttributeCodes = array();
3029

31-
function __construct()
30+
public function __construct()
3231
{
3332
$this->_solrRequest = Mage::helper('integernet_solr')->factory()->getSolrRequest();
3433
if ($this->_solrRequest instanceof HasFilter) {
@@ -46,7 +45,7 @@ function __construct()
4645
*/
4746
public function getSolrResult()
4847
{
49-
if (is_null($this->_solrResult)) {
48+
if (null === $this->_solrResult) {
5049
$this->_solrResult = $this->_solrRequest->doRequest($this->activeFilterAttributeCodes);
5150
}
5251

src/app/code/community/IntegerNet/Solr/Test/Config/Config.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class IntegerNet_Solr_Test_Config_Config extends EcomDev_PHPUnit_Test_Case_Confi
1111
{
1212
/**
1313
* @test
14-
* @loadExpections
1514
*/
1615
public function globalConfig()
1716
{
@@ -61,29 +60,4 @@ public function storeConfigShouldContainBaseUrl()
6160
$this->assertEquals(Mage::app()->getStore(1)->getBaseUrl(), $config->getStoreConfig()->getBaseUrl());
6261
}
6362

64-
/**
65-
* The SerializableConfig interface is part of the SolrSuggest package
66-
* @test
67-
*/
68-
public function configShouldBeSerializable()
69-
{
70-
// use different fuzzy config for search and autosuggest to make sure, both are serialized independently
71-
Mage::app()->getStore(1)->setConfig('integernet_solr/fuzzy/is_active', '1');
72-
Mage::app()->getStore(1)->setConfig('integernet_solr/fuzzy/is_active_autosuggest', '0');
73-
74-
/**
75-
* @var $configFromSerialized IntegerNet\Solr\Implementor\Config
76-
*/
77-
$config = Mage::getModel('integernet_solr/config_store', 1);
78-
$configFromSerialized = unserialize(serialize(\IntegerNet\SolrSuggest\Plain\Config::fromConfig($config)));
79-
80-
$this->assertInstanceOf(\IntegerNet\SolrSuggest\Plain\Config::class, $configFromSerialized);
81-
$this->assertEquals($config->getStoreConfig(), $configFromSerialized->getStoreConfig());
82-
$this->assertEquals($config->getGeneralConfig(), $configFromSerialized->getGeneralConfig());
83-
$this->assertEquals($config->getResultsConfig(), $configFromSerialized->getResultsConfig());
84-
$this->assertEquals($config->getFuzzyAutosuggestConfig(), $configFromSerialized->getFuzzyAutosuggestConfig());
85-
$this->assertEquals($config->getFuzzySearchConfig(), $configFromSerialized->getFuzzySearchConfig());
86-
$this->assertEquals($config->getIndexingConfig(), $configFromSerialized->getIndexingConfig());
87-
$this->assertEquals($config->getServerConfig(), $configFromSerialized->getServerConfig());
88-
}
8963
}

src/app/code/community/IntegerNet/Solr/Test/Controller/Category.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/app/code/community/IntegerNet/Solr/Test/Controller/Configuration.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public function shouldShowStatusBlock()
2929
'Solr server configuration is complete.',
3030
'Connection to Solr server established successfully.',
3131
'Test search request issued successfully.',
32-
'You haven\'t entered your license key yet.'
3332
];
3433
foreach ($expectedMessages as $message) {
3534
/*

src/app/code/community/IntegerNet/Solr/Test/Model/Result.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,39 @@ public function shouldUseDefaultParametersWithoutToolbar()
161161
$this->setCurrentStore($storeId);
162162
$result->getSolrResult();
163163
}
164+
/**
165+
* @test
166+
*/
167+
public function shouldExpandPageSizeIfFuzzyIsActive()
168+
{
169+
$storeId = 1;
170+
$query = 'tshirt';
171+
172+
$this->app()->getStore($storeId)->setConfig('integernet_solr/fuzzy/is_active', 1);
173+
$this->app()->getLayout()->unsetBlock('product_list_toolbar');
174+
$searchHelperStub = $this->mockHelper('catalogsearch', ['getQueryText']);
175+
$searchHelperStub->expects($this->any())
176+
->method('getQueryText')
177+
->willReturn($query);
178+
$this->replaceByMock('helper', 'catalogsearch', $searchHelperStub);
179+
180+
$this->_resourceMock->expects($this->exactly(2))
181+
->method('search')
182+
->with(
183+
$storeId,
184+
$this->stringContains($query),
185+
0,
186+
99999,
187+
$this->logicalAnd(
188+
$this->isType('array'),
189+
$this->contains('score desc', true, true),
190+
$this->logicalNot($this->arrayHasKey('rows'))
191+
))
192+
->willReturn($this->_getDummyResponse());
193+
$result = Mage::getModel('integernet_solr/result');
194+
$this->setCurrentStore($storeId);
195+
$result->getSolrResult();
196+
}
164197

165198
/**
166199
* @test

0 commit comments

Comments
 (0)