定制 emma/searchengine 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

emma/searchengine

Composer 安装命令:

composer require emma/searchengine

包简介

Php - MySql/SQL Search Engine. Considering the challenges in using MySQL/MSSQL/SQL as a back-end for industrial level application search-engine. An optimized techniques and algorithms are developed to boost performance and make SQL databases works like magic for the purpose of searching.

README 文档

README

A Php - MySql Search Engine. Considering the challenges in using MySQL/MSSQL/SQL as a back-end for industrial level application search-engine. An optimized techniques and algorithms are developed to boost performance and make SQL databases works like magic for the purpose of searching.

HOW TO USE

Please see the example in the package after downloading for a fast understanding of how to deploy the library.

SAME EXAMPLE BELOW

error_reporting(E_ALL ^ E_NOTICE);

include dirname(FILE) . DIRECTORY_SEPARATOR . "autoloader.php";

/**

  • Sample Database From:
  • https://github.com/datacharmer/test_db
  • If using XAMPP and on WINDOWS:
    1. Create an empty database: 'employees'
    1. Use the test_db.sql in this repository as I have already helped edit the employees.sql file for ease of import.
    1. Then, Open Command Line (Windows)
    1. cd c:\xampp\mysql\bin
    1. C:\xampp\mysql\bin> mysql -u {username} -p {databasename} < file_name.sql

*/

/**

  • CREATE MYSQL CONNECTION */ $connection = SearchEngine\SQL\PDOConnection::getInstance(new SearchEngine\SQL\ConnectionProperty("localhost", "root", "", "employees"));

/**

  • EXAMPLE 1: fulltext search example: First, run this SQL on your employees Database:
  • ALTER TABLE employees ADD FULLTEXT(first_name, last_name);
  • ===================================================================================================================== */

/** SEARCH STRING : The strings to be search inside the database (Boolean Search). */ $searchString = "Georgi OR Paddy OR King NOT Gregory";

$SqlLoadDB = new SearchEngine\SQL\SqlLoadDB( $connection, (new SearchEngine\SQL\QueryBuilder())->setTableName("employees"), new SearchEngine\SentenceAnalyzer\MysqlFullText( $searchString, ["employees.first_name", "employees.last_name"], SearchEngine\SentenceAnalyzer\MysqlFullText::IN_BOOLEAN_MODE ) );

//Now, Search $searchEngine = new SearchEngine\SearchEngine(); $searchEngine->add($SqlLoadDB) // Register a callback on the Search Engine before viewing of final results (Optional)... ->registerResultCallBack(function ($searchResult) { while (count($searchResult) < 4095) { //Simply duplicate the search to increase the total number of result... //Just an example of how to add an inline callback. $result2 = $searchResult; $searchResult = array_merge($searchResult, $result2); } return $searchResult; });

$result = $searchEngine->search()->getResult();

/**

  • EXAMPLE 2 : Test of Using Multiple DataSource By creating another SqlLoadDB()
  • ===================================================================================================================== */

/** USING QUERY BUILDER TO BUILD YOUR SEARCH QUERY... / $mysqlQueryBuilder = new SearchEngine\SQL\QueryBuilder(); $mysqlQueryBuilder->select(array( /* employees.first_name As employeesfirst_name : Use this if duplicate column exist. */ "employees.first_name" => "First Name", "employees.emp_no" => "Employee Number", "employees.birth_date", "employees.hire_date", ))->from("employees") ->leftJoin("dept_emp", "dept_emp.emp_no = employees.emp_no") ->where("employees.first_name IN ('Georgi', 'Paddy', 'King')") ->andWhere("employees.first_name NOT IN ('Gregory')")

/** Another Method of Adding Single Column to select() Field-list While also testing the Mysql UNION function */
->union()
->selectColumn("employees.first_name", "First Name")
->selectColumn("employees.emp_no", "Employee Number")
->selectColumn("employees.birth_date")
->selectColumn("employees.hire_date")
->from("employees")
->leftJoin("dept_emp", "dept_emp.emp_no = employees.emp_no")
->where("employees.first_name IN ('Georgi', 'Paddy', 'King')")
->andWhere("employees.first_name NOT IN ('Gregory')");

$SqlLoadDB2 = new SearchEngine\SQL\SqlLoadDB( $connection, $mysqlQueryBuilder, new SearchEngine\SentenceAnalyzer\SqlLike($searchString) ); //Now, Search $searchEngine = $searchEngine->reset(); $searchEngine->add($SqlLoadDB2)->registerResultCallBack(function ($searchResult) { while (count($searchResult) < 4095) { $result2 = $searchResult; $searchResult = array_merge($searchResult, $result2); } return $searchResult; }); $result2 = $searchEngine->search()->getResult();

/**

  • EXAMPLE 3: File System Searching... / /* @var SearchEngine\FileSystem\SearchOption $fileSystemDataSource / $fileSystemDataSource = new SearchEngine\FileSystem\SearchOption( dirname(FILE). DIRECTORY_SEPARATOR . "dictionary", /* >> This can be either file or directory ==>> */ "BASIC" ); $fileSystemDataSource->setGroupResultByFilePath(true); $fileSystemLoadDB = new SearchEngine\FileSystem\CtrlF($fileSystemDataSource); //Now, Search $searchEngine = $searchEngine->reset(); $result3 = $searchEngine->add($fileSystemLoadDB)->search()->getResult();

echo "

EXAMPLE 1 - SEARCH RESULT

"; var_dump($result); echo "

EXAMPLE 2 - SEARCH RESULT

"; var_dump($result2); echo "

EXAMPLE 3 - SEARCH RESULT

"; var_dump($result3);

统计信息

  • 总下载量: 32
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-only
  • 更新时间: 2022-02-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固