pat / riddle

Ruby Client API for Sphinx
MIT License
135 stars 67 forks source link

string and json attributes retrieved empty in matches #96

Closed kapcod closed 8 years ago

kapcod commented 8 years ago

It might be API bug and not Riddle, but when I connect to sphinx with mysql client all attributes are returned and through Riddle string attributes returned empty. Tried with sphinx 2.2.10.

pat commented 8 years ago

Presuming this is related to #97?

kapcod commented 8 years ago

I think quite vice-versa :) Meaning that I need to be able to retrieve regular stored string attributes, unrelated to group_concat. I just think that if this one will be fixed, we can try to tweak group_concat too (#97).

kapcod commented 8 years ago

Hey, Pat, is there a chance that someone will look at it? Or there's no way but to switch to thinkingsphinx? I tried to find any place in documentation that says that this is not supported in API but couldn't.

pat commented 8 years ago

Hi Ilya

Sorry for the delay, this year is not giving me as much time for open-source support as I'd like.

I've just done some manual testing with Sphinx 2.2.10, and I'm seeing both string and JSON attributes being returned for matches with the appropriate data, via the binary protocol. This remains the case when I group by either of those attributes. The generated @groupby attribute has an integer value instead, mind you, but that's a limitation of Sphinx, from what I understand.

As for the idea of switching to Thinking Sphinx: that's not quite what I meant. It was more that you may want to switch to Sphinx's SphinxQL/mysql41 protocol (which is what Thinking Sphinx uses) and then run SphinxQL queries against your daemon instead of using Riddle::Client - and to do that, you'd need to use the mysql2 gem (and the Thinking Sphinx source code may be a helpful reference in that case).

Still, I'm finding things are working with the older binary protocol… but you've mentioned group_concat in both this issue and #97: can you elaborate on the query you're running using that, so I can test that finer detail more accurately?

kapcod commented 8 years ago

Hi, you're right, I had riddle 1.5.9, for some reason it was capped in my Gemfile. With 1.5.12 string attributes work and with small tweak also group_concat works. Here's the tweak (I can create full pull request, but don't have time currently):

AttributeTypes[:group_concat] = 10
AttributeHandlers[AttributeTypes[:group_concat]] = :next

The way i'm using group concat is as following:

    @riddle.group_by = 'type_id'
    @riddle.group_function = :attr
    @riddle.group_clause = "type_id desc"
    @riddle.select = "*, group_concat(id) AS ids"
pat commented 8 years ago

Thanks, just pushed a commit to develop with your tweak :) Great to know it's all working now!

kapcod commented 8 years ago

Cool. I couldn't find any docs, though, that describe this attribute type 10. Could be that it's not only group_concat, but any function added in query-time in "select" clause (min, max, in, etc.). Need to test further.