README.txt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. We have a movie data set in JSON, Solr XML, and CSV formats.
  2. All 3 formats contain the same data. You can use any one format to index documents to Solr.
  3. The data is fetched from Freebase and the data license is present in the films-LICENSE.txt file.
  4. This data consists of the following fields:
  5. * "id" - unique identifier for the movie
  6. * "name" - Name of the movie
  7. * "directed_by" - The person(s) who directed the making of the film
  8. * "initial_release_date" - The earliest official initial film screening date in any country
  9. * "genre" - The genre(s) that the movie belongs to
  10. Steps:
  11. * Start Solr:
  12. bin/solr start
  13. * Create a "films" core:
  14. bin/solr create -c films
  15. * Set the schema on a couple of fields that Solr would otherwise guess differently (than we'd like) about:
  16. curl http://localhost:8983/solr/films/schema -X POST -H 'Content-type:application/json' --data-binary '{
  17. "add-field" : {
  18. "name":"name",
  19. "type":"text_general",
  20. "multiValued":false,
  21. "stored":true
  22. },
  23. "add-field" : {
  24. "name":"initial_release_date",
  25. "type":"pdate",
  26. "stored":true
  27. }
  28. }'
  29. * Now let's index the data, using one of these three commands:
  30. - JSON: bin/post -c films example/films/films.json
  31. - XML: bin/post -c films example/films/films.xml
  32. - CSV: bin/post \
  33. -c films \
  34. example/films/films.csv \
  35. -params "f.genre.split=true&f.directed_by.split=true&f.genre.separator=|&f.directed_by.separator=|"
  36. * Let's get searching!
  37. - Search for 'Batman':
  38. http://localhost:8983/solr/films/query?q=name:batman
  39. * If you get an error about the name field not existing, you haven't yet indexed the data
  40. * If you don't get an error, but zero results, chances are that the _name_ field schema type override wasn't set
  41. before indexing the data the first time (it ended up as a "string" type, requiring exact matching by case even).
  42. It's easiest to simply reset the environment and try again, ensuring that each step successfully executes.
  43. - Show me all 'Super hero' movies:
  44. http://localhost:8983/solr/films/query?q=*:*&fq=genre:%22Superhero%20movie%22
  45. - Let's see the distribution of genres across all the movies. See the facet section of the response for the counts:
  46. http://localhost:8983/solr/films/query?q=*:*&facet=true&facet.field=genre
  47. - Browse the indexed films in a traditional browser search interface:
  48. http://localhost:8983/solr/films/browse
  49. Now browse including the genre field as a facet:
  50. http://localhost:8983/solr/films/browse?facet.field=genre
  51. If you want to set a facet for /browse to keep around for every request add the facet.field into the "facets"
  52. param set (which the /browse handler is already configured to use):
  53. curl http://localhost:8983/solr/films/config/params -H 'Content-type:application/json' -d '{
  54. "update" : {
  55. "facets": {
  56. "facet.field":"genre"
  57. }
  58. }
  59. }'
  60. And now http://localhost:8983/solr/films/browse will display the _genre_ facet automatically.
  61. Exploring the data further -
  62. * Increase the MAX_ITERATIONS value, put in your freebase API_KEY and run the film_data_generator.py script using Python 3.
  63. Now re-index Solr with the new data.
  64. FAQ:
  65. Why override the schema of the _name_ and _initial_release_date_ fields?
  66. Without overriding those field types, the _name_ field would have been guessed as a multi-valued string field type
  67. and _initial_release_date_ would have been guessed as a multi-valued pdate type. It makes more sense with this
  68. particular data set domain to have the movie name be a single valued general full-text searchable field,
  69. and for the release date also to be single valued.
  70. How do I clear and reset my environment?
  71. See the script below.
  72. Is there an easy to copy/paste script to do all of the above?
  73. Here ya go << END_OF_SCRIPT
  74. bin/solr stop
  75. rm server/logs/*.log
  76. rm -Rf server/solr/films/
  77. bin/solr start
  78. bin/solr create -c films
  79. curl http://localhost:8983/solr/films/schema -X POST -H 'Content-type:application/json' --data-binary '{
  80. "add-field" : {
  81. "name":"name",
  82. "type":"text_general",
  83. "multiValued":false,
  84. "stored":true
  85. },
  86. "add-field" : {
  87. "name":"initial_release_date",
  88. "type":"pdate",
  89. "stored":true
  90. }
  91. }'
  92. bin/post -c films example/films/films.json
  93. curl http://localhost:8983/solr/films/config/params -H 'Content-type:application/json' -d '{
  94. "update" : {
  95. "facets": {
  96. "facet.field":"genre"
  97. }
  98. }
  99. }'
  100. # END_OF_SCRIPT
  101. Additional fun -
  102. Add highlighting:
  103. curl http://localhost:8983/solr/films/config/params -H 'Content-type:application/json' -d '{
  104. "set" : {
  105. "browse": {
  106. "hl":"on",
  107. "hl.fl":"name"
  108. }
  109. }
  110. }'
  111. try http://localhost:8983/solr/films/browse?q=batman now, and you'll see "batman" highlighted in the results