• Products
    • Overview
    • LucidWorks Search Platform
      • Features and Benefits
      • Technical Overview
      • Only with LucidWorks
      • LucidWorks and Solr
      • White Papers
      • LucidWorks Enterprise
      • LucidWorks Cloud
    • Certified Distributions
      • Certified Solr
      • Certified Lucene
    • Apache Releases
      • Apache Solr
      • Apache Lucene
  • Support & Services
    • Overview
    • Support
    • Training
    • Solr/Lucene Certification
    • ExpertLink Advisory
    • Consulting
    • Partners
    • Subscriptions
  • Why Lucid?
    • Why Lucid?
    • Technology
    • Technical Leadership
    • Who uses Lucene/Solr?
      • What customers are saying
    • Case Studies
    • Whitepapers
    • Demos
    • Webinars
  • Blog
  • DevZone
    • DevZone Overview
    • Forums (LWE)
    • Videos & Podcasts
      • How To's
      • Screencasts
      • Podcasts
      • Conference Videos
    • Technical Articles
      • Whitepapers
    • Reference Materials
      • Documentation
      • Solr Reference Guide
      • Solr & LucidWorks Matrix
      • Tutorials
    • Events
      • Conferences
      • Meet Ups
    • Code & Test
  • Downloads
  • About Us
    • Management
    • Careers
    • News
      • Media Coverage
      • Press Releases
    • Contact Us
Sign Up or Log In
Home . Blog

November 20, 2009

Fun with Solr Functions

Posted by Grant Ingersoll

For a long time now, Solr has had a good chunk of functions available for use to boost relevance based on the content of a field, but I’ve always been on the user side of them and never on the writing side.  At least, that is, until recently.  This week I have been putting the finishing touches on an article on using Lucene and Solr for spatial search.  As part of the article, I had a chance to write up a bunch of new functions for Solr, including several for calculating distance between two points.  These functions are:

  1. hsin and ghhsin (geohash based haversine) – Calculate the Haversine distance (Great Circle) between two points on a sphere
  2. Lp norm – i.e. the 1-norm (Manhattan distance), 2-norm (Euclidean), etc.
  3. radian/degree converter
  4. Geohash converter – convert latitude/longitude pair to a geohash value.

On top of that, Yonik added in support for pretty much all of java.util.Math, including cosine, sine, tangent, etc. so now Solr really has some very significant mathematical capabilities, all of which can powered by the values selected by doing a search.  Not too mention, they can be used for filtering too, using the FunctionRangeQParser (frange for short).

As an example, here’s a few Solr requests I generated for my article:

http://localhost:8983/solr/select/?q={!func}recip(hsin(0.78, -1.6, lat_rad, lon_rad, 3963.205), 1, 1, 0)

http://localhost:8983/solr/select/?q=*:*&fq={!frange l=0 u=10}dist(2, 32, -79, lat, lon)

In the first example, I’m scoring all my docs based on the great circle distance from a specific point on the globe, while in the second, I’m filtering out docs based on distance.

I’ve also seen functions used in all sorts of different ways.  One customer was even using them to simulate alternate scoring models by using the ExternalFileValueSource.  Additionally, one of the nice things they can also do is give you much higher precision document/field boosts.

Up until now, I had never realized how dead-simple they are to write.  Basically, take in a ValueSource, convert it to a DocValues instance which gives you the value of the field for each document and then do your calculation.  Finally, register it in the solrconfig.xml.  For more on this, see the SolrPlugins wiki. page.

Finally, keep an eye on Solr 1.5, as I have an inkling to add what I’m tentatively calling aggregating functions, which I think can be used to power more business intelligence applications.  These aggregating functions would be a significant extension of Solr’s StatsComponent and allow for much more expressive calculations over result sets.

  • Share this:
  • Email
  • Facebook
  • Digg
  • Share
  • Print
  • Reddit
  • StumbleUpon

Category: apache, Solr

One Response to “Fun with Solr Functions”

  1. [...] functions, functions!  We’ve already added a bunch of functions (see my earlier post) and I see more on the horizon.  Additionally, I see great value in adding, for lack of a better [...]

    December 12, 2009 15:45 — Lucid Imagination » Apache Solr 1.5 on the move with more “functionality”

Leave a Reply

Go to Blog Front Page

  • Recent Posts

    • Lucene Revolution 2012 – Call for Participation now open!
    • SolrCloud is Coming (and looking to mix in even more ‘NoSQL’)
    • Our Solr Reference Guide updated for v3.5
    • Enhancing Discovery with Solr and Mahout – session slides now available!
    • Solr and LucidWorks feature matrix available
    • LucidWorks Enterprise latest version 2.0.1 released!
    • Why Not AND, OR, And NOT?
    • Options to tune document’s relevance in Solr
    • Dallas JavaMUG December 14th 2011
    • Apache Mahout user meeting – session slides and videos are now available!
  • Archives

    • January 2012
    • December 2011
    • November 2011
    • October 2011
    • September 2011
    • August 2011
  • Tags

    acts_as_solr apache Apache Mahout best practices chump code4lib dismax drupal enterprise search Erik Hatcher field collapsing function query Grant Ingersoll hoss image isfdb local params Lucene lucene revolution LucidGaze lucid imagination Mahout Marc Krellenstein Mark Miller nested queries nutch Open Source Open Source Search qparser query parser queryparser Rails release result grouping Richmond Ruby schema design sint Solr solr 3.1 solr 4.0 solr cloud sortable Tika VA
  • Contact Us
  • About Lucid Imagination
  • Help & Support
  • Training
  • Privacy Policy
  • Legal Terms of Use
  • Copyrights and Disclaimers
  • Log in

Apache Solr, Solr, Apache Lucene, Lucene and their logos are trademarks of the Apache Software Foundation.

© 2011 Lucid Imagination. All Right reserved.

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.