Redisearch achieve full-text search service

"Search" is a lot of functional modules that can not be bypassed, when a small amount of data that can be used when the fuzzy query and other operations improvise, but when faced with massive data and high concurrency, lucene common in the industry elasticsearch and other programs, but elasticsearch run-time memory has a minimum size recommended more than 2G of memory space while it is running, and require additional disk space for persistent storage.

    In fact mongoDB built-in regular text search and matching solution comes with text indexing and search keywords is a tricky, but this time we bring a more efficient and economical text retrieval program: Redisearch

 

Redis Modules are introduced 4.0 redis an extension mechanism, the user may be provided through the interface to achieve redis module C api to add custom features redis service. redisLab also in hopes to regulate redis community ecosystem to achieve.

    version redis module itself is independent of the redis, and are compiled into dynamically loading libraries .so file release, different versions of the same version module.so redis can load the file.

    redis provides two ways to load. By adding loadmodule /path/to/mymodule.so in conf file, or you can use the command in redis-cli in MODULE LOAD /path/to/panda.so dynamic loading, MODULE UNLOAD unload.

 

    Characteristics

    based on full-text index of the document.
    High-performance incremental indexing.
    Supporting documentation score, document field (field) weighting mechanism.
    Support complex Boolean queries.
    Support completion.
    Based on the analysis stemming snowball, multi-language support. Use friso support Chinese word.
    utf-8 character set support.
    redis data persistence support.
    Custom scoring mechanism.

    

    The principle is the basis redis on hashmap can easily implement an inverted index structure. redisearch inverted index in addition to achieve the basic functions, but also introduces the optimization of memory management. If you are interested src / inverted_index.c part of reading the source code

    

    First, install Rediseach, remember that your local service redis version must be 4.0 or more, a lot of online Raiders compiled and installed, cumbersome and a waste of time, it is also time to Docker debut, has compiled images available for free on the hub we downloaded

1, redis installation

# Download and install the source rpm 
yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7 .rpm
 # install redis 
yum install --enablerepo = Remi - the y-redis
 # start redis service 
service redis start

2, installation Rediseach

docker pull redislabs/redisearch
After downloading, start the service directly in the background
docker run -d -p 6666:6379 redislabs/redisearch:latest

 

 At this point there has been a docker container started in the background, redis service is mapped to the host port 6666, we look to connect

redis-cli -h localhost -p 6666

 

 Check whether the modules successfully loaded

If it returns an array exist "ft", it indicates redisearch has been successfully loaded.

Index Concepts & elasticsearch of Redisearch similar to the index, the document represents a certain type of resource unit.

Here we define a SMARTX_VM index, which is stored document contains the title and desc two TEXT type of field.

    

FT.CREATE SMARTX_VM SCHEMA title TEXT WEIGHT 5.0 desc TEXT

 Then add a document to this index just created

Vm-20,190,901 1.0 SMARTX_VM FT.ADD LANGUAGE " chinese " the FIELDS title " Chinese " desc " I am Chinese "

LANGUAGE "chinese" parameter indicates the use of Chinese word processing text. The default is English

    At this point we document retrieval

 

FT.SEARCH SMARTX_VM "中国" LANGUAGE "chinese"

  Note also specify the language when searching, here we use the Chinese word, English word default is unable to retrieve the Chinese

 

 We can see already returned the results we want.

Redisearch is an efficient, full-featured, high-performance full-text search components stored in memory, is very suitable for use in moderate amount of data, limited memory and storage space environment. With data synchronization means, we can easily be integrated into existing redisearch data storage, thus providing full-text search to the product, automatically fill congruent service optimization.

 

Guess you like

Origin www.cnblogs.com/xcsg/p/11442138.html