Showing posts with label sphinx search php. Show all posts
Showing posts with label sphinx search php. Show all posts

Sunday 30 November 2014

Sphinx Search Engine installation WAMP

Sphinx Search Engine installation WAMP



 Here is my environment:

  • Windows
  • WAMP
  • Apache 2.2.11
  • MySQL 5.1.36
  • PHP 5.3.0
  • Sphinx 1.10
First of all download Sphinx for Windows which can be found (http://sphinxsearch.com/downloads/beta/).

Sphinx creates a separate index of the table you want to search. Your PHP scripts calls the Sphinx API to search connecting to a specific port where Sphinx is listening to. Sphinx then searches its own index and does the search returning the result. Yes, the index has to be updated every time your update your original table. 

Once you have created sphinx.conf in the bin folder copy the content from c:\sphinx\sphinx-min.conf.in (this is their provided sample file). It looks like:
#
# Minimal Sphinx configuration sample (clean, simple, functional)
#

source src1
{
 type   = mysql

 sql_host  = localhost
 sql_user  = test
 sql_pass  =
 sql_db   = test
 sql_port  = 3306 # optional, default is 3306

 sql_query  = \
  SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS
  date_added, title, content \
  FROM table

 sql_attr_uint  = group_id
 sql_attr_timestamp = date_added

 sql_query_info  = SELECT * FROM table WHERE id=$id
}

index test1
{
 source   = src1
 path   = @CONFDIR@/data/test1
 docinfo   = extern
 charset_type  = sbcs
}

index testrt
{
 type   = rt
 rt_mem_limit  = 32M

 path   = @CONFDIR@/data/testrt
 charset_type  = utf-8

 rt_field  = title
 rt_field  = content
 rt_attr_uint  = gid
}

indexer
{
 mem_limit  = 32M
}

searchd
{
 listen   = 9312
 listen   = 9306:mysql41
 log   = @CONFDIR@/log/searchd.log
 query_log  = @CONFDIR@/log/query.log
 read_timeout  = 5
 max_children  = 30
 pid_file  = @CONFDIR@/log/searchd.pid
 max_matches  = 1000
 seamless_rotate  = 1
 preopen_indexes  = 0
 unlink_old  = 1
 workers   = threads # for RT to work
}
These settings should cover most of what you're looking for in terms of setting up Sphinx.

Code in PHP script:
require_once('sphinxapi.php');
//Sphinx
$s = new SphinxClient;
$s->setServer("localhost"9312);
$s->setMatchMode(SPH_MATCH_EXTENDED2);


Sphinx commands:

C:\wamp\www\sphinx-2.2.3-beta-
win32\bin>indexer.exe --config c:\wamp\www\sphinx-
2.2.3-beta-win32\sphinx.conf.in test1

C:\wamp\www\sphinx-2.2.3-beta-win32\bin>searchd.exe --install --config c:\wamp\w
ww\sphinx-2.2.3-beta-win32\sphinx.conf.in --servicename SphinxSearch

Create .ICS file using PHP code

Recently worked on creating a .ics file in PHP after a very long time, code so thought to share with everybody. Please find below the comple...