Searching ORM: First Why, Then How

722 views

Published on

Hibernate changed how many applications are written. With its inclusion in ColdFusion 9, ORM has changed how many ColdFusion applications are written. This session will cover first why searching via ORM may benefit applications. Secondly the session will cover the many options for how to configure the search options and perform searches.

Presented at cf.Objective() 2012.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
722
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Searching ORM: First Why, Then How

    1. 1. Searching ORMSam Farmer
    2. 2. Me
    3. 3. MeSenior Applications Architect at FirstComp
    4. 4. MeSenior Applications Architect at FirstCompColdFusion, JavaScript, yada, yada...
    5. 5. MeSenior Applications Architect at FirstCompColdFusion, JavaScript, yada, yada...Hobbies:
    6. 6. MeSenior Applications Architect at FirstCompColdFusion, JavaScript, yada, yada...Hobbies: Soccer. Play and Arsenal fan.
    7. 7. MeSenior Applications Architect at FirstCompColdFusion, JavaScript, yada, yada...Hobbies: Soccer. Play and Arsenal fan. Code. oldjam.com
    8. 8. MeSenior Applications Architect at FirstCompColdFusion, JavaScript, yada, yada...Hobbies: Soccer. Play and Arsenal fan. Code. oldjam.comLive in Washington, DC with my wife and twodaughters
    9. 9. Agenda
    10. 10. AgendaWhy search
    11. 11. AgendaWhy searchPre-CF10 Enterprise
    12. 12. AgendaWhy searchPre-CF10 EnterpriseWith CF10 Enterprise
    13. 13. Other SessionsA/B Testing with Squabble (Mark Mandel)Creating ColdFusion Builder Extensions (Simon Free)Authentication made Easy using Twitter, Facebook,Google, and more (Billy Cravens)Node.js and You - Server Side Javascript (SimonBateman)
    14. 14. Who likes Objects?
    15. 15. Who likes Objects?
    16. 16. Who likes cf.Objective()?
    17. 17. Who likes ORM?
    18. 18. Using or planning to useCF10?
    19. 19. Retrieving ObjectsBased on criteria
    20. 20. entityLoad( "user", 1 );ormExecuteQuery( "FROM user WHERE state = DC or state=NE ");
    21. 21. Why SearchingGet what you are looking for
    22. 22. 1998
    23. 23. flickr.com/photos/crystaleagle/
    24. 24. flickr.com/photos/crystaleagle/
    25. 25. That star looking shape flickr.com/photos/crystaleagle/
    26. 26. That star looking shape flickr.com/photos/crystaleagle/
    27. 27. That star looking shape flickr.com/photos/crystaleagle/
    28. 28. That star looking shape flickr.com/photos/crystaleagle/
    29. 29. What we used to have
    30. 30. Now we have
    31. 31. SearchLets look at the options
    32. 32. Artist and Art one-to-many artist art
    33. 33. Looking for Michael Mychael Face of by Night Mikael
    34. 34. LikeEverything has its place
    35. 35. LIKE
    36. 36. LIKEDont snicker
    37. 37. LIKEDont snickerPremature optimization
    38. 38. With HQL
    39. 39. With HQLSimilar to SQL
    40. 40. <cfquery dbtype="hql" name="getArt">FROM ARTWHERE name like <cfqueryparam value="Mi%"></cfquery>
    41. 41. With Hibernate Criteria API
    42. 42. With Hibernate Criteria API More "object-ey"
    43. 43. order = createObject( java,"org.hibernate.criterion.Order" );Restrictions = createObject( java,"org.hibernate.criterion.Restrictions" );
    44. 44. order = createObject( java,"org.hibernate.criterion.Order" );Restrictions = createObject( java,"org.hibernate.criterion.Restrictions" );artSearch = ormGetSession().createCriteria( "art" );artSearch.add( Restrictions.like( "name", "Mi%" ) );artSearch.addOrder( order.asc( "name" ) );getArt = artSearch.list();writeDump( getArt );
    45. 45. order = createObject( java,"org.hibernate.criterion.Order" );Restrictions = createObject( java,"org.hibernate.criterion.Restrictions" );artSearch = ormGetSession().createCriteria( "art" );artSearch.add( Restrictions.like( "name", "Mi%" ) );artSearch.addOrder( order.asc( "name" ) );getArt = artSearch.list();writeDump( getArt );
    46. 46. (If you likelook atColdBox)coldbox.org
    47. 47. Search EnginesLets look at the options
    48. 48. Database (Full Text Search)Options
    49. 49. Database (Full Text Search)Options I couldnt make work
    50. 50. Database (Full Text Search)Options I couldnt make work Smarter people may have
    51. 51. Database (Full Text Search)Options I couldnt make work Smarter people may have Or, double query to
    52. 52. Database (Full Text Search)Options I couldnt make work Smarter people may have Or, double query to get Ids
    53. 53. Database (Full Text Search)Options I couldnt make work Smarter people may have Or, double query to get Ids get entities
    54. 54. Apache LuceneA "flagship sub-project"
    55. 55. "Our core algorithms alongwith the Solr search serverpower applications the worldover, ranging from mobiledevices to sites like Twitter,Apple and Wikipedia."
    56. 56. "Our core algorithms alongwith the Solr search serverpower applications the worldover, ranging from mobiledevices to sites like Twitter,Apple and Wikipedia." And soon your apps! :)
    57. 57. Lucene & Solr
    58. 58. Lucene & SolrBoth from Apache
    59. 59. Lucene & SolrBoth from ApacheSolr is a servlet
    60. 60. Lucene & SolrBoth from ApacheSolr is a servletLucene is an index
    61. 61. Lucene & SolrBoth from ApacheSolr is a servletLucene is an index
    62. 62. Lucene & SolrBoth from ApacheSolr is a servletLucene is an indexSolr needs Lucene but Lucene does not need Solr
    63. 63. What can Lucene do?
    64. 64. What can Lucene do?Fuzzy
    65. 65. What can Lucene do?FuzzyWords near each other
    66. 66. What can Lucene do?FuzzyWords near each otherBoost
    67. 67. What can Lucene do?FuzzyWords near each otherBoostRange
    68. 68. SolrEntity
    69. 69. SolrEntity Nathan Mische proof of concept
    70. 70. SolrEntity Nathan Mische proof of concept‣ http://cfml.us/z3
    71. 71. How it works
    72. 72. How it worksBase cfc
    73. 73. How it worksBase cfcMetadata defines configuration
    74. 74. How it worksBase cfcMetadata defines configurationEvent Handlers
    75. 75. How it worksBase cfcMetadata defines configurationEvent Handlers postUpdate(), postInsert(), postDelete()
    76. 76. How it worksBase cfcMetadata defines configurationEvent Handlers postUpdate(), postInsert(), postDelete() update Solr
    77. 77. Entry.cfccomponent persistent="true" table="entry"extends="SolrEntity" solrcollection="blog" {property name="entryid" fieldtype="id"generator="native" solrfield="key";property name="author" fieldtype="many-to-one"fkcolumn="authorid" cfc="Author";property name="title" solrfield="title";property name="content" solrfield="body";}
    78. 78. ColdFusion 10 ORM SearchPutting the pieces together
    79. 79. searchArt = ormSearch("name:Mi*", "art" );
    80. 80. searchArt = ormSearch("name:Mi*", "art" );writeDump( var=searchArt, top=3, showudfs=false );
    81. 81. searchArt = ormSearch("name:Mi*", "art" );writeDump( var=searchArt, top=3, showudfs=false );
    82. 82. searchArt = ormSearch("name:Michael~", "art" );
    83. 83. searchArt = ormSearch("name:Michael~", "art" );
    84. 84. Lucene Query Syntax
    85. 85. Lucene Query SyntaxThis is the "magic"
    86. 86. Lucene Query SyntaxThis is the "magic"http://cfml.us/Ax
    87. 87. Wildcard Searches
    88. 88. Wildcard Searches? = one character
    89. 89. Wildcard Searches? = one character Arsen?l (finds Arsenal)
    90. 90. Wildcard Searches? = one character Arsen?l (finds Arsenal)* = many characters
    91. 91. Wildcard Searches? = one character Arsen?l (finds Arsenal)* = many characters Cant be first
    92. 92. Wildcard Searches? = one character Arsen?l (finds Arsenal)* = many characters Cant be first Arse*
    93. 93. Wildcard Searches? = one character Arsen?l (finds Arsenal)* = many characters Cant be first Arse* Ar*al
    94. 94. Fuzzy Searches ~
    95. 95. Fuzzy Searches ~~ will find similar spellings
    96. 96. Fuzzy Searches ~~ will find similar spellings Arsenal~ (finds Arsenal)
    97. 97. Fuzzy Searches ~~ will find similar spellings Arsenal~ (finds Arsenal)~0-1 indicates how similar
    98. 98. Fuzzy Searches ~~ will find similar spellings Arsenal~ (finds Arsenal)~0-1 indicates how similar 0=least similar, 0.5=default, 1=most similar
    99. 99. Fuzzy Searches ~~ will find similar spellings Arsenal~ (finds Arsenal)~0-1 indicates how similar 0=least similar, 0.5=default, 1=most similar Arsenal~0.1
    100. 100. Fuzzy Searches ~~ will find similar spellings Arsenal~ (finds Arsenal)~0-1 indicates how similar 0=least similar, 0.5=default, 1=most similar Arsenal~0.1 Arsenal~1
    101. 101. Boost ^
    102. 102. Boost ^^ boost makes one term more important/relevant
    103. 103. Boost ^^ boost makes one term more important/relevant Arsenal^6 Chelsea (makes Arsenal more relevant)
    104. 104. Boost ^^ boost makes one term more important/relevant Arsenal^6 Chelsea (makes Arsenal more relevant)^0.1-99 indicates how much more relevant
    105. 105. Boost ^^ boost makes one term more important/relevant Arsenal^6 Chelsea (makes Arsenal more relevant)^0.1-99 indicates how much more relevant 1 = default
    106. 106. Boost ^^ boost makes one term more important/relevant Arsenal^6 Chelsea (makes Arsenal more relevant)^0.1-99 indicates how much more relevant 1 = default Normally whole numbers
    107. 107. Proximity Searches ~9
    108. 108. Proximity Searches ~9Find two words close to each other
    109. 109. Proximity Searches ~9Find two words close to each other"one two"~NUM where NUM is how close
    110. 110. Proximity Searches ~9Find two words close to each other"one two"~NUM where NUM is how close "Arsenal Champions"~6 (finds Arsenal)
    111. 111. Proximity Searches ~9Find two words close to each other"one two"~NUM where NUM is how close "Arsenal Champions"~6 (finds Arsenal)
    112. 112. How it works
    113. 113. ColdFusion / JVM Database
    114. 114. ColdFusion / JVMHey Lucene can you look this up? Database
    115. 115. ColdFusion / JVMHey Lucene can you look this up? Sure, here are matching Ids Database
    116. 116. ColdFusion / JVMHey Lucene can you look this up? Sure, here are matching IdsThanks! Hibernate entities please Database
    117. 117. ColdFusion / JVMHey Lucene can you look this up? Sure, here are matching IdsThanks! Hibernate entities please DatabaseSure, hey database can I get data?
    118. 118. ColdFusion / JVMHey Lucene can you look this up? Sure, here are matching IdsThanks! Hibernate entities please DatabaseSure, hey database can I get data? Most def. SELECT blah FROM table WHERE Id = 999
    119. 119. ColdFusion / JVMHey Lucene can you look this up? Sure, here are matching IdsThanks! Hibernate entities please DatabaseSure, hey database can I get data? Most def. Here you go SELECT blah FROM table WHERE Id = 999
    120. 120. Lets see that...
    121. 121. Is it slow?
    122. 122. Is it slow? Two fast operations
    123. 123. Is it slow? Two fast operations Lucene search
    124. 124. Is it slow? Two fast operations Lucene search Look up by Ids
    125. 125. Is it slow? Two fast operations Lucene search Look up by Ids Load Testing
    126. 126. Skip the database
    127. 127. Skip the databaseormSearchOffline()
    128. 128. Skip the databaseormSearchOffline()Returns only fields specified by indexStore
    129. 129. searchArt = ormSearchOffline("name:Michael~", "ART",["id","name"] );
    130. 130. searchArt = ormSearchOffline("name:Michael~", "ART",["id","name"] );writeDump( var=searchArt, top=3, showudfs=false );
    131. 131. searchArt = ormSearchOffline("name:Michael~", "ART",["id","name"] );writeDump( var=searchArt, top=3, showudfs=false );
    132. 132. Setup
    133. 133. Application.cfccomponent {this.name = "ormSearchCriteria";this.datasource = "cfartgallery";this.ormEnabled = true;this.ormSettings = { searchEnabled = true | false, search = { [autoIndex = true], [indexDir = filepath], [language = "english"] } };}
    134. 134. MP LESApplication.cfc IN SA USEDcomponent {this.name = "ormSearchCriteria";this.datasource = "cfartgallery";this.ormEnabled = true;this.ormSettings = { searchEnabled = true, search = { autoIndex = true }, logsql = true };this.invokeImplicitAccessor = true;}
    135. 135. Entity - Attributescomponent persistent = true indexable = true | false indexLanguage = "english" autoIndex = true | false {
    136. 136. Entity - Propertiescomponent persistent = true indexable = true {property name="name" indexable = true | false indexTokenized = true | false indexFieldName = "" indexBoost = 0-1 indexStore = true | false | compressed indexLanguage = "english"
    137. 137. MP LES Art.cfc IN SA USEDcomponent persistent="true" indexable="true" {property name="id" column="ARTID" fieldtype="id";property name="name" column="ARTNAME"ormtype="string" indexable="true" indexStore="true";property name="description" ormtype="text" indexable="true";property name="price" ormtype="double" indexable="true";property name="largeimage" ormtype="string";property name="mediaid" ormtype="int";property name="issold" ormtype="boolean";property name="artist" fieldtype="many-to-one" cfc="artist";
    138. 138. Indexes
    139. 139. Creation and Update
    140. 140. Creation and UpdateAutomatic on all entity operations
    141. 141. Creation and UpdateAutomatic on all entity operationsBuild
    142. 142. Creation and UpdateAutomatic on all entity operationsBuild Lucene is fast
    143. 143. Maintenance
    144. 144. MaintenanceChanges to properties indexed
    145. 145. MaintenanceChanges to properties indexedFunctions provided act on:
    146. 146. MaintenanceChanges to properties indexedFunctions provided act on: whole index
    147. 147. MaintenanceChanges to properties indexedFunctions provided act on: whole index entities
    148. 148. MaintenanceChanges to properties indexedFunctions provided act on: whole index entities entity
    149. 149. MaintenanceChanges to properties indexedFunctions provided act on: whole index entities entityormIndex() and ormIndexPurge()
    150. 150. Pitfalls?What are the downsides?
    151. 151. Pitfalls Enterprise only Single server (at the moment)
    152. 152. What can we do now?Add intelligent search to our apps
    153. 153. Guess vs Guide Make your own search algorithm Use Boost, Fuzzy and others Refine
    154. 154. Thank you! Q&A @sam_farmer sam@samfarmer.com www.samfarmer.com

    ×