Laravel Xunsearch Full Text Search

Source: Internet
Author: User
Tags derick echo date
Before you begin, it is highly recommended to take a look at Xunsearch's official documentation

Xunsearch Introduction

Xunsearch is a high-performance, full-featured full-text retrieval solution.
Xunsearch is designed to help average developers quickly and easily build their own full-text search engine for the massive amounts of data they already have.

Details point I

Test environment:

Linux server 2:

Code function IP system
Server A Provide Web services 192.168.56.2 Centos7
Server B Provide Xunsearch backend Services 192.168.56.3 Centos7

Xunsearch back-end server configuration:

PHP version 7.0.13 no cache installed, production environment recommended installation cache

PHP 7.0.13 (CLI) (Built:dec 13:53:31) (NTS) Copyright (c) 1997-2016 the PHP groupzend Engine v3.0.0, Copyright ( c) 1998-2016 Zend Technologies with    Xdebug v2.5.0, Copyright (c) 2002-2016, by Derick Rethans

Connect to Server B run the following instructions to install, unzip the Xunsearch installation package

wget HTTP://WWW.PHP.CN/TAR-XJF xunsearch-full-latest.tar.bz2

Execute the installation script, follow the prompts, mainly enter the installation directory of the Xunsearch package, and strongly recommend that you plan a directory separately, rather than mixing it into another software catalog.

CD xunsearch-full-1.4.10/sh setup.sh

The installed interface is then displayed, then press ENTER directly and install to the default path.
Then have a cup of coffee and wait a moment. The following installation success prompt appears.

+==========================================+| Welcome to setup xunsearch (full) | | Welcome to the Xunsearch (full version) installer |+------------------------------------------+| Follow the on-screen instructions please | | Follow the on-screen instructions to complete the installation |+==========================================+please specify the installation directory, specify the installation directory (The default is the value in brackets) [/usr/local/xunsearch]:confirm the installation directory please confirm the installation directory:/usr/local/xunsearch [y/n]ychecking Scws ... Noinstalling Scws (1.2.3) ... Extracting SCWS Package ... Configuring SCWS ... compiling & installing SCWS ... Checking Scws dict ... noextracting scws dict file ... Checking libuuid ... no, try to install itextracting libuuid ... Configuring Libuuid ... compiling & installing Libuuid ... Checking Xapian-core-scws ... noinstalling xapian-core-scws (1.2.22) ... Extracting XAPIAN-CORE-SCWS Package ... Configuring XAPIAN-CORE-SCWS ... compiling & installing XAPIAN-CORE-SCWS ... Checking libevent noinstalling libevent (2.0.21-sTable) ... Extracting Libevent Package ... Configuring Libevent ... compiling & installing libevent ... Extracting Xunsearch Package (1.4.10) ... Configuring Xunsearch ... compiling & installing Xunsearch ... Cleaning ... done+=================================================+| Installation completed successfully, Thanks you | | Installation successful, thanks for choosing and using Xunsearch |+-------------------------------------------------+| Notes and precautions: | |    1. Open/re-open the Xunsearch service program with the following command: | |    /usr/local/xunsearch/bin/xs-ctl.sh Restart | |                                                 It is strongly recommended that this command be written to the server boot script | | ||    2. All index data will be stored in the following directory: | |    /usr/local/xunsearch/data | |                                                 If you need to transfer to a different directory, please use a soft link. ||    3. You can now build on the development package (SDK) We provide | |    Develop your own search. | |    Currently only supported in PHP language, see the following documentation: | | /usr/local/xunsearch/sdk/php/readme |+=================================================+ 

注意: 如果是生产环境iptables可能需要配置得严格,本文仅为测试

Configure Iptables, if you are not enabled then ignore this operation

Vi/etc/sysconfig/iptables join, below two lines-a input-p tcp-m state--state new-m TCP--dport 8383-j accept-a input-p tcp-m STA Te--state new-m TCP--dport 8384-j Accept restart Iptablesservice iptables restart

Start the service

/usr/local/xunsearch/bin/xs-ctl.sh-b inet Start

Start the output content:

Info:starting Server[xs-indexd] ... (bind:8383) Info:starting Server[xs-searchd] ... (bind:8384)

Web server Configuration

Installing the Xunsearch PHP SDK

CD Project/root/pathcomposer require--prefer-dist Hightman/xunsearch

Create a Project profile, a project that corresponds to a profile, and the project name cannot be duplicated

CP App\vendor\hightman\xunsearch\app\demo.ini App\config\search-demo.ini

Modify the contents of the file you just created, where the IP address of Server.index and Server.search is the IP address of the server that has the Xunsearch service installed

