SoFunction
Updated on 2025-03-10

The Yii2 framework integrates the Xunsearch search engine

This article illustrates the method of Yii2 framework integrating Xunsearch search engine. Share it for your reference, as follows:

The company has always used the YII2 framework, and then it is necessary to build a Chinese search engine. All the Xunsearch projects I think of, have mentioned before, how to install the Xunsearch server. (refer to"A brief tutorial on how to quickly build full-text search function under the innodb engine》)

xunsearch has only the server and PHP-SDK of Liunx for the time being. But the author does provide an extension to YII2. Suddenly I felt so happy.

Originally, it was written by using PHP-SDK to simply add indexes and update indexes and delete indexes, but it was considered in multiple projects. It means that a Xunsearch can be used by multiple projects, and all configuration files are placed in the configuration file of each project, and each search database is distinguished based on the configuration file of this project. This was my initial idea, but the point was not to think about it, but how to do it. Practice is the bottom line, and then we encounter the following problems.

/extension/yii-xunsearch/#hh4Here is the target link, I will talk about the installation experience next

// application components
  'components => [
    // ... other components ...
    'xunsearch' => [
      'class' => 'hightman\xunsearch\Connection', // This line must be, it is not necessarily written here, it may be based on the actual project      'iniDirectory' => '@app/config',  // Search the ini file directory, default: @vendor/highman/xunsearch/app      'charset' => 'utf-8',  // Specify the default encoding used by the project, the default instant utf-8 can not be specified    ],
  ],

Then, if your PHP environment is an integrated installation package, you may encounter such a problem

Unexpected character in input: '\' (ASCII=92) state=1

Some people on the Internet said it was a configuration problem inside, and said that short_open_tag was changed to On. The first thing I saw was that it made sense, and then I found it, it was On.

Then I went to a technical forum (a technology forum that is used all over the world, the official language is English), and I found it. I really don’t want to know the truth.

Because the YII2 extension uses namespace effects that only exist in PHP5.3. And my local PHP version is 5.2.6. I said I couldn't calm down. The thing that I tortured for a day was actually because the PHP version was too low. . .

That’s all for the summary.

For more information about PHP related content, please check out the topic of this site:Summary of usage of php regular expressions》、《Summary of the usage of php curl》、《Complete collection of PHP array (Array) operation techniques》、《Summary of php sorting algorithm》、《Summary of common traversal algorithms and techniques for PHP》、《PHP data structure and algorithm tutorial》、《Summary of PHP Programming Algorithm》、《Summary of PHP mathematical operation skills》、《Summary of PHP operations and operator usage》、《Summary of usage of php strings"and"Summary of common database operation techniques for php

I hope this article will be helpful to everyone's PHP programming.