Doctrine Lexer Use Case

Doctrine Lexer Use Case

PHPTour Lyon 2014 - 24/06/2014

418997665c4a3368515ecf9c3d746b95?s=128

Olivier Dolbeau

June 24, 2014
Tweet

Transcript

  1. Doctrine Lexer use case

  2. None
  3. Olivier Dolbeau @odolbeau Web Architect About me

  4. RIDESHARING Cost of motoring 100€ 25€ 25€ 25€ 25€ @BlaBlaCar_FR

    ALONE
  5. A fast growing community

  6. A European phenomenon

  7. None
  8. I want to be able to search tweets using a

    human language.
  9. None
  10. None
  11. None
  12. None
  13. Where are my tweets ?

  14. None
  15. None
  16. None
  17. None
  18. None
  19. None
  20. Other solutions Logstash Home made external river

  21. distributed restful search and analytics elasticsearch

  22. None
  23. None
  24. None
  25. None
  26. None
  27. We know what we want. We know where our data

    is.
  28. Now let’s see HOW we are doing to retrieve it.

  29. How... … to translate a human language into a technical

    one.
  30. “ A retweet FROM @CameronNash23 ”

  31. None
  32. What’s a Lexer ? In computer science, lexical analysis is

    the process of converting a sequence of characters into a sequence of tokens, i. e. meaningful character strings.
  33. Tokens ! Now !

  34. None
  35. None
  36. None
  37. None
  38. “ A retweet FROM @CameronNash23 ” T_SELECTOR T_RETWEET T_FROM T_USERNAME

  39. How... … to use these tokens to generate an ElasticSearch

    query.
  40. None
  41. None
  42. None
  43. None
  44. It works!

  45. None
  46. None
  47. None
  48. And what about Doctrine ORM ? Let’s take a look

    at : Doctrine\ORM\Query\Lexer
  49. From DQL to SQL SELECT t0.id AS id1, t0.name AS

    name3, t0. username AS username4, t0.email AS email5 FROM mos_users t0 WHERE t0.username = “foobar” SELECT u FROM MyProject\Model\User u WHERE u.username = ‘foobar’
  50. 77 tokens !!

  51. Some patterns...

  52. And a switch (true) !

  53. Forget the Parser !

  54. None
  55. None
  56. None
  57. Example A trip OR A search FROM "Paris, France" OR

    TO "Paris, France" BETWEEN 12/01/2013 AND 26/05/2014 A trip OR A search FROM "Paris, France" OR TO "Paris, France" BETWEEN 12/01/2013 AND 26/05/2014
  58. Lexer to GET tokens. Parser to USE tokens.

  59. @odolbeau On recrute ! :) MERCI !

  60. @odolbeau https://joind.in/ 11246 https://github.com/odolbeau/elasticsearch-sandbox https://speakerdeck.com/odolbeau/doctrine-lexer-use-case