Search configuration File Example project.name = Demoproject.default_charset = Utf-8server.index = 192.168.56.4:8383server.search = 192.168.56.4:8384[pid]type = Id[subject]type = Title[message]type = Body[chrono]type = Numeric

Modify the app/routes/web.php file, write some client search test code

###################### Test Module ####################/* * Full-Text Search Test section */route::get ('/search/{key} ', function ($key) {$xs = new    XS (Config_path (' Search-demo.ini ')); $search = $xs->search;    Gets the Search object $query = $key;  $search->setquery ($query)->setsort (' Chrono ', true)//Chrono Positive order->setlimit (20,0)//Set Search statement, paging,    The offset amount; $docs = $search->search (); Perform a search to save the search results document in a $docs array $count = $search->count (); Gets the total number of matches for the search result. foreach ($docs as $doc) {$subject = $search->highlight ($doc->subject);//Highlight Subject Word Segment $message = $search->highlight ($doc->message); Highlight the Message field echo $doc->rank (). '. ' . $subject. " [" . $doc->percent ().        "%] - "; echo Date ("y-m-d", $doc->chrono). "<br>". $message.        "<br>";    Echo ' <br>========<br> '; } echo ' total: '. $count;});    Route::get ('/makedoc/{title}/{message} ', function ($title, $message) {$xs = new xs (' demo '); $doc = NEW xsdocument;  $doc->setfields (' pid ' = + 1, ' subject ' and ' = ' $title, ' message ' + $message, ' chrono ' = Time (),]); Use Arrays for batch assignment $xs->index->add ($doc);});

Use the browser to access the above two road test functions

By visiting:/HTTP//your domain/makedoc/title/content Test Build Index

Test examples:

http://Your domain/makedoc/about Xunsearch DEMO Project test/Project test is a very interesting behavior!http://your domain name/makedoc/Test Second/Here is the content of the second article/HTTP/ makedoc/Project Test third/The saying goes, there is no three, so there is a third article

注意: 索引不是即时生效的 延迟大概在10秒左右

By visiting:/HTTP/your domain/search/keyword Test search function
such as search keywords项目

1. DEMO Project test on Xunsearch [99%]-2011-08-26 project test is a very interesting behavior! ========2. Project Test Article III [100%]-2011-08-26 as the saying goes, there is no three, so there is a third article total number of ========: 2

We have completed one of the simplest full-text search examples through the above steps.
If you would like more details, please read the official documentation for Xunsearch.

Reference content

    1. Xunsearch Official documents


Before you begin, it is highly recommended to take a look at Xunsearch's official documentation

Xunsearch Introduction

Xunsearch is a high-performance, full-featured full-text retrieval solution.
Xunsearch is designed to help average developers quickly and easily build their own full-text search engine for the massive amounts of data they already have.

Details point I

Test environment:

Linux server 2:

Code function IP system
Server A Provide Web services 192.168.56.2 Centos7
Server B Provide Xunsearch backend Services 192.168.56.3 Centos7

Xunsearch back-end server configuration:

PHP version 7.0.13 no cache installed, production environment recommended installation cache

PHP 7.0.13 (CLI) (Built:dec 13:53:31) (NTS) Copyright (c) 1997-2016 the PHP groupzend Engine v3.0.0, Copyright ( c) 1998-2016 Zend Technologies with    Xdebug v2.5.0, Copyright (c) 2002-2016, by Derick Rethans

Connect to Server B run the following instructions to install, unzip the Xunsearch installation package

wget HTTP://WWW.PHP.CN/TAR-XJF xunsearch-full-latest.tar.bz2

Execute the installation script, follow the prompts, mainly enter the installation directory of the Xunsearch package, and strongly recommend that you plan a directory separately, rather than mixing it into another software catalog.

CD xunsearch-full-1.4.10/sh setup.sh

The installed interface is then displayed, then press ENTER directly and install to the default path.
Then have a cup of coffee and wait a moment. The following installation success prompt appears.

