Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Tutorials»How to Install and Configure Sphinx on Ubuntu 16.04, 14.04

    How to Install and Configure Sphinx on Ubuntu 16.04, 14.04

    RahulBy RahulDecember 25, 20174 Mins ReadUpdated:January 8, 2018

    Sphinx is a simple, relevance and open source full-text search server. It is written in C++ programming language and works with Linux and other popular operating systems. This tutorial will help you to install and configure Sphinx full-text search server on Ubuntu 16.04, 14.04 LTS operating systems.

    Prerequisites

    Before you begin this guide, you must have the followings.

    • Ubuntu server with sudo access
    • Pre installed MySQL server

    Step 1 — Install Sphinx

    Installing Sphinx on Ubuntu is easy because it’s in the native package repository. Install it using the apt-get package manager on your Ubuntu system.

    sudo add-apt-repository ppa:builds/sphinxsearch-rel22
    sudo apt-get update
    sudo apt-get install sphinxsearch
    

    Step 2 – Import MySQL Database

    Let’s import the sample SQL file into the database.First, create a database named test in your MySQL server, after that restore the database provided by the sphinx search package.

    sudo mysqladmin -u root -p create test
    sudo mysql -u root -p test < /usr/share/doc/sphinxsearch/example-conf/example.sql
    

    Step 3 – Configure Sphinx

    Edit sphinx configuration as below and edit for the MySQL connection configuration as showing below.

    sudo vi /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                = secret
    	sql_db                  = test
    	sql_port                = 3306  # optional, default is 3306
    

    Step 4 – Running Indexer

    Run the indexer to create the full-text index from your data. The indexer is the first of the two principal tools as part of Sphinx. It works for gathering the data that will be searchable. You will see the results like below.

    sudo indexer --all 
    
    Sphinx 2.2.11-id64-release (95ae9a6)
    Copyright (c) 2001-2016, Andrew Aksyonoff
    Copyright (c) 2008-2016, 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.006 sec, 30791 bytes/sec, 638.16 docs/sec
    indexing index 'test1stemmed'...
    collected 4 docs, 0.0 MB
    sorted 0.0 Mhits, 100.0% done
    total 4 docs, 193 bytes
    total 0.001 sec, 99382 bytes/sec, 2059.73 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
    
    

    Step 5 – Starting Sphinx

    Also, configure you Sphinx server to auto start on system boot. Use below command to set START to yes.

    sudo sed -i 's/START=no/START=yes/g' /etc/default/sphinxsearch
    

    Now also start service for the first time and check the status.

    service sphinxsearch start
    service sphinxsearch status
    

    You can also configure the indexer in your crontab to run it on a regular interval. The below crontab will run on every hour.

    0 * * * * /usr/bin/indexer --rotate --all
    

    Step 6 – Working with Sphinx

    Let's execute some queries on your Sphinx server. First connect to Sphinx MySQL server using the following ocmmand.

    mysql -h0 -P9306
    

    Now run one by one command below and see the changes. This is for your own learning only.

    mysql> SELECT * FROM test1 WHERE MATCH('document');
    mysql> INSERT INTO rt VALUES (1, 'adding', 'sample text here', 11);
    mysql> INSERT INTO rt VALUES (2, 'adding some more', 'sample text here', 22);
    mysql> SELECT gid/11 FROM rt WHERE MATCH('sample') GROUP BY gid;
    mysql> SELECT * FROM rt ORDER BY gid DESC;
    mysql> SELECT *, WEIGHT() FROM test1 WHERE MATCH('"document one"/1');
    mysql> SHOW META;
    mysql> SET profiling=1;
    mysql> SELECT * FROM test1 WHERE id IN (1,2,4);
    mysql> SHOW PROFILE;
    mysql> SELECT id, id%3 idd FROM test1 WHERE MATCH('this is | nothing') GROUP BY idd;
    mysql> SHOW PROFILE;
    mysql> SELECT id FROM test1 WHERE MATCH('is this a good plan?');
    mysql> SHOW PLAN;
    mysql> SELECT COUNT(*) FROM test1;
    mysql> CALL KEYWORDS ('one two three', 'test1');
    mysql> CALL KEYWORDS ('one two three', 'test1', 1);
    mysql> SHOW TABLES;
    
    search sphinx
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Install Swift on Ubuntu 16.04 LTS
    Next Article How to Install and Configure OpenVPN Server on Ubuntu 18.04, 16.04

    Related Posts

    How to Correctly Set the $PATH variable in Bash

    2 Mins Read

    What is the /etc/aliases file

    2 Mins Read

    What is the /etc/nsswitch.conf file in Linux

    2 Mins Read

    How to Setup Squid Proxy Server on Ubuntu and Debian

    Updated:June 17, 20225 Mins Read

    How to Delete a Let’s Encrypt Certificate using Certbot

    Updated:June 3, 20222 Mins Read

    How to Install Latest Git on Ubuntu 22.04

    Updated:May 31, 20222 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Import GPG Keys on Ubuntu & Debian (without apt-key)
    • How To Install Google Chrome On macOS
    • How to Install Minecraft on Ubuntu 22.04 & 20.04
    • Running a Cron job every Sunday (Weekly)
    • Running Multiple Commands At Once in Linux
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.