Home Database Mysql Tutorial mysql中使用sphinx搜索子域名需注意的问题

mysql中使用sphinx搜索子域名需注意的问题

Jun 07, 2016 pm 05:55 PM
sphinx

比如搜索jb51.net会把www.jb51.net、jb51.net、sc.jb51.net等都搜索出来

搜索子域名

比如搜索jb51.net会把www.jb51.net、jb51.net、host.jb51.net等都搜索出来。

如果使用mysql用like的话效率是非常低的,几百万甚至上千万的数据那是没有办法使用的,于是采取sphinx来做。

在使用的过程中发现了诸多问题,这里将其总结起来,也让不知道的朋友注意下这些字符。

分析:
sphinx是全文索引,它搜索的是包含的记录。

首先如果我们不做任何设置的话,搜索jb51.net会出现把aajb51.net、jb51.a.cn、jb51.net.com(当然这个域名后缀不存在,但是会有符合相应规则的域名,这里只举例)等等。

为什么会出现这种情况呢?

我们使用./search -c 配置文件 -i 索引名 'jb51.net' 搜索的时候会发现下面words部分被分成了两部分'jb51'和'cn',默认以.作为分隔符,如果我们不想让它做为分隔符,就需要把.添加到charset_table里面,这里需要说的是我们搜索域名只需要有字母、数字、"-"等字符,其他的不需要。设置如下:
charset_table = 0..9,A..Z->a..z, a..z,U+002e,U+002d,U+0040,U+0060 #其中U+002e代表".",U+002d代表"-",U+0040代表"@",U+0060代表"`",这里为ascii码值。
这样会解决掉搜出jb51.a.cn这类域名。

那么jb51.net.com这类呢?我们可以在索引的字段中增加惟一后缀比如“XXXXX”,concat(search,'XXXXX')这样,就不会出来了。

现在就剩下aajb51.net这类域名,我们使用关键字“ '".jb51.net"' ”(注意是单引号里面套双引号)这样来搜索,主域名单独加上,但是使用的过程中发现这样搜出了与这个域名无关的域名,比如aa.bb.cn这样,经后来研究是"."的问题,后来把"."替换成"@",来搜索又出现12306等好多域名无法读取到的问题,后来经研究估计这些特殊字符在sphinx中都有特殊的意义,于是找到了"`"这个字符,换成这个以后一切才算正常了。

注意:将"."替换成"`"等相应字符后需在charset_table里增加这个字符,不然是被忽略的。

所以在搜索的过程中我们需要注意下这些特殊字符。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use php extension Sphinx for full text search How to use php extension Sphinx for full text search Jul 29, 2023 am 10:05 AM

How to use PHP extension Sphinx for full-text search Full-text search is one of the common requirements in modern web applications. In order to satisfy users' efficient query and retrieval of data, we can use Sphinx, a powerful open source search engine, to implement the full-text search function. Sphinx is written in C++ and provides PHP extensions to facilitate our use in PHP projects. This article will introduce how to use the PHP extension Sphinx for full-text search

Sphinx PHP application guide to implement full-text search Sphinx PHP application guide to implement full-text search Oct 03, 2023 am 08:37 AM

Introduction to the PHP application guide for implementing full-text search with Sphinx: In modern Web applications, the full-text search function has become an essential feature. Because users often search and match the content they need by entering keywords. In order to provide efficient and accurate search results, we need a powerful search engine. As an open source full-text search engine, Sphinx provides a perfect search solution for PHP. This article will introduce how to use Sphinx to implement

Sphinx PHP application skills in natural language processing Sphinx PHP application skills in natural language processing Oct 03, 2023 am 09:53 AM

SphinxPHP application skills in natural language processing require specific code examples. With the development of the Internet and the advancement of artificial intelligence technology, natural language processing (Natural Language Processing, NLP) has become an important research direction in computer science. The goal of natural language processing is to enable computers to understand, interpret and generate natural language, making the communication between humans and machines more convenient and intelligent. In natural language processing, text retrieval is a very important

Sphinx implements real-time search effects for PHP projects Sphinx implements real-time search effects for PHP projects Oct 03, 2023 am 09:16 AM

Sphinx is an open source full-text search engine that can quickly and efficiently realize search and retrieval of large-scale data. In PHP projects, using Sphinx can achieve real-time search effects and improve user experience and search speed. This article will introduce how to use Sphinx in PHP projects and provide specific code examples. 1. Install Sphinx To achieve real-time search effects in PHP projects, you first need to install Sphinx. It can be found in Sphinx official website

Analysis of PHP implementation method of Sphinx distributed search Analysis of PHP implementation method of Sphinx distributed search Oct 03, 2023 am 08:49 AM

Analysis of the PHP implementation method of Sphinx distributed search Introduction: In today's Internet era, search engines have become one of the main ways for people to obtain information. In order to provide more efficient and accurate search results, some large-scale websites or applications usually use distributed search engines to process search requests. Sphinx is a well-known distributed search engine with good performance and scalability. This article will introduce how to use PHP to implement Sphinx distributed search and provide specific code examples.

Sphinx implements fast search and cache optimization for PHP projects Sphinx implements fast search and cache optimization for PHP projects Oct 03, 2023 am 09:01 AM

Sphinx is an open source full-text search engine that can quickly process large amounts of data and provide efficient search capabilities. Using Sphinx in PHP projects can achieve fast search and cache optimization, improving project performance and user experience. This article will introduce how to integrate Sphinx in a PHP project and illustrate its usage and advantages through specific code examples. 1. Sphinx installation and configuration To use Sphinx, you first need to install and configure it on the server.

Sphinx PHP product search and sorting optimization on e-commerce websites Sphinx PHP product search and sorting optimization on e-commerce websites Oct 03, 2023 am 10:53 AM

Product search and sorting optimization by SphinxPHP in e-commerce websites In e-commerce websites, product search and sorting are one of the important factors for user experience and sales conversion. In order to improve the user's search experience and present results that best match user needs, SphinxPHP is a very powerful and widely used full-text search engine. This article will introduce how to use SphinxPHP to optimize product search and sorting on e-commerce websites, and provide specific code examples. 1. Install and configure Sphin

How to do full text search using Sphinx in ThinkPHP6? How to do full text search using Sphinx in ThinkPHP6? Jun 12, 2023 pm 12:40 PM

In modern web development, search engines have become an integral part. Compared with other search engines, Sphinx is a service specially designed to handle full-text search. In this article, we will introduce in detail how to integrate Sphinx in ThinkPHP6 for full-text search. Install Sphinx First, we need to install Sphinx on the server. The following is an example command to install Sphinx on an Ubuntu system: $sudoap

See all articles