开发者

How to get text result in SPHINX

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
 开发者_如何学Python   [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 ?


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.


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,

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