WordPress Blog Search from Rails Application

I have a custom written search controller for my Rails 3 application and would like to include results from the WordPress site blog. What is the best way to search for keywords in messages from my Rails application?

+4
source share
6 answers

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).

+5
source

An interesting problem. I think I would approach him like this:

  • Use RSS as the transfer of text from a blog to a rails app. This allows you to flexibly add more blogs in the future, change the blog engine, database host, etc. It also protects you from Wordpress code updates. Given the security history of Wordpress, I like to place them in a secure sandbox anyway. RSS is the native language for blogs, so it seems like a natural help for this kind of content integration.

  • Use feedzirra gem to import RSS entries into the rails model.

  • Use Elasticsearch and tire to find fuzzy text for your rails application and blog entries. See this Railscast for more details.

+1
source

Option 1. should use a search engine for both sites, such as elasticsearch, solr, etc. This way you populate the index from rails and wordpress.

Option 2. You write a script that periodically reads your wordpress RSS and saves the data in your rails application.

In the end, you should avoid searching from different sources, you should collect data in one place and then perform a search.

0
source

You do not need to get stuck in wordpress. You can use the Google search API. Web search api is out of date but still works . Its replacement is a custom search API . You may have to pay if you request a cap.

Alternatively, you can use other search engine APIs, such as the Bing Search API .

0
source

I would suggest using the Wordpress JSON API and connecting it to the search using solr or something similar. You can index when posts are created and then invoke articles through the sam JSON interface.

0
source

Use Tire and wp-elasticsearch with ElasticSearch.

0
source

Source: https://habr.com/ru/post/1442654/


All Articles