#Liftweb and #SOLR, slashem with write-support

I like foursquare's libs. If you're using liftweb a lot (and there is no reason you shouldn't), then you've probably discovered the trove of treasures foursquare is managing in their repositories on GitHub.

If you haven't used Rogue, then you're missing out. It offers the neatest DSL for querying/modifying/deleting MongoDB with accordance to your Lift-Record Models.

The absolute awesome pendant for your Apache SOLR Backend is Slashem. It provides nearly the same Query DSL to SOLR as Rogue does, with the exception that it does not handle writes by default. There is no workable .save() or something that persists your record to SOLR. You have to do it yourself, and i agree that this can be quite cumbersome unless you are using my Trait. :)

Only extend your SolrSchema class with this Trait, your Meta will get it through the class!

What it does

It uses the default SOLR-client created by each SolrMeta object and creates POST-requests out of your model's .asJValue. I added the .asJValueForSolr with a default-value of .asJValue (can be overridden in the model).

It offers 2 ways of saving to SOLR. You can either use myRecordObj.saveToSolr() to save a single record or MyModel.saveToSolr(listOfMyRecordObjs) in order to save a bunch of objects in one request to SOLR.

Last but not least you should run a MyModel.commitToSolr() to trigger a commit.

Caveats

  • MyModel.saveToSolr() does not work, since it's not an instanced record.
  • myRecordObj.saveToSolr(listOfMyRecordObjs) will not append myRecordObj to the listOfMyRecordObjs, you have to do it.

Merry Christmas everyone.

Flattr me!

Tell your friends!