• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

How to install and configure Sphinx in Ubuntu

989

To install and configure Sphinx on Ubuntu

Sphinx is a free search engine that permits full-text searches and performs search over large area. In this manual we will learn how to install and configure Sphinx in Ubuntu is explained.


Features

  • High index and search performance
  • Easy integration
  • Advanced querying tools
  • Advanced result set post-processing
  • Proven scalability
  • Easy scaling


To install Sphinx

Run the following command to installing the sphinx.

root@linuxhelp1:~# apt-get install sphinxsearch -y 
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libmysqlclient20 libpq5 libstemmer0d
The following NEW packages will be installed:
libmysqlclient20 libpq5 libstemmer0d sphinxsearch
0 upgraded, 4 newly installed, 0 to remove and 85 not upgraded.
Need to get 2,686 kB of archives.
After this operation, 20.7 MB of additional disk space will be used.
.
.
.
Adding system user `sphinxsearch'  (UID 122) ...
Adding new group `sphinxsearch'  (GID 130) ...
Adding new user `sphinxsearch'  (UID 122) with group `sphinxsearch'  ...
Not creating home directory `/var/run/sphinxsearch' .
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Processing triggers for systemd (229-4ubuntu7) ...
Processing triggers for ureadahead (0.100.0-19) ...


Create a database and import sample files inside the new database.

root@linuxhelp1:~# mysql -u root -p 
Enter password:
Welcome to the MySQL monitor. Commands end with   or g.
Your MySQL connection id is 4
Server version: 5.7.15-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ' help '  or ' h'  for help. Type ' c'  to clear the current input statement.

mysql>  CREATE DATABASE test 
Query OK, 1 row affected (0.78 sec)

mysql>  SOURCE /etc/sphinxsearch/example.sql 
Query OK, 0 rows affected, 1 warning (0.05 sec)

Query OK, 0 rows affected (0.38 sec)

Query OK, 4 rows affected (0.14 sec)
Records: 4 Duplicates: 0 Warnings: 0

Query OK, 0 rows affected, 1 warning (0.00 sec)

Query OK, 0 rows affected (0.13 sec)

Query OK, 10 rows affected (0.00 sec)
Records: 10 Duplicates: 0 Warnings: 0

mysql>  quit
Bye


Next rename the configuration file from sphinx.conf.sample to sphinx.conf by using the following command.

root@linuxhelp1:~# cd /etc/sphinxsearch/
root@linuxhelp1:/etc/sphinxsearch# ls 
example.sql sphinx.conf.dist sphinx.conf.sample sphinx-min.conf.dist
root@linuxhelp1:/etc/sphinxsearch# mv sphinx.conf.sample sphinx.conf
root@linuxhelp1:/etc/sphinxsearch# ls 
example.sql sphinx.conf sphinx.conf.dist sphinx-min.conf.dist


Open the sphinx.conf file and set your type, host name, username, password and the database name as shown below.

root@linuxhelp1:~# vim /etc/sphinxsearch/sphinx.conf 
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 = linuxc
sql_db = test
sql_port = 3306 # optional, default is 3306


Run the following command to managing the index data to the index by utilizing the configuration that we have created.

root@linuxhelp1:~# indexer --all 
Sphinx 2.2.9-id64-release (rel22-r5006)
Copyright (c) 2001-2015, Andrew Aksyonoff
Copyright (c) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file ' /etc/sphinxsearch/sphinx.conf' ...
indexing index ' test1' ...
.
.
.
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 193 bytes
total 0.004 sec, 38723 bytes/sec, 802.56 docs/sec
skipping non-plain index ' dist1' ...
skipping non-plain index ' rt' ...
total 8 reads, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
total 24 writes, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg


Now initialize the crontab for sphinx by using the following command.

root@linuxhelp1:~# crontab &ndash e 
You may be asked which text editor you want to use. Choose whichever you prefer  in this tutorial, we' ve used nano.
The follow cronjob will run on every hour and add new data to the index using the configuration file we created earlier. Copy and paste it at the end of the file, then save and close the file.

@hourly /usr/bin/indexer --rotate --config /etc/sphinxsearch/sphinx.conf --all

To Launch Sphinx

Turn on the sphinx daemon services and then restart the services by running the following command.

root@linuxhelp1:~# sed -i ' s/START=no/START=yes/g'  /etc/default/sphinxsearch
root@linuxhelp1:~# systemctl restart sphinxsearch.service 
After restarting verify whether the Sphinx daemon is active or not.

root@linuxhelp1:~# systemctl status sphinxsearch.service 
? sphinxsearch.service - LSB: Fast standalone full-text SQL search engine
Loaded: loaded (/etc/init.d/sphinxsearch  bad  vendor preset: enabled)
Active: active (running) since Mon 2016-09-19 17:37:22 IST  19s ago
Docs: man:systemd-sysv-generator(8)
Process: 37494 ExecStop=/etc/init.d/sphinxsearch stop (code=exited, status=0/SUCCESS)
Process: 37500 ExecStart=/etc/init.d/sphinxsearch start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/sphinxsearch.service
??37506 /usr/bin/searchd
??37507 /usr/bin/searchd

Sep 19 17:37:22 linuxhelp1 sphinxsearch[37500]: Copyright (c) 2001-2015, Andrew Aksyonoff
Sep 19 17:37:22 linuxhelp1 sphinxsearch[37500]: Copyright (c) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com)
Sep 19 17:37:22 linuxhelp1 sphinxsearch[37500]: precaching index ' test1' 
Sep 19 17:37:22 linuxhelp1 sphinxsearch[37500]: [218B blob data]
Sep 19 17:37:22 linuxhelp1 sphinxsearch[37500]: [208B blob data]
Sep 19 17:37:22 linuxhelp1 sphinxsearch[37500]: Sphinx 2.2.9-id64-release (rel22-r5006)
Sep 19 17:37:22 linuxhelp1 sphinxsearch[37500]: Copyright (c) 2001-2015, Andrew Aksyonoff
Sep 19 17:37:22 linuxhelp1 sphinxsearch[37500]: Copyright (c) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com)
Sep 19 17:37:22 linuxhelp1 sphinxsearch[37500]: sphinxsearch.
Sep 19 17:37:22 linuxhelp1 systemd[1]: Started LSB: Fast standalone full-text SQL search engine.

To test the sphinx

In order to test the sphinx functionality, connect to SphinxQL available on the port 9306 with the help of MySQL. Your prompt will automatically changes to mysql>

root@linuxhelp1:~# mysql -h0 -P9306 
Welcome to the MySQL monitor. Commands end with   or g.
Your MySQL connection id is 1
Server version: 2.2.9-id64-release (rel22-r5006)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ' help '  or ' h'  for help. Type ' c'  to clear the current input statement.

mysql> 

Let' s search a sentence.

mysql>  SELECT * FROM test1 WHERE MATCH(' test document' )  SHOW META 
+------+----------+------------+
| id | group_id | date_added |
+------+----------+------------+
| 1 | 1 | 1474286253 |
| 2 | 1 | 1474286253 |
+------+----------+------------+
2 rows in set (0.06 sec)

+---------------+----------+
| Variable_name | Value |
+---------------+----------+
| total | 2 |
| total_found | 2 |
| time | 0.057 |
| keyword[0] | test |
| docs[0] | 3 |
| hits[0] | 5 |
| keyword[1] | document |
| docs[1] | 2 |
| hits[1] | 2 |
+---------------+----------+
9 rows in set (0.00 sec)


From the above result it is clear that it found out 2 matches from our test sentence. The SHOW META command checks the sentence result individually.

mysql>  CALL KEYWORDS (' test one three' , ' test1' , 1) 
+------+-----------+------------+------+------+
| qpos | tokenized | normalized | docs | hits |
+------+-----------+------------+------+------+
| 1 | test | test | 3 | 5 |
| 2 | one | one | 1 | 2 |
| 3 | three | three | 0 | 0 |
+------+-----------+------------+------+------+
3 rows in set (0.00 sec)

mysql>  CALL KEYWORDS (' test one three' , ' test1' , 1) 
+------+-----------+------------+------+------+
| qpos | tokenized | normalized | docs | hits |
+------+-----------+------------+------+------+
| 1 | test | test | 3 | 5 |
| 2 | one | one | 1 | 2 |
| 3 | three | three | 0 | 0 |
+------+-----------+------------+------+------+
3 rows in set (0.00 sec)

Now you can leave the MySQL shell.

mysql>  quit
Bye

Tags:
jackson
Author: 

Comments ( 0 )

No comments available

Add a comment

Frequently asked questions ( 5 )

Q

Why my accuracy is poor in Sphnix?

A

Speech recognition accuracy is not always great. To test speech recognition you need to run recognition on prerecorded reference database to see what happens and optimize parameters.

Q

Which languages are supported in Sphnix?

A

It provides prebuilt language models for many languages (English, Chinese, French, Spanish, German, Russian, etc)

Q

How to add support for a new language in Sphnix?

A

The process of building a new language model consists of the following steps
Data cleanup
Model training
Testing

Q

What is sample rate and how does it affect accuracy

A

Unfortunately we don’t provide universal models for different bandwidths (8khz models are 10% worse in accuracy) and we can not detect sample rate yet.

Q

Does I run large vocabulary speech recognition on a mobile device?

A

No, you can’t. The CPU is too slow for large vocabulary speech recognition. Phone CPU is usually 9 times slower than desktop. Speech recognition with unlimited vocabulary requires very big computational and memory resources

Related Tutorials in How to install and configure Sphinx in Ubuntu

Related Tutorials in How to install and configure Sphinx in Ubuntu

How to Install and Configure Sphinx in CentOS
How to Install and Configure Sphinx in CentOS
Nov 16, 2016
How to install and configure Sphinx in Ubuntu
How to install and configure Sphinx in Ubuntu
Oct 11, 2016
How to Install and Configure Sphinx on Ubuntu 16.04
How to Install and Configure Sphinx on Ubuntu 16.04
Feb 23, 2018

Related Forums in How to install and configure Sphinx in Ubuntu

Related Forums in How to install and configure Sphinx in Ubuntu

Linux
lincoln class=
Cant able to install sphinx
Apr 8, 2017
Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Elijah ?
Remote Desktop Connection Has Stopped Working

When accessing my remote machine server using remote desktop on a windows machine I am getting this error

forum (1)

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.