dcsimg

Sunspot: A Solr-Powered Search Engine for Ruby

Search can make or break your website. Sunspot and Solr give you an intuitive engine that maps directly to your Ruby objects.

As your site amasses content — be it stories, SKUs, or statistics — a tailored, effective, and exacting search engine becomes increasingly vital. Imagine a bookstore that doesn’t index its tomes by title or author, or a clothing retailer that doesn’t index garments by size. Without search, each site is useless. In general, the quality and relevance of search results makes or breaks a site.

Typically, at least some search results are generated by the site’s underlying database. A database can maintain and catalog enormous volumes of data. Thus, an inquiry for an obscure piece of content would likely fall to the database since it’s the canonical repository. Complex, multi-variate queries may also fall to the database as it’s designed specifically for the purpose.

However, a database query can be slow. Like any engineering feat, a database has strengths and weaknesses and one size rarely fits all. Hence, it’s also typical for other actors to provide search results. For instance, a content management application might use an entirely separate engine to index the prose and respond to keyword, phrase, and proximate searches.

Of course, it’s also de rigueur for an application to maintain one or more RAM-resident indices to speed common lookups and preclude repetitive computations. Additionally, software such as memcached provides surrogate memory extending across multiple machines.

Each technique—the (relational or object) database, special-purpose engine, and in-memory data structures—is a viable option; whether one, some, or all of the approaches are valid depends on the application at hand.

You are no doubt familiar with MySQL, SQLite, Oracle, and any number of other database packages. Each is capable, and there are scores of strategies to tune performance, from writing efficient queries, to tuning the database host’s I/O subsystem. You are also likely familiar with memcached, Squid, and other helpful proxies (both figurative and literal) that offload work from the database and application server. You can find plenty of books on the latter subjects.

And what about the specialized search engine? Certainly, there are plenty of commercial text indexers (FAST, Documentum) and even a few open source solutions (Zebra, Lucene, Sphinx), but what if you need to index 350,000 auto parts, 50,000 email messages, or 4,000 grocery items?

If you code in Ruby, Sunspot is an ideal solution for any of those inventories. Created by Mat Brown, Sunspot is an intuitive and expressive domain specific-language for indexing and searching Ruby objects. Sunspot is powered by Solr, the open source enterprise search server based on Lucene. Solr can highlight matches, replicate its index across many servers, shard indices, and, for the purposes of this discussion, perform advanced full-text and faceted searches.

Wanted: Indexing Engine. Apply Within.

To search your data with Sunspot, you create an index for one or more classes, populate the index, and then search using any of the indexed fields. Here’s an example use of Sunspot to index books for sale.

class Book
  # A book includes instance variables for
  # the author, a title, a publisher, an edition, a 10- and 13-digit
  # ISBN number, a blurb, a publication date, and a price.
end

To create an index, call the class method Sunspot.setup(class) block, where class is the name of the Ruby class to catalog, and block is a list of Sunspot declarations (part of Sunspot’s domain-specific language) to describe how Solr should treat one, some, or all class attributes.

Sunspot.setup(Book) do
  text    :author
  text    :blurb
  integer :edition
  string  :isbn10, :isbn13
  float   :price
  time    :published_at
  text    :publisher
  string  :sort_title do
    title.downcase.sub(/^(an?|the)\W+/, '') if title = self.title
  end
  text    :title
end

float and time and the others are Sunspot DSL keywords to define Solr types. Most of the type keywords are eponymous, but string and text require a little clarification. Use the former for values (like a UPC code) where full-text indexing doesn’t make sense; use the latter for full-text fields.

The code above builds an index for all attributes of a Book, since a consumer might want to search or sort on any of those values. The code also adds a virtual attribute, :sort_title, to help improve the readability of search results. You can search the entire text of :title and sort results either by :title or :sort_title.

The next step is to populate the index with data. (The previous step merely describes what fields to index, but does not catalog values). Assuming you’ve created a new collection of books in the array book_list, adding the books to the index requires just two statements.

