Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit cd7f1e1

Browse files
1.9
* [+] showMeta moved to SphinxToolkitHelper * [+] `::spql_getDataSet()`
1 parent 3c9f7a7 commit cd7f1e1

File tree

4 files changed

+82
-66
lines changed

4 files changed

+82
-66
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.gitignonre export-ignore
2+
README*.* export-ignore

TODO.md

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

src/SphinxToolkit.php

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Closure;
66
use Exception;
7+
use Foolz\SphinxQL\Drivers\ConnectionInterface;
78
use Foolz\SphinxQL\Exception\ConnectionException;
89
use Foolz\SphinxQL\Exception\SphinxQLException;
910
use PDO;
@@ -317,7 +318,7 @@ public function checkIndexExist(string $sphinx_index)
317318
*/
318319
private static $spql_connection_port;
319320
/**
320-
* @var Connection
321+
* @var ConnectionInterface
321322
*/
322323
private static $spql_connection;
323324

@@ -523,6 +524,79 @@ public static function rt_RebuildAbstractIndex(PDO $pdo_connection, string $sql_
523524
return $total_updated;
524525
}
525526

527+
528+
/**
529+
*
530+
*
531+
* @param string $search_query
532+
* @param string $source_index
533+
* @param string $sort_field
534+
* @param string $sort_order
535+
* @param int $limit
536+
* @param array $option_weight
537+
* @return array
538+
*
539+
* @throws ConnectionException
540+
* @throws DatabaseException
541+
* @throws SphinxQLException
542+
*/
543+
public static function spql_getDataSet(string $search_query, string $source_index, string $sort_field, string $sort_order = 'DESC', int $limit = 5, array $option_weight = []): array
544+
{
545+
$found_dataset = [];
546+
$compiled_request = '';
547+
548+
if (empty($source_index)) return $found_dataset;
549+
550+
try {
551+
$search_request = self::createInstance()
552+
->select()
553+
->from($source_index);
554+
555+
if (!empty($sort_field)) {
556+
$search_request = $search_request
557+
->orderBy($sort_field, $sort_order);
558+
}
559+
560+
if (!empty($option_weight)) {
561+
$search_request = $search_request
562+
->option('field_weights', $option_weight);
563+
}
564+
565+
if (!is_null($limit) && is_numeric($limit)) {
566+
$search_request = $search_request
567+
->limit($limit);
568+
}
569+
570+
if (strlen($search_query) > 0) {
571+
$search_request = $search_request
572+
->match(['title'], $search_query);
573+
}
574+
575+
$search_result = $search_request->execute();
576+
577+
while ($row = $search_result->fetchAssoc()) {
578+
$found_dataset[] = $row['id'];
579+
}
580+
581+
} catch (Exception $e) {
582+
583+
$meta = SphinxToolkitHelper::showMeta(self::$spql_connection);
584+
585+
self::$spql_logger->error(
586+
__CLASS__ . '/' . __METHOD__ .
587+
" Error fetching data from `{$source_index}` : " . $e->getMessage(),
588+
[
589+
$e->getCode(),
590+
htmlspecialchars(urldecode($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])),
591+
$search_request->getCompiled(),
592+
$meta
593+
]
594+
);
595+
}
596+
return $found_dataset;
597+
} // get_IDs_DataSet()
598+
599+
526600
/**
527601
*
528602
* @param string $index_name

traits/SphinxToolkitHelper.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,17 @@ public static function EmulateBuildExcerpts($source, $needle, $options)
238238
/**
239239
*
240240
* @param ConnectionInterface $connection
241+
* @return array
242+
*
241243
* @throws \Foolz\SphinxQL\Exception\ConnectionException
242244
* @throws \Foolz\SphinxQL\Exception\DatabaseException
243245
* @throws \Foolz\SphinxQL\Exception\SphinxQLException
244246
*/
245247
public static function showMeta(ConnectionInterface $connection)
246248
{
247-
(new Helper($connection))->showMeta()->execute()->fetchAllAssoc();
249+
return (new Helper($connection))->showMeta()->execute()->fetchAllAssoc();
248250
}
249251

252+
253+
250254
}

0 commit comments

Comments
 (0)