Sphinx pre-query not inheriting

db, sphinx Add comments

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 
}

Comments are closed.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in