Sunspot.index( book_list )
Sunspot.commit

The first statement adds each book in the list book_list to the in-memory Solr index. The second statement commits the new additions to the index to the Solr instance’s persistent store.

Sunspot for Ruby includes other methods to manipulate the index, too, such as remove(instances) and remove_all(classes). The former removes one or more instances from the index; a subsequent commit is required to affect the persistent index. (Optionally, you can call remove!(instance) to delete and commit in one fell swoop.) The latter method removes all instances of one or multiple classes from the index, (and has an analog remove_all!(class(es)) to implicitly commit.

And, naturally, there is a method to search and provide a variety of criteria.

Sunspot.search(Book) do
  facet :publisher
  keywords 'Zaphod'
  with(:edition, 1)
  with(:price).less_than 19.99
  order_by :sort_title
end

The query above says, “Search the current index for all first edition books less than $19.99 where ‘Zaphod’ appears in a full-text field, and return the results sorted by the special sorting title.” In addition to those results, the statement facet :publisher also produces a list of publishers whose books match the criteria. You can use a facet to drill down and produce a list of matching books sold by a specific publisher.

Next: Show Me the Code

Comments on "Sunspot: A Solr-Powered Search Engine for Ruby"

That could be the end of this write-up. Here you will find some web sites that we feel you?ll value, just click the hyperlinks.

Please stop by the web pages we follow, such as this a single, because it represents our picks through the web.

Although websites we backlink to below are considerably not associated to ours, we really feel they may be really really worth a go by way of, so have a look.

The time to read or pay a visit to the subject material or sites we’ve linked to below.

Wonderful story, reckoned we could combine a handful of unrelated data, nonetheless seriously really worth taking a look, whoa did one understand about Mid East has got more problerms at the same time.

Woah! I’m really loving the template/theme of this site.
It’s simple, yet effective. A lot of times it’s challenging to get that “perfect balance” between superb usability and visual appeal.

I must say you have done a fantastic job with this.
Additionally, the blog loads extremely fast for me on Internet explorer.
Exceptional Blog!

Also visit my web blog: replica hermes birkin

Always a huge fan of linking to bloggers that I like but do not get lots of link appreciate from.

Check below, are some entirely unrelated web sites to ours, nonetheless, they may be most trustworthy sources that we use.

One of our guests recently suggested the following website.

We came across a cool internet site that you simply may well love. Take a look in the event you want.

Just beneath, are numerous entirely not connected sites to ours, however, they’re surely worth going over.

It’s an remarkable article in favor of all the online people; they will obtain benefit from it I am sure.

Here is my homepage: Anna

Heya i’m for the first time here. I came across this board and I find It really useful & it helped me
out a lot. I hope to offer one thing back and help
others like you aided me.

Take a look at my blog: buy cheap Twitter followers

What’s up, just wanted to say, I liked this
article. It was practical. Keep on posting!

Also visit my weblog; http://jdeb71.fr/wp/?page_id=72

Although internet sites we backlink to below are considerably not connected to ours, we feel they’re essentially worth a go by way of, so have a look.

Here is a good Weblog You might Discover Exciting that we encourage you to visit.

Check beneath, are some completely unrelated internet websites to ours, even so, they are most trustworthy sources that we use.

The time to study or pay a visit to the material or websites we’ve linked to below.

Men love to wear Classy or modern kurta and shalwar kameez in these days.
Tissot watches are one of the important brands in the popular watch Group.
Mc – Q trainers are well worth a look if you are looking to up your footwear collection this year.

Feel free to visit my homepage: giuseppe zanotti uk

We like to honor quite a few other internet web pages on the net, even though they aren?t linked to us, by linking to them. Under are some webpages worth checking out.

One of our guests recently proposed the following website.

Here is a superb Weblog You may Locate Intriguing that we encourage you to visit.

Here is a good Blog You might Uncover Interesting that we encourage you to visit.

Please stop by the web sites we stick to, like this one, because it represents our picks in the web.

Wonderful story, reckoned we could combine a number of unrelated data, nevertheless truly really worth taking a search, whoa did one discover about Mid East has got far more problerms too.

Below you?ll locate the link to some internet sites that we assume you must visit.

Very handful of web-sites that happen to be in depth below, from our point of view are undoubtedly effectively worth checking out.

We prefer to honor a lot of other world wide web web-sites on the internet, even though they aren?t linked to us, by linking to them. Below are some webpages worth checking out.

In between both of these releases the Jordan 6 Rings used the epic colorway that has been dubbed “Concord”.
A quick tip is to take care to not bring your knees up actively as you might when you are jogging.
Along with the Max Air cushioning system, this
edition is finished off with a clean white outsole.

my page cheap jordan shoes

Usually posts some incredibly exciting stuff like this. If you are new to this site.

Here are several of the websites we advocate for our visitors.

Always a massive fan of linking to bloggers that I enjoy but do not get lots of link enjoy from.

Here is a great Blog You may Obtain Interesting that we encourage you to visit.

Please visit the web pages we stick to, which includes this one, because it represents our picks from the web.

Firstly, there’s nothing wrong with warm to eat. There are some individuals who dwell to enjoy and also there are several exactly who eat to reside in. But the complete people isn’t going to are part of either of such classes. There are several that adore excellent meal, yet their own life rely on thier food. Tavern meal Cheshire is actually beloved in several parts of the country along with for anyone who is some sort of foods significant other, you should knowledge the type of foodstuff you get here. Go to a loved ones bar Cheshire and enjoy the finest foodstuff in addition to refreshments using your entire household. You’ll find nothing completely wrong with caring you can eat. There are some people who stay to consume along with there are many that take to call home. Though the entire human race isn’t going to are part of both of the types. There are many which really like good foods, although their own lifestyles be based upon the meals. Pub foodstuff Cheshire is actually adored in many places and for anyone who is some sort of foodstuff significant other, you must knowledge the sort of food you will get in this article. Check out a household bar Cheshire and you may take pleasure in the ideal food in addition to products together with your overall family. The word bar is often connected with grownups. The greatest brs in the country are generally occupied by means of sports activities fans which love to discover their squads challenge the idea away while they sip light beer and beer and the like. Although it’s not important your young children can’t go to the tavern. Without a doubt, there are a few cafes which you wouldn’t prefer to take the kids for you to. However a family pub Cheshire isn’t amongst these types of companies. This tavern meals Cheshire within this bar is really great which everyone extends to take pleasure in in some manner or maybe the other. That household bar Cheshire affords the finest with United kingdom food. You can find lots of people saying that Uk food just isn’t as good as the foodstuff that is certainly prepared inside the some other international locations just like People from france along with The nation while others. Also, the actual influx regarding Native american curries offers further altered this colour scheme on the United kingdom foodies. But the truth is which Uk foodstuff has its very own fantastic tastes. You consume typical United kingdom meals therefore you cannot aid although nearly lick your current palms. Without a doubt, this matters that the cooking is extremely good, yet after you check out the best place regarding nightclub meals Cheshire, you can expect this chief cook being at the top of his or her food preparation ability. Within this loved ones club Cheshire you will get every thing you intend to take in addition to take in. Within the refreshments section you have the optimum cask beers, English in addition to brought in beer, cider in addition to a thorough collection of wine beverages. The meal menu is also comprehensive and also you have the option available this restaurant food selection, the 2-for-1 selection, the particular bar menus and the Weekend food selection. The mouth-watering dinners usually are sure to generate you sense more than content. In the event that you would like possessing this club foodstuff Cheshire, go to the site as well as look into the particular food selection. All the information which you will want can be provided in the web page such as the number for you to telephone to generate your booking. On weekdays you might come to the actual cafe and discover a spot, but throughout weekends, it really is foolhardy trying to find a location without a reservation. In any case, it’s wise to help book in advance irrespective of when you’re in. Get more information on the web to be able to taste superb tavern meals Cheshire. At this spouse and children pub Cheshire you will get all those foods that produce an individual delighted. The costs tend to be properly affordable, nevertheless the meals is actually outside the world.

To begin with, nothing is wrong along with supportive to consume. There are some individuals who reside you can eat as well as there are some whom take in to reside. However the overall people isn’t going to remain in sometimes of the categories. There are numerous that enjoy good foods, although the day-to-day lives count on the food. Club meal Cheshire can be loved in many parts of the country and also for anyone who is a new food partner, you should encounter the amount of foods you get in this article. Go to a household nightclub Cheshire and experience the greatest food and also beverages with your overall spouse and children. There’s nothing inappropriate having loving to consume. There are some people that live to consume and there are numerous whom try to eat to live. Even so the whole human race will not fit in with both these groups. There are a few exactly who love excellent food, nevertheless the day-to-day lives be determined by thier food. Bar food Cheshire is adored in many areas and also should you be a meal partner, you must knowledge the type of foods you have right here. Search for a family pub Cheshire and you’ll experience the ideal food and drinks along with your complete spouse and children. The saying bar is usually connected with grown ups. The greatest bars near you tend to be filled by simply sporting activities fans that want to observe their particular groups challenge the idea available as they drink draught beer along with beer and the like. Yet it’s not necessarily necessary that your particular youngsters can’t go to the pub. Of course, there are some pubs that you simply wouldn’t like to take your children to. Although loved ones bar Cheshire seriously isn’t amongst most of these shops. The particular bar food Cheshire in this particular tavern can be so wonderful which anyone actually reaches take pleasure in in some manner or additional. This specific household club Cheshire affords the finest in English foods. You will find many people saying that will Uk foods just isn’t as good as the food that may be organized within the some other places just like Italy and also The world and the like. In addition, the actual increase of Indian native curries features further changed the actual color scheme from the British foodies. Although truth be told of which United kingdom food possesses a great tastes. You eat normal British isles food and you are not able to help yet practically coat your fingers. Sure, this issues that the chief cook is excellent, but once you pay a visit to a good option regarding bar food Cheshire, you will probably have this cocinero to be at the top of his or her preparing proficiency. With this spouse and children pub Cheshire you receive anything you would like to take in as well as ingest. Inside products area you have the best cask ales, United kingdom in addition to brought in lager, cider and a substantial collection of wine beverages. The meals selection is usually intensive and also you have the option available your cafe food list, this 2-for-1 food selection, the particular bar selection and also the Sunday menu. Your mouth-watering pots and pans tend to be certain to make you really feel in excess of pleased. If you would like having this kind of nightclub foods Cheshire, visit the web page in addition to have a look at the menu. All the information that you need is presented inside internet site including the range in order to telephone to create your booking. With weekdays you could arrive at your restaurant and discover a location, but through weekends, it is foolhardy trying to find a place and not using a reservation. Whatever the case, it’s wise to arrange in advance irrespective of when you’re. Read more on-line to be able to trial outstanding tavern meals Cheshire. At this family members club Cheshire you might have all those foodstuffs that make people happy. The values are generally nicely affordable, even so the foods is merely outside the planet.

Firstly, nothing is inappropriate using loving you can eat. There are some individuals who dwell you can eat along with there are a few which consume to reside. Even so the overall people won’t fit in with sometimes these classes. There are numerous who adore beneficial meal, but the existence be determined by thier food. Pub foods Cheshire is liked in numerous parts of the country and also should you be a foods partner, you should practical knowledge the type of foods you receive the following. Go to the family tavern Cheshire and benefit from the very best foodstuff as well as products with all your whole household. Absolutely nothing is inappropriate along with loving to nibble on. There are numerous people that dwell to consume as well as there are many exactly who take in to live on. Nevertheless the complete people isn’t going to remain in both of those types. There are a few who adore very good foods, nevertheless the existence be based upon the foodstuff. Tavern meals Cheshire can be beloved in most places as well as in case you are a new foodstuff significant other, you must experience the kind of meal you obtain in this article. Search for a family members tavern Cheshire and you may benefit from the finest foodstuff in addition to refreshments with all your entire loved ones. The word tavern is usually connected with adults. The biggest bars in the united kingdom are usually entertained by simply sports activities enthusiasts who love to view their particular clubs fight the item available when they drink beer as well as lager etc. Although it isn’t necessary that your particular little ones can not visit a club. Yes, there are a few pubs that you just won’t like to acquire the kids for you to. Nevertheless children club Cheshire just isn’t among these kinds of companies. The actual tavern food Cheshire on this nightclub can be so great that everyone gets to delight in somehow as well as the other. That family members pub Cheshire provides the best with United kingdom meals. You will find many individuals expressing that United kingdom foodstuff just isn’t as effective as thier food that is certainly organized inside the other nations including People from france in addition to The world and others. In addition, the particular influx involving Indian native curries has more improved the particular colour scheme from the British isles foodies. Although truth be told that will United kingdom meals offers a unique good style. You take in normal English meals therefore you can not help nevertheless almost coat your current arms. Of course, the idea issues that the cooking is fantastic, nevertheless when you go to the absolute right place intended for tavern foods Cheshire, you could expect this cook for being presents itself their particular food preparation skill. In this family nightclub Cheshire you receive anything you want to take in along with take in. Within the beverages portion you might have the best possible cask ales, Uk and also imported lager, cider and also a thorough variety of wine drinks. The food food selection is usually considerable so you have the option to choose from the particular diner food list, the 2-for-1 menus, your clubhouse food selection plus the Saturday selection. The actual mouth-watering meals are bound for making you are feeling a lot more than pleased. In case you are searching for acquiring this particular bar meals Cheshire, visit the web site and check out this food list. All the information which you are required is offered inside internet site such as the amount to help phone to make your own booking. With weekdays you could possibly reach this restaurant and find a location, nevertheless while in weekends, it really is foolhardy looking to find the place without a reservation. Whatever the case, it feels right in order to hold before hand no matter what when you go. Find out more on the web to be able to trial excellent bar foods Cheshire. Only at that household tavern Cheshire you could have the many meals which make a person content. The values are generally effectively affordable, nevertheless the food is simply from the world.

Always a major fan of linking to bloggers that I really like but really don’t get a whole lot of link enjoy from.

A round of applause for your article post. Really Great.

I really enjoy the article post.Really thank you! Awesome.

We like to honor a lot of other online web pages on the net, even though they aren?t linked to us, by linking to them. Underneath are some webpages worth checking out.

Very couple of websites that take place to become detailed beneath, from our point of view are undoubtedly very well worth checking out.

Although web sites we backlink to beneath are considerably not connected to ours, we really feel they are basically worth a go by, so have a look.

Very couple of internet sites that take place to become detailed below, from our point of view are undoubtedly well worth checking out.

One of our guests a short while ago encouraged the following website.

Here is an excellent Weblog You might Locate Exciting that we encourage you to visit.

Below you?ll come across the link to some websites that we assume you should visit.

One of our visitors not long ago encouraged the following website.

Usually posts some quite fascinating stuff like this. If you?re new to this site.

Make reasonable accommodations for medical problems that may require
specific types of shoes or clothing devices. The classy
style of babydoll dresses for women creates a stunning and classic look, not only adding a
naughty though innocent look but also timeless sexy appeal.
For professional parties, it is advisable to carry
off the clean shaven look but be careful as many people in the
excitement of partying, shave in a hurried manner
and accidentally end up cutting themselves. You can be invited to many parties
however finding cheap cocktail dresses are really a hard
task. For example thin girls should avoid wearing body hugging fabrics etc.
The virtual celebs you have there, in these celebrity dress up games, are all at your service.

Leave a Reply