Introducing 

Prezi AI.

Your new presentation assistant.

Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.

Loading…
Transcript

Introduction

  • Basic DSL design techniques
  • Using Solr client for Java
  • Wrapping it in a Scala DSL

Available scala libraries:

  • Slashem
  • ScalalikeSolr

Use object mapping or fully dynamic approach

Tips!

A Type-Safe Solar System

Steal it!

Original idea by Travis Brown:

http://stackoverflow.com/questions/13671734/iteration-over-a-sealed-trait-in-scala

A gentle introduction to DSL design in Scala

ADTDD ... a new fancy acronym

Algebraic Data Type Driven Development

http://github.com/timeoutdigital/talk-solarsystem

Challenges

Writing

Reading

Query

Research

Usage

Tradeoff

  • SolrJ document interfaces dichotomy
  • Let's put everything together, we need a model first.
  • Same approach as for writing, just simpler
  • There is multiple ways were the schema can be beneficial for building queries
  • How can we get the best of both world?
  • Extensible records
  • Row polymorphism

Read API

  • Using immutability and laziness can have bad impact on performance.
  • First we define the operations available on a Field
  • Set - set a field value
  • Add - add a value to multi-valued field

q=pizza&fq=cuisines:italian&bq=price^20

Write API

  • For example
  • Filtering
  • Sorting
  • Boost
  • ...

The syntax is a bit less naive,

but still far from anything doable in vanilla scala

But what is that `SealedObjects` thing???

That horrible casting is necessary because Solr return `Any`

With little changes, we can make the DSL behave in a mutable way!

No more object allocation... but more coupling and less composable.

In fact it's very close to what you can do TODAY with Shapeless

An operation mutates a SolrInputDocument

Questions ?

Thanks!

Research

Tradeoff

Usage

Writing

Query

Reading

@aloiscochard

Challenges

  • A simple schema definition

http://github.com/aloiscochard

  • No safety at "document level"
  • Some instances for types natively supported by Solr
  • "Schema-less" but we still want safety at "fields level"

That is at the moment not an easy one to solve and is a subject of research ...

  • Further hacking
  • shapeless (scala library)
  • lot of crazy things!
  • including extensible records
  • https://github.com/milessabin/shapeless
  • type provider in macro paradise (scala)
  • http://docs.scala-lang.org/overviews/macros/typeproviders.html
  • Travis Brown schema binding (scala)
  • http://meta.plasm.us/posts/2013/06/19/macro-supported-dsls-for-schema-bindings/
  • ctrex (haskell library)
  • extensible records
  • http://www.haskell.org/haskellwiki/CTRex
  • vinyl (haskell library)
  • extensible records
  • https://hackage.haskell.org/package/vinyl
  • purescript (experimental programming language)
  • row polymorphism
  • http://purescript.readthedocs.org/en/latest/types.html#row-polymorphism

Ideally, the city writer should be derived automatically

Very naive syntax

Lazy!

Usage

Basically we went structural typing instead of nominative typing.

Query

Reading

Writing

  • Read / Write / Query
  • Let's integrate the schema in our Query builder
  • Operations compose
  • Wrapping SolrJ document

Challenges

  • Need a first working implementation ASAP

Ideally, we would be nice to support collection like syntax...

Safe!

Using extensible records or row polymorphism is out of scope

NOTE: The code is actually wrong!

The functions `person` and `address` should take `Address` and `Person`.

Writing

  • We create a new document using `InputDocument`

Writing

  • But how do we know which types are supported by Solr?

Type Class!

Writing

  • Let's use the Type Class in operations

Why putting the `writer` implicit there?

Why not on the `apply` method, where it is actually needed?

Writing

  • Let's add some instances for types supported natively by Solr

Writing

"Well guys, that's just a Contrafunctor"

Daniele Turi

A Contra-WHAT????

Writing

s/Cofunctor/Contrafunctor/

Writing

  • All right, let's make our Writer a Contrafunctor then!
Learn more about creating dynamic, engaging presentations with Prezi