Question

Assume I'm indexing a table of books. They have title, author, description, etc.

I want to do a search across all fields and return the title of the books that contain my search term. I can do a search and return the book_id (doc_id) from Sphinx so I can look them up myself, but what would be really awesome is if Sphinx just gave me the titles so I don't have to hit the database at all. I can get Sphinx to return different attributes to me, but getting a text field is eluding me.

Is this possible? If so, how do you do it?

[Update] Found this today: http://www.sphinxsearch.com/faq.html#row-storage

Was it helpful?

Solution

Hate to kill the idea so quickly, but it's not possible. Sphinx doesn't return any information about the values of fields, nor even which fields provided a match on the query.

And to elaborate a little more... Sphinx usually loads all attribute values into memory, which is probably why it's fine with returning them for each result. It could be that fields are stored in a non-reversible encoding, and so can't be translated back to normal values? That's a stab in the dark, though.

OTHER TIPS

There some trick is. As I answer before, you could add these column you wanna get to the attr entries, then you could just pick the value from the result from sphinx.

May it be helpful for you :D

In case you have a small amount of data in text fields then you can use Sphinx string attributes.

sql_attr_string

But, it have some limitation like:

String attributes can store arbitrary strings attached to every document. There's a fixed size limit of 4 MB per value. Also, searchd will currently cache all the values in RAM, which is an additional implicit limit.

So, it would be not good idea to store a lot of data in them, because all attributes are stored in RAM.

There's been some progress on this front. Now, if you use SphinxSE, you can join the SphinxSE table which you search on to the table the index was generated on, and get your title's that way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top