If you are sharing a database, just use the SQL query. This solution gives you the speed of a direct db request, but you need to build this request correctly in order to get all the relevant data.
If you do not have access to the WP database from your Rails application, the best way would be to use curl, httparty, RestClient, or any other file search library.
To do this, create a Wordpress page with a custom template that will display the search results in the format that is best suited for analysis in a Rails application (json, xml, csv, urlencoded, whatever).
Then request this WP page from your Ruby application using curl / RestClient / httparty ...
This solution gives you the ability to use the tags and features of WP templates to get results.
In addition, instead of creating a custom template from scratch, you can simply copy and configure the search.php file from the main template to provide the results in the format required by your Rails application.
With this solution, you lack the speed of direct access to db, because all search results must be transmitted via http pipe, and you will have to process the data twice (encode to the appropriate format in WP and decode in the Rails application).
source share