Coder Social home page Coder Social logo

debascoguy / searchengine Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 1.0 37.91 MB

A Php - MySql Search Engine. Considering the challenges of using MySQL/MSSQL/SQL as a back-end database management tool for large enterprise/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.

License: GNU General Public License v2.0

PHP 100.00%
php search-engine search-in-text search-interface searching-algorithms searching mysql mssql sql

searchengine's Introduction

SearchEngine

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);

searchengine's People

Contributors

debascoguy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

impatidar

searchengine's Issues

Can't test

First: great work!
This package is huge... Actually beacuse of this it I can really feel the lack of a documentation...
It would be great to have this package installable via composer, but maybe I'll open another issue for this (I could even help for this!).

Meanwhile I was curious to test this but I really don't know where to start and I tried to open the example.php file, but of course I don't have the "test_database" in my mysql db.

So, would it be possible to add a sql file with the exported "text_database" example db for testing the library and trying to understand how it works?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.