11

i have been using mysql FTS , but recently switched to sphinx for testing purpose.

installed sphinx on centos 7

Linux production 3.10.0-123.8.1.el7.x86_64 #1 GNU/Linux

sphinx.conf

source content_src1
{
    type            = mysql
    sql_host        = localhost
    sql_user        = 
    sql_pass        = 
    sql_db          = t_prod2
    sql_port        = 3306  # optional, default is 3306

    sql_query       = \
        SELECT content.record_num, \
                    content.title, \
                    content.category, \
                    content.upload_date, \
                    content.comments_count, \
                    content.verified, \
                    content.uploader, \
                    content.size \
                    FROM content WHERE enabled = 1 

    sql_attr_uint       = record_num
    sql_attr_string = title
}


index content_index1
{
    source          = content_src1
    path            = /var/lib/sphinx/content_index1
    morphology              = stem_en

    min_word_len            = 1
    min_prefix_len          = 0
    min_infix_len           = 1
    docinfo                 = extern 

}

i am using php to connect sphinxql and run queries, .like this

$sphinxql = @mysqli_connect($sphinxql_host.':'.$sphinxql_port,'','');

$sphinxql_query = "SELECT id FROM $sphinx_index WHERE MATCH('".mysqli_real_escape_string($prod1,$q)."') LIMIT  $from,$max_results";

simple queries are working fine, i.e. queries without any order by condition. but when i tried to run sql queries having order by , sphinx is throwing errors .

i.e. query and their errors.

SELECT id FROM $sphinx_index WHERE MATCH('".mysqli_real_escape_string($prod1,$q)."') ORDER BY title DESC LIMIT  $from,$max_results

index content_index1: sort-by attribute 'title' not found

another try, i replaced field name with @field name

SELECT id FROM $sphinx_index WHERE MATCH('".mysqli_real_escape_string($prod1,$q)."') ORDER BY @title DESC LIMIT  $from,$max_results

sphinxql: syntax error, unexpected USERVAR, expecting IDENT (or 55 other tokens) near '@title DESC LIMIT 0,25'

table has order by fields like title, category , upload_date , size , verified

so how can i use order by in my sphinxql query


update 1

i have managed to run queries "not having order by" , but queries having "order by" not working properly,doesnt gives error, gives result sets, but if i change the direction of sort by attribute , the results sets doesnt changes.

updated fields and attributes are as.

sql_field_string = title
sql_field_string = og_name
sql_field_string = hash
sql_field_string = keywords

sql_attr_timestamp = upload_date_timestamp

sql_attr_uint = category
sql_attr_uint = comments_count
sql_attr_bool = verified
sql_attr_bigint = size

1 Answers1

2

Have you tried using that column as sql_attr_string?

http://sphinxsearch.com/docs/current.html#conf-sql-attr-string

You need at least version 2.0.1 to use an ORDER BY clause on such attribute:

Starting from 2.0.1-beta string attributes can be used for sorting and grouping(ORDER BY, GROUP BY, WITHIN GROUP ORDER BY).

Vojtech Kurka
  • 875
  • 9
  • 10