tag:support.flying-sphinx.com,2011-01-05:/discussions/questions/399-two-searches-in-one-roundtripFlying Sphinx: Discussion 2022-05-03T20:47:16Ztag:support.flying-sphinx.com,2011-01-05:Comment/449377362018-03-20T12:37:55Z2018-03-20T12:37:55ZTwo searches in one roundtrip?<div><p>Hi Roger,</p>
<p>It is indeed possible to send two search queries in a single call to Sphinx. Presuming you're using TS v3, this syntax should do the trick:</p>
<pre>
<code>batch = ThinkingSphinx::BatchedSearch.new
batch.searches << Model.search("foo")
batch.searches << Model.search("bar")
batch.populate
batch.searches.each do |search|
# ...
end</code>
</pre>
<p>Keep in mind that if you're testing this in a Rails console, the inspection of a search results set populates the data immediately, which would make this fail. An easy way around this is to add <code>; ""</code> at the end of lines that involve search calls. e.g.:</p>
<pre>
<code>batch.searches << Model.search("foo"); ""</code>
</pre>
<p>All of that said… if you need the values from the first search to be used in the second, I'm afraid that's not possible in Sphinx.</p></div>Pat Allantag:support.flying-sphinx.com,2011-01-05:Comment/449377362018-03-20T12:48:07Z2018-11-28T10:06:44ZTwo searches in one roundtrip?<div><p>Hey, that's awesome. Can't believe I didn't stumble across this when googling.</p>
<p>Thanks, Pat!</p></div>rogertag:support.flying-sphinx.com,2011-01-05:Comment/449377362018-03-20T13:09:51Z2018-03-20T13:09:51ZTwo searches in one roundtrip?<div><p>Mostly it's not documented, and it's rarely requested, so it would have taken quite some googling!</p>
<p>Though I've realised it's not in the documentation at all - and I've been working on that for the upcoming v4 release, so I'll make sure it gets added shortly.</p></div>Pat Allan