-
Notifications
You must be signed in to change notification settings - Fork 1
/
m_test_search_speed.php
82 lines (75 loc) · 2.93 KB
/
m_test_search_speed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* Mirasvit
*
* This source file is subject to the Mirasvit Software License, which is available at http://mirasvit.com/license/.
* Do not edit or add to this file if you wish to upgrade the to newer versions in the future.
* If you wish to customize this module for your needs.
* Please refer to http://www.magentocommerce.com for more information.
*
* @category Mirasvit
* @package Sphinx Search Ultimate
* @version 2.3.4
* @build 1384
* @copyright Copyright (C) 2017 Mirasvit (http://mirasvit.com/)
*/
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once 'app/Mage.php';
Mage::app();
?>
<div style="width:600px;border:1px solid #e2e2e2;margin:0 auto;padding:20px">
<form action="m_test_search_speed.php" method="get" style="margin: 0 auto;">
<label for="search">Input query here: <input id="search" type="text" name="q" value="<?php echo $_GET['q'] ?>" /></label>
<button type="submit">Search</button>
</form>
<?php if ($query = $_GET['q']): ?>
<?php
try {
$storeId = Mage::app()->getStore()->getId();
$index = Mage::getResourceModel('searchindex/index_collection')
->addFieldToFilter('index_code', array('eq' => 'mage_catalog_product'))
->getFirstItem()
->getIndexInstance();
$engine = Mage::helper('searchindex')->getSearchEngine();
$start = microtime(true);
$result = $engine->query($query, $storeId, $index);
$end = microtime(true);
$resultTime = round($end - $start, 4);
} catch (Exception $e) {
// alternative engine (fulltext)
try {
$start = microtime(true);
$engine = Mage::getModel('searchsphinx/engine_fulltext');
$result = $engine->query($query, $storeId, $index);
$end = microtime(true);
$resultTime = round($end - $start, 4);
goto RESULT;
} catch (Exception $e) {
?>
<div style="border:3px solid red;padding:20px;position:absolute;top:100px;left:10px">
<h1 style="text-align:center;color:red">Exception:</h1>
<pre>
<?php echo $e;
die();
?>
</pre>
</div>
<?php
}
?>
<?php
} ?>
<?php RESULT: ?>
<h3 >Query: "<?php echo htmlentities($query) ?>"</h3>
<p><b>Count:</b> <?php echo count($result) ?></p>
<p><b>Search Speed (seconds): </b> <?php echo $resultTime ?></p>
<h3>Results:</h3>
<table border="1" align="center">
<tr><th>Product ID</th></tr>
<?php foreach ($result as $itemId => $relevance): ?>
<tr><th><?php echo $itemId ?></th></tr>
<?php endforeach ?>
</table>
<?php endif ?>
</div>