Install Manticore Search And Play With Wordpress Database

2018-10-03 966 words 5 mins read

A few days ago I found Manticore search, a fork of Sphinx search. I researched it and found an article.

It is worth trying.

Back up all the content of the existing server and start to increase the search function.

Install Manticore Search


First go to their website to download the latest version for this server system. This server uses Ubuntu 18.04. The latest version of the link can be easily found on the web page. The commands for downloading and installing at the current time are as follows:
wget https://github.com/manticoresoftware/manticoresearch/releases/download/2.7.3/manticore_2.7.3-180926-d07c4d43-stemmer.bionic_amd64-bin.deb

sudo dpkg -i manticore_2.7.3-180926-d07c4d43-stemmer.bionic_amd64-bin.deb

According to its installation tutorial, you also need to install several LIBs.
sudo apt-get install libmysqlclient20 libodbc1 libpq5 libexpat1

Then start this service
sudo systemctl start manticore

This service is also started when the server starts.
sudo systemctl enable manticore

Create a Manticore search test database


First log in to MySQL with the root username password.
mysql -u root -p

Create a test database
mysql> CREATE DATABASE test;

Manticore search provides an example file to import into the test database
mysql> SOURCE /usr/share/doc/MANTICORE/example-conf/example.sql

Exit the mysql command interface
mysql> exit

Ok, so there is a test database

Configuring Manticore Search


Because the manticore search is a sphinx branch project, the configuration file remains the same in order to maintain compatibility with the meta project.

So edit its configuration file
sudo nano /etc/sphinxsearch/sphinx.conf

Modify the database, username and password:
source src1
{
# data source type. mandatory, no default value
# known types are mysql, pgsql, mssql, xmlpipe, xmlpipe2, odbc
type = mysql

#####################################################################
## SQL settings (for 'mysql' and 'pgsql' types)
#####################################################################

# some straightforward parameters for SQL source types
sql_host = localhost
sql_user = root
sql_pass = yourpassword
sql_db = test
sql_port = 3306 # optional, default is 3306

....

The configuration file is very long, and others need not be modified for the time being.

Test Manticore search


The test database is stored in mysql. The Manicore search needs to be included in your own system. Use the following command:
sudo -u manticore indexer -c /etc/sphinxsearch/sphinx.conf test1 --rotate

Come out with
indexing index 'test1'...
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 193 bytes
total 0.160 sec, 1202 bytes/sec, 24.91 docs/sec
total 4 reads, 0.000 sec, 8.1 kb/call avg, 0.0 msec/call avg
total 12 writes, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
rotating indices: successfully sent SIGHUP to searchd (pid=21729).

Successfully indexed. We need to use mysql to log in to Manticore search
mysql -h0 -P9306

Go to the MySQL shell
mysql> show TABLES;

See the following results
+--------+-------------+
| Index | Type |
+--------+-------------+
| dist1 | distributed |
| test1 | local |
| testrt | rt |
+--------+-------------+
3 rows in set (0.00 sec)

It means that TEST1 has been successfully included. We can test its search function
mysql> CALL KEYWORDS ('one two three', 'test1', 1);
+------+-----------+------------+------+------+
| qpos | tokenized | normalized | docs | hits |
+------+-----------+------------+------+------+
| 1 | one | one | 1 | 2 |
| 2 | two | two | 1 | 2 |
| 3 | three | three | 0 | 0 |
+------+-----------+------------+------+------+
3 rows in set (0.00 sec)

There are some test commands on the documentation, you can refer to the test.

 

Connect with Wordpress Database


I make another conf file
sudo nano /path/sphinx.conf

Paste the following content:
#
# INDEX GROUP:
# MY BLOG
#
# SOURCES:
# src_my_blog
#
# INDEXES:
# idx_blog
#
#
source src_my_blog {
type = mysql
sql_host = localhost
sql_user = yourusername
sql_pass = yourpassword
sql_db = wordpress
sql_query_pre = SET NAMES utf8
sql_query = \
SELECT \
p.ID as ID, \
p.post_title as title, \
p.post_content as body, \
UNIX_TIMESTAMP(p.post_date) AS date_added \
FROM \
wp_posts as p \
WHERE \
p.post_type = 'post' AND \
p.post_status = 'publish';
sql_attr_string = title
sql_field_string = body
sql_attr_timestamp = date_added
}
index idx_blog {
source = src_my_blog
path = /var/lib/manticore/data/idx_blog
docinfo = extern
mlock = 0
min_word_len = 1
### support Chinese words query ###
charset_type = utf-8
charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F
ngram_len = 1
ngram_chars = U+3000..U+2FA1F
html_strip = 1
html_index_attrs = img=alt,title; a=title;
html_remove_elements = style, script, object, embed, span
}
#############################################################################
## indexer settings
#############################################################################
indexer
{
# memory limit, in bytes, kiloytes (16384K) or megabytes (256M)
# optional, default is 128M, max is 2047M, recommended is 256M to 1024M
mem_limit = 256M
}
#############################################################################
## searchd settings
#############################################################################
searchd
{
listen = 9312
listen = 9306:mysql41
log = /var/log/manticore/searchd.log
query_log = /var/log/manticore/query.log
read_timeout = 5
client_timeout = 300
max_children = 30
persistent_connections_limit = 30
pid_file = /var/run/manticore/searchd.pid
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
mva_updates_pool = 1M
max_packet_size = 8M
max_filters = 256
max_filter_values = 4096
max_batch_queries = 32
workers = threads # for RT to work
binlog_path = /var/lib/manticore/data # binlog.001 etc will be created there
}
# --eof--

CTRL-X saves and exits.

Run the indexer command:
sudo indexer --config /path/sphinx.conf --all --rotate

Run the searchd command to start the search service.
sudo searchd --config /path/sphinx.conf

Ok, let's mysql login to the Manticore Search data server again.
mysql -h0 -P9306

Check the table:
mysql> show tables;

+----------+-------+
| Index | Type |
+----------+-------+
| idx_blog | local |
+----------+-------+
1 row in set (0.00 sec)

No problem, idx_blog has been indexed.

This is the article of this blog. Run a few commands to test it
mysql> select title from idx_blog where match('EURJPY');

1 result:



No problem.

Make PHP back-end and AJAX front-end


front-end HTML



Then generate a php file for background processing.



These codes include the snippet function and ajax sorting of SphinxQL.

You can try this search function here.

Manticore Search:



 

 

author

Authored By Jesse Lau

A freelancer living in New Zealand, engaged in website development and program trading. Ever won 1st ranking twice in the Dukascopy Strategy Contest. Making GPTs on GPT Search | GPT Finder. This article is licensed under a Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now

Post Your Comments Here:

Our website uses cookies to improve your user experience. If you continue browsing, we assume that you consent to our use of cookies. More information can be found in our privacy policy Got it