Customising SQL Query

12 views
Skip to first unread message

Simone Miller

unread,
Nov 7, 2022, 5:51:24 AM11/7/22
to Thinking Sphinx
Hi Pat

Hope you're keeping well.

We're using a thinking sphinx search and we'd like to chain additional sql generating active record queries on to the search. Ideally, we wouldn't want to run the query or load the models immediately, so that we can maintain a consistent code flow to instances where a search is not applied.

We've seen we can define sphinx scopes and provide options within the search itself - e.g. sql, select, with etc. Would there be a way to do this from the outside - e.g. Article.search('pancakes').any_further_queries (that weren't sphinx scopes)?

Many thanks
Simone

Pat Allan

unread,
Dec 29, 2022, 10:26:18 PM12/29/22
to thinkin...@googlegroups.com
Hi Simone,

I'm sorry for the slow response.

It sounds like you may have already found the `:sql` option for search calls to pass through a limited set of SQL-based options as part of populating the search results:
https://freelancing-gods.com/thinking-sphinx/v5/searching.html#advanced

Granted, that's quite old, and the syntax was inspired by ActiveRecord's pre v3 approach. 😓 But there isn't anything else of this manner in Thinking Sphinx.

I realise it may not be ideal, but I would recommend instead querying Sphinx for the instance ids (using Article.search_for_ids instead of Article.search), and then - as/when needed - perform the SQL query using those ids. This avoids the initial SQL query to populate the search results as ActiveRecord objects. Would this be feasible in your situation?

Kind regards,

-- 
Pat
--
You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thinking-sphi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/thinking-sphinx/d2a693ca-6169-444c-a7bf-5ca23c7f590cn%40googlegroups.com.

Simone Miller

unread,
Feb 12, 2023, 1:31:36 PM2/12/23
to thinkin...@googlegroups.com
Hi Pat, 

Thanks for coming back to us - we'll give it a try! Have a great week, 

Kind regards
Simone

You received this message because you are subscribed to a topic in the Google Groups "Thinking Sphinx" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/thinking-sphinx/10ubCjBQkRY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to thinking-sphi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/thinking-sphinx/f2d4ed46-4914-416c-84e4-34a9f940023a%40Spark.
Reply all
Reply to author
Forward
0 new messages