pat / thinking-sphinx

Sphinx/Manticore plugin for ActiveRecord/Rails
http://freelancing-gods.com/thinking-sphinx
MIT License
1.63k stars 468 forks source link

SHOW META not behaving in batch queries #1214

Closed jdelStrother closed 2 years ago

jdelStrother commented 2 years ago

Hi there - I noticed that our batched queries have started behaving oddly. Something like this:

batch = ThinkingSphinx::BatchedSearch.new
batch.searches << Model.search("foo")
batch.searches << Model.search("bar")
batch.populate

batch.searches.each do |search|
  puts search.total_entries
end

would give the same total_entries for each search term.

I think I've reduced the problem down to this, which is essentially what ThinkingSphinx is doing in ThinkingSphinx::Connection::MRI :

client = Mysql2::Client.new(port: 9306, host: '192.168.86.22')
results = [client.query("SELECT * FROM `audio_clip_rt_core` WHERE MATCH('red') LIMIT 0, 1; show meta; SELECT * from `audio_clip_rt_core ` WHERE MATCH('blue') limit 0, 1; show meta;")]
results << client.store_result while client.next_result
results.each{|r| puts "---"; r.each{|a| pp a} }

which prints:

---
{"id"=>63368728,
 "sphinx_deleted"=>0,
 "sphinx_internal_id"=>7921091,
 "sphinx_internal_class"=>"AudioClip"}
---
{"Variable_name"=>"total", "Value"=>"1"}
{"Variable_name"=>"total_found", "Value"=>"1"}
{"Variable_name"=>"time", "Value"=>"0.003"}
{"Variable_name"=>"keyword[0]", "Value"=>"blue"}
{"Variable_name"=>"docs[0]", "Value"=>"1"}
{"Variable_name"=>"hits[0]", "Value"=>"1"}
---
{"id"=>63370232,
 "sphinx_deleted"=>0,
 "sphinx_internal_id"=>7921279,
 "sphinx_internal_class"=>"AudioClip"}
---
{"Variable_name"=>"total", "Value"=>"1"}
{"Variable_name"=>"total_found", "Value"=>"1"}
{"Variable_name"=>"time", "Value"=>"0.003"}
{"Variable_name"=>"keyword[0]", "Value"=>"blue"}
{"Variable_name"=>"docs[0]", "Value"=>"1"}
{"Variable_name"=>"hits[0]", "Value"=>"1"}

Note the same keyword appearing in both META results. It appears as though given a multi-statement query LIKE SELECT ...; SHOW META; SELECT ...; SHOW META, the results returned for both SHOW METAs are that of the last SELECT statement.

I'm pretty sure this wasn't always the case. I can reproduce the problem against Sphinx 3.3.1 & 3.4.1, but not against an aged 2.2.11 server.

Seems hard/impossible to fix for batched queries, but wondered if it was a known limitation or if you'd run into it before.

pat commented 2 years ago

Well that's frustrating indeed, but well done on all the debugging!

I have previously managed to get the TS test suite green with Sphinx 3.4, but the batched search testing doesn't look at metadata - so essentially: this isn't a known limitation nor something I've run into previously.

I wonder if it's worth reporting as a bug? - though I must admit, the inconsistent communication around Sphinx (and the fact it's now closed source) is a bit concerning. I'm not sure if it's worth giving Manticore a try as a drop-in replacement given the development there seems more active and open (though I'm still working on getting TS tests passing with v4.2).

jdelStrother commented 2 years ago

though I must admit, the inconsistent communication around Sphinx (and the fact it's now closed source) is a bit concerning.

yeah, likewise. We'll see what they say - http://sphinxsearch.com/bugs/view.php?id=2751

pat commented 2 years ago

@jdelStrother just catching up on open-source chores - I'm going to close this issue, given the bug seems to be with Sphinx itself. I'd be curious as to whether you can reproduce this issue with Manticore though!