Install Sphinx on Mac

development, mac, server, sphinx Comments Off on Install Sphinx on Mac

To install Sphinx search on Mac, I had to find pieces of information here and there.

Here is my list how to sort it out:

1. Download a fresh stable source from Sphinx website to your /tmp folder. It’s a tar.gz file.

2. Go to /tmp folder and run this command to untar the arhieve:

tar -zxvf sphinx-2.0.6-release.tar.gz

Fix the file name since the version can change.

3. Go into the “sphinx-2.0.6-release” folder.

4. Fix this command by my comments below and then run:

./configure --enable-id64  --prefix=/usr/local --with-mysql=/usr/local/mysql-5.1.63-osx10.6-x86/ LDFLAGS="-arch i386"
  • --enable-id64 mean you want to support really long integers as document IDs, depends on your application needs
  • --with-mysql – fix the path to the file

5. Run this command:

sudo make

Check the response, there must be no errors. Mine ends like this:

...[scary looking C commands]...
Making all in test
make[1]: Nothing to be done for `all'.
Making all in doc
All docs are already pre-built by developer.
If you want to rebuild them, install docbook-xsl
and xsltproc and then run 'make docs' instead of simple 'make'.
make[1]: Nothing to be done for `all-am'.

6. Run this:

sudo make install

7. Test if all is OK. If you run this, you must get a list of parameters of this tool:

indexer

Good luck!

Sphinx pre-query not inheriting

db, sphinx Comments Off on Sphinx pre-query not inheriting

Sphinx is a nice search engine and is used at our project hugely.

Although, I found a case when using a pre-fetch query is not obvious. The pre-fetch query is a query that is run before the data is got from database, so thus you can set character encoding, tune database caching, set variables, etc.

So, if we have 2 sources, one is parent for all other sources since it has database connection params, and second one inherits from the parent.

source www {
    type                    = mysql

    sql_user                = root
    sql_pass                = 

    sql_query_pre           = SET NAMES utf8    
}

source www_country : www {
    sql_query = SELECT * FROM country
}

All works fine – when www_country souce is used, the same sql_query_pre will be used because www_country is a child of parent source.

Although, if one day you decide to add a custom pre-query to the child source, it seems you loose the parent’s ones:

...
source www_country : www {
    sql_query_pre = SET @usefulVariable = 1

    sql_query = SELECT * FROM country 
}

In this case it seems you have to duplicate the parental pre-query in every child =(
So the right child is gonna be:

...
source www_country : www {
    sql_query_pre = SET NAMES utf8    
    sql_query_pre = SET @usefulVariable = 1

    sql_query = SELECT * FROM country 
}
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in