Archive for March 2014

SphinxQL over JDBC

This is an extension of my earlier blog post about performing free text search with Sphinx (v2.1.6+). This time we are going to access the index via JDBC as opposed to Sphinx API and perform some basic queries to fetch indexed data.

Add following entries to searchd section inside sphinx.conf

Once done start the sphinx daemon (searchd) so that the search engine can be accessed from external applications on port 9306. Next just get the JDBC connection (no need to specify database details and credentials) as shown below and you are ready to rock.
con = DriverManager
statement = con.createStatement();
// perform wild search on last names
resultSet = statement
 .executeQuery("select * from addressBookIndex 
where MATCH ('gogna | sharma')"); 

  • 1. The attributes specified in the sphinx.conf file (e.g. sql_attr_string, sql_attr_uint etc) can not be used with MATCH though they can be part of WHERE clause.
  • 2. Given that now String attributes are supported in order to avoid making a database call define key columns as attributes as well as fields in sql_query.
  • 3. Results from Delta Indexes can be handled using union.
  • 4. Explore RT indexes for real time update scenarios.
For more information about the Sphinx QL syntax visit here.
Saturday, March 15, 2014
Posted by Munish Gogna

Popular Post


enums (1) java (2) JAX-RS (1) JPA (1) mysql (1) request 2 (1) RESTful (1) sphinx (1) tomcat (1) web service (2) ws (2)