Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rigel

Avatar for eddking eddking
October 11, 2013

 Rigel

Rigel is a client library for Apache Solr

Avatar for eddking

eddking

October 11, 2013

Other Decks in Programming

Transcript

  1. What is Rigel? A star in the constellation of Orion

    Client library for Apache Solr 7 months in development built on-top of SolrJ (for now) Monday, 14 October 13
  2. What is Rigel? A star in the constellation of Orion

    Client library for Apache Solr 7 months in development built on-top of SolrJ (for now) A promise: All code compiles, has tests and uses no reflection Monday, 14 October 13
  3. How to use Define your fields: StringField ID = new

    StringField("s2_id"); StringField TYPE = new StringField("s2_type"); StringField TAG = new StringField("tag"); StringField AUTHOR = new StringField("dc_creator"); IntegerField SCENE_COUNT = new IntegerField("scene_count"); DateField DATE = new DateField("dc_issued"); Monday, 14 October 13
  4. Define your models: public static class Play extends ContentItem {

    public static class Schema extends ContentItem.Schema<Play> { public Schema() { super(ID); type = field(TYPE).build(); author = field(AUTHOR.multivalued()) .transform(asList(Author.parse())) .build(); ... filter(TYPE.equalTo("play")); } public Play create(Map<DataKey<?>, ? super Object> data) { return new Play(this, data); } } ... Monday, 14 October 13
  5. Define your models: private final Schema schema; public Play(Schema schema,

    Map<DataKey<?>, ? super Object> data) { super(schema, data); this.schema = schema; } public String getType() { return get(schema.type); } public List<Author> getAuthors() { return get(schema.author); } ... Monday, 14 October 13
  6. Initialize a Rigel Context: Play.Schema play = new Play.Schema(); RigelContext

    rigel = RigelContext.builder() .registerSchemas(play) .build(); ContentRepository<Play> plays = rigel.getContentRepository(play); List<Play> top20NewPlays = plays.all() .filter(TAG.equalTo("new")) .orderBy(DATE, ORDER.desc) .limit(20) .get(); List<Play> lotsOfScenes = plays.all() .filter(SCENE_COUNT.greaterThan(10)) .get(); Start Querying: Monday, 14 October 13
  7. More types of Query: Optional<Play> play1 = plays.id("play1").get(); Map<String, Optional<Play>>

    bla = plays.ids("play1", "play2").get(); ListMultimap<String, Play> shortPlaysByAuthor = plays.groupBy(AUTHOR) .limitResultsPerGroup(3) .filter(SCENE_COUNT.atLeast(1).andAtMost(10)) .get(); List<Play> results = plays.joinFrom(CHILD_IDS) .filter(ID.equalTo("collection1")) .joinTo(ID) .get(); Monday, 14 October 13
  8. Literate Filters: SCENE_COUNT.lessThan(5).and(AUTHOR.startsWith("Edd")) .group() .or(SCENE_COUNT.atLeast(5)) (scene_count:[* TO 5} AND dc_creator:Edd*)

    OR scene_count:[5 TO *] DATE.greaterThan(new Date()).or( TAG.equalTo("Future").or(TAG.equalTo("Year 3000")).group()); dc_issued:{2013-10-10T15:34:13.020Z TO *] OR (tag:Future OR tag:Year\ 3000) Monday, 14 October 13
  9. Benefits Over DIY: No error prone string building Automatic escaping

    special chars & spaces Type Safety Avoids undefined solr behavior thing:A OR stuff:B AND thing:C Monday, 14 October 13
  10. Benefits Over DIY: No error prone string building Automatic escaping

    special chars & spaces Type Safety Avoids undefined solr behavior thing:A OR stuff:B AND thing:C thing:A OR (stuff:B AND thing:C) Monday, 14 October 13
  11. Benefits Over DIY: No error prone string building Automatic escaping

    special chars & spaces Type Safety Avoids undefined solr behavior thing:A OR stuff:B AND thing:C thing:A OR (stuff:B AND thing:C) (thing:A OR stuff:B) AND thing:C Monday, 14 October 13
  12. Benefits Over DIY: No error prone string building Automatic escaping

    special chars & spaces Type Safety Avoids undefined solr behavior thing:A OR stuff:B AND thing:C thing:A OR (stuff:B AND thing:C) (thing:A OR stuff:B) AND thing:C stuff:B AND thing:C Monday, 14 October 13
  13. No nulls! date = field(DATE) .transform(optional(Date.class)) .build(); sceneCount = field(SCENE_COUNT)

    .transform(defaultValue(0)) .build(); ... public Optional<Date> getDate() { return get(schema.date); } public Integer getSceneCount() { return get(schema.sceneCount); } Monday, 14 October 13
  14. Whats in it for Semantico? List<Downloadable> topDownloads = downloadable.all() .orderBy(DOWNLOAD_COUNT,

    desc) .limit(10) .forceType() .get() Core features are possible with NO coupling to client site code Monday, 14 October 13
  15. public class Schema extends ContentItem.Schema<PlayCollection> { ... public Schema() {

    plays = field(CHILD_IDS.multivalued()) .transform(asList(foreignKeyField(Play.class))) .build() ... } public List<Play> getPlays() { return get(schema.plays); } } Rigel can be a kind of ORM The transformation chain is lazy There is an option to make it eager too... Monday, 14 October 13
  16. public class ExampleSearch extends Search { ... public ExampleSearch() {

    dateFacet = facet(DATE).build(); rangeFacet = rangeFacet(SCENE_COUNT) .start(0) .gap(1) .end(10) .build(); } } Out of the Box Search is possible Monday, 14 October 13
  17. Interesting Code Things String Field Type Safety in Rigel Integer

    Field Date Field Long Field Type safe, but type agnostic The Map Monday, 14 October 13
  18. Filter implements Predicate<SolrDocument> Filters are Predicates over SolrDocuments (Function of

    SolrDocument to boolean) Used to decide what Content Item to create You can evaluate the behavior of a Filter without sending the request to Solr (only on non tokenized fields) Monday, 14 October 13
  19. Rigel is pretty Complex /* * R = The raw

    type of the field, its comparable e.g. Long, Integer * F = the formatted type (what the transorm func turns our Range<R> into) * B = The solrj range facet type (Number or Date) * G = The solrj gap type, Number or String */ public abstract class RangeFacetResults<R extends Comparable<R>,F,B,G> extends FacetResults<Range<R>, F> I’ve learnt a lot mainly to dislike type erasure Monday, 14 October 13