+==========================================+| Welcome to setup xunsearch (full) | | Welcome to the Xunsearch (full version) installer |+------------------------------------------+| Follow the on-screen instructions please | | Follow the on-screen instructions to complete the installation |+==========================================+please specify the installation directory, specify the installation directory (The default is the value in brackets) [/usr/local/xunsearch]:confirm the installation directory please confirm the installation directory:/usr/local/xunsearch [y/n]ychecking Scws ... Noinstalling Scws (1.2.3) ... Extracting SCWS Package ... Configuring SCWS ... compiling & installing SCWS ... Checking Scws dict ... noextracting scws dict file ... Checking libuuid ... no, try to install itextracting libuuid ... Configuring Libuuid ... compiling & installing Libuuid ... Checking Xapian-core-scws ... noinstalling xapian-core-scws (1.2.22) ... Extracting XAPIAN-CORE-SCWS Package ... Configuring XAPIAN-CORE-SCWS ... compiling & installing XAPIAN-CORE-SCWS ... Checking libevent noinstalling libevent (2.0.21-sTable) ... Extracting Libevent Package ... Configuring Libevent ... compiling & installing libevent ... Extracting Xunsearch Package (1.4.10) ... Configuring Xunsearch ... compiling & installing Xunsearch ... Cleaning ... done+=================================================+| Installation completed successfully, Thanks you | | Installation successful, thanks for choosing and using Xunsearch |+-------------------------------------------------+| Notes and precautions: | |    1. Open/re-open the Xunsearch service program with the following command: | |    /usr/local/xunsearch/bin/xs-ctl.sh Restart | |                                                 It is strongly recommended that this command be written to the server boot script | | ||    2. All index data will be stored in the following directory: | |    /usr/local/xunsearch/data | |                                                 If you need to transfer to a different directory, please use a soft link. ||    3. You can now build on the development package (SDK) We provide | |    Develop your own search. | |    Currently only supported in PHP language, see the following documentation: | | /usr/local/xunsearch/sdk/php/readme |+=================================================+ 

注意: 如果是生产环境iptables可能需要配置得严格,本文仅为测试

Configure Iptables, if you are not enabled then ignore this operation

Vi/etc/sysconfig/iptables join, below two lines-a input-p tcp-m state--state new-m TCP--dport 8383-j accept-a input-p tcp-m STA Te--state new-m TCP--dport 8384-j Accept restart Iptablesservice iptables restart

Start the service

/usr/local/xunsearch/bin/xs-ctl.sh-b inet Start

Start the output content:

Info:starting Server[xs-indexd] ... (bind:8383) Info:starting Server[xs-searchd] ... (bind:8384)

Web server Configuration

Installing the Xunsearch PHP SDK

CD Project/root/pathcomposer require--prefer-dist Hightman/xunsearch

Create a Project profile, a project that corresponds to a profile, and the project name cannot be duplicated

CP App\vendor\hightman\xunsearch\app\demo.ini App\config\search-demo.ini

Modify the contents of the file you just created, where the IP address of Server.index and Server.search is the IP address of the server that has the Xunsearch service installed

Search configuration File Example project.name = Demoproject.default_charset = Utf-8server.index = 192.168.56.4:8383server.search = 192.168.56.4:8384[pid]type = Id[subject]type = Title[message]type = Body[chrono]type = Numeric

Modify the app/routes/web.php file, write some client search test code

###################### Test Module ####################/* * Full-Text Search Test section */route::get ('/search/{key} ', function ($key) {$xs = new    XS (Config_path (' Search-demo.ini ')); $search = $xs->search;    Gets the Search object $query = $key;  $search->setquery ($query)->setsort (' Chrono ', true)//Chrono Positive order->setlimit (20,0)//Set Search statement, paging,    The offset amount; $docs = $search->search (); Perform a search to save the search results document in a $docs array $count = $search->count (); Gets the total number of matches for the search result. foreach ($docs as $doc) {$subject = $search->highlight ($doc->subject);//Highlight Subject Word Segment $message = $search->highlight ($doc->message); Highlight the Message field echo $doc->rank (). '. ' . $subject. " [" . $doc->percent ().        "%] - "; echo Date ("y-m-d", $doc->chrono). "<br>". $message.        "<br>";    Echo ' <br>========<br> '; } echo ' total: '. $count;});    Route::get ('/makedoc/{title}/{message} ', function ($title, $message) {$xs = new xs (' demo '); $doc = NEW xsdocument;  $doc->setfields (' pid ' = + 1, ' subject ' and ' = ' $title, ' message ' + $message, ' chrono ' = Time (),]); Use Arrays for batch assignment $xs->index->add ($doc);});

Use the browser to access the above two road test functions

By visiting:/HTTP//your domain/makedoc/title/content Test Build Index

Test examples:

http://Your domain/makedoc/about Xunsearch DEMO Project test/Project test is a very interesting behavior!http://your domain name/makedoc/Test Second/Here is the content of the second article/HTTP/ makedoc/Project Test third/The saying goes, there is no three, so there is a third article

注意: 索引不是即时生效的 延迟大概在10秒左右

By visiting:/HTTP/your domain/search/keyword Test search function
such as search keywords项目

1. DEMO Project test on Xunsearch [99%]-2011-08-26 project test is a very interesting behavior! ========2. Project Test Article III [100%]-2011-08-26 as the saying goes, there is no three, so there is a third article total number of ========: 2

We have completed one of the simplest full-text search examples through the above steps.
If you would like more details, please read the official documentation for Xunsearch.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.