2

I'm trying to use Sphinx API to get the text result all I get is something like this:

16809 Array (
    [error] =>
    [warning] =>
    [status] => 0
    [fields] => Array (
        [0] => name
        [1] => description
    )
    [attrs] => Array ( )
    [matches] => Array (
        [16809] => Array ( [weight] => 2 [attrs] => Array ( ) )
    )
    [total] => 1
    [total_found] => 1
    [time] => 0.000
    [words] => Array (
        [radell] => Array (
            [docs] => 1
            [hits] => 2
        )
    )
)

I'm using the following additional lines in sphinx.conf:

sql_query                       = \
            SELECT \
                    id, name, description \
            FROM \
                    products_description;
sql_field_string = name
   sql_query_info = SELECT * FROM products_description WHERE id=$id

Is it possible to get the full text result like name and description instead of above array ?

5
  • Could you please provide the PHP code you used to do the query and produce the var_dump() results above? Aug 21, 2011 at 12:52
  • 2
    Pending that code to provide additional information, the short version is you should take that value, 16809, and use it as a parameter in a query to SQL SELECT name, description FROM products_description WHERE id = ? Aug 21, 2011 at 12:54
  • I have provided the php code. Please check it now
    – fawad
    Aug 21, 2011 at 20:23
  • Thanks, you have solved my problem. You are right. I can use that ID number to fetch the text record.
    – fawad
    Aug 21, 2011 at 20:39
  • Sphinx does not save the text it indexes. You can't get the content of the text fields in the result. You can only know if they matched. The returned values will only be the attributes, and among the document ID. This is the main concept of Sphinx Search. So the way proposed by Conspicuous Compiler is the only way.
    – user699082
    Aug 22, 2011 at 3:08

2 Answers 2

4

Sphinx provides you the index of your database record but not store it. You have to fetch the id from search result and write another sql select to fetch data from that row.

1

Ok, I think you can get the string data from the 1-10beta version of Sphinx. You can add the fields you need as attributes in your source definition.

Check here what you need to use:

sql_attr_string explanation in SphinxSearch.com

For example,

I have an index with events data:

sql_query = \
            SELECT\
                    p.place_id,\
                    p.place_id as place_id_attr,\
                    ...
                    ...
            FROM\
                    places p\
                    .......
                    ....
            GROUP BY\
                    p.place_id

    sql_attr_uint = place_id_attr
    sql_field_string = title
    sql_field_string = title_normalized
    sql_field_string = subtitle
    sql_field_string = description
    ....

In that way you have your fields available from the php code inside the attrs array.

One important detail: I'm using sql_field_string because I make some operations with the texts, I mean, filters, orders and so. If you need only the information you could use sql_attr_string as they explain in the link I posted.

I hope this helps! :)

bests,

2
  • But I have heard that this returned data will be loaded into server RAM. If i get lot of records against the search query the server performance can be effected. Is that right?
    – fawad
    Aug 24, 2011 at 7:38
  • Yes, all the data inside the indexes is loaded in RAM. You cannot get it all :), but it is useful if you want to show the results in a search results page for example, only with a few fields as attribs. Aug 31, 2011 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.