Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the sphinx ql expression? #1033

Closed
joshweir opened this issue Dec 20, 2016 · 1 comment
Closed

How to get the sphinx ql expression? #1033

joshweir opened this issue Dec 20, 2016 · 1 comment

Comments

@joshweir
Copy link

pancakes = Article.search 'pancakes'

How would I then get the resultant underlying sphinxql expression?
Is it possible to just retrieve the expression without performing the query?

Thanks

Josh

@pat
Copy link
Owner

pat commented Dec 20, 2016

Hi Josh

To find the SphinxQL statement, you can do the following:

pancakes = Article.search 'pancakes'
pancakes.populate
pancakes.context[:sphinxql].to_sql

However, if you want to get that without actually sending the query to Sphinx, you'll want to send through a much more minimal middleware stack:

middleware = ::Middleware::Builder.new do
  use ThinkingSphinx::Middlewares::SphinxQL
end

pancakes = Article.search 'pancakes', :middleware => middleware
pancakes.populate
pancakes.context[:sphinxql].to_sql

You can also send the :populate => true option through as part of the search options instead of calling populate on the search object, to save a line of code. TS search results are lazily loaded, hence the need for that when accessing the context data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants