ActiveResource is a great concept which consumes rails-style REST API but unfortunately most of the REST API's are not rails-style. This means that very frequently you will end up modifying ActiveResource to consume non rails-style REST API's. This article is about understanding ActiveResource and how to tweak/extend it to consume non rails-style REST API's. We will mainly concentrate on reading data i.e. the GET method.
Writing a web widget 4
Web widgets are widely used across the Internet but still lacks good documentation. From online advertisement to videos to blogs, widgets are highly used. Some of the popular widgets being Google Adsense, Youtube, MyBlogLog widgets and Twitter badges.
Note: This page will be slow to load because of many widget examples.
Table of Contents
To formally define : The web widget is a portable chunk of code that can be installed and executed within any separate HTML-based web page by an end user without requiring additional compilation. A widget adds some content to that page that is (mostly) not static. Generally widgets are third party originated, though they can be home made. Widgets are also known as modules, snippets, and plug-ins.
This article is my journey of understanding and making a widget myself. I have tried to make things look simple and insightful by taking a lot of examples.
Advanced acts_as_solr 6
This article extends our acts_as_solr : search and faceting tutorial and talks about how to manage rails associations, solr indexes and more with acts_as_solr.
Table Of Contents
- Rebuild Solr index
- Import existing Solr index or your custom Solr schema.xml
- Highlight search term
- Rails associations and acts_as_solr
- Tips
Rebuild Solr Index
rebuild_solr_index is a class method to re-build your model indexes on import of external data. For large tables rebuilding Solr index is a time consuming process. See the fifth line in the pseudo code below (index optimization call), it makes rebuild_solr_index a slow process. For large tables, you do not want optimization to take place for each object added to the table. Whereas, removing optimization calls slows down the process of updating solr index.
1 2 3 4 5 6 7 |
## pseudo code
def rebuild_solr_index
for_each_row_in_table do |doc|
doc.save_to_solr_index
index.optimize
end
end |
The solution to the problem is to use batch_size in #rebuild_solr_index. With batch size, say for example 100, the index optimization call is executed after indexing 100 rows.
acts_as_solr : search and faceting 17
Table of Contents
Solr and acts_as_solr
Solr is a search server based on lucene java search library with a HTTP/XML interface. Using Solr, large collections of documents can be indexed based on strongly typed field definitions, thereby taking advantage of Lucene's powerful full-text search features.
acts_as_solr is a ruby on rails plugin adding Solr capabilities to activerecord models. It hides all configuration and manual setting efforts with Solr and provides you with simple find_by... methods. acts_as_solr can be used as a replacement to
acts_as_ferret because of inbuilt full text search capabilities ;-) . The purpose of this article is to explain acts_as_solr with examples.
Getting Started
Installation: Installation is well explained on acts_as_solr homepage and getting started with acts_as_solr
Note: acts_as_solr requires jre1.5 on system. Before running any of the solr methods make sure you start solr server with rake solr:start command.
Our example model for this tutorial will be DigitalCamera [classname: Camera] with following fields
- name (type:string)
- brand (type:string) [we want faceted browsing on this field]
- resolution (type:float) [we want faceted browsing on this field]
- other fields which we do not want to index
