isomorfeus-ferret 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +612 -0
  3. data/README.md +44 -0
  4. data/ext/isomorfeus_ferret_ext/benchmark.c +223 -0
  5. data/ext/isomorfeus_ferret_ext/benchmark.h +45 -0
  6. data/ext/isomorfeus_ferret_ext/benchmarks_all.h +25 -0
  7. data/ext/isomorfeus_ferret_ext/bm_bitvector.c +123 -0
  8. data/ext/isomorfeus_ferret_ext/bm_hash.c +118 -0
  9. data/ext/isomorfeus_ferret_ext/bm_micro_string.c +40 -0
  10. data/ext/isomorfeus_ferret_ext/bm_store.c +93 -0
  11. data/ext/isomorfeus_ferret_ext/email.rl +21 -0
  12. data/ext/isomorfeus_ferret_ext/extconf.rb +5 -0
  13. data/ext/isomorfeus_ferret_ext/fio_tmpfile.h +53 -0
  14. data/ext/isomorfeus_ferret_ext/frb_analysis.c +2577 -0
  15. data/ext/isomorfeus_ferret_ext/frb_index.c +3457 -0
  16. data/ext/isomorfeus_ferret_ext/frb_lang.c +9 -0
  17. data/ext/isomorfeus_ferret_ext/frb_lang.h +17 -0
  18. data/ext/isomorfeus_ferret_ext/frb_qparser.c +629 -0
  19. data/ext/isomorfeus_ferret_ext/frb_search.c +4460 -0
  20. data/ext/isomorfeus_ferret_ext/frb_store.c +515 -0
  21. data/ext/isomorfeus_ferret_ext/frb_threading.h +30 -0
  22. data/ext/isomorfeus_ferret_ext/frb_utils.c +1127 -0
  23. data/ext/isomorfeus_ferret_ext/frt_analysis.c +1644 -0
  24. data/ext/isomorfeus_ferret_ext/frt_analysis.h +247 -0
  25. data/ext/isomorfeus_ferret_ext/frt_array.c +124 -0
  26. data/ext/isomorfeus_ferret_ext/frt_array.h +54 -0
  27. data/ext/isomorfeus_ferret_ext/frt_bitvector.c +95 -0
  28. data/ext/isomorfeus_ferret_ext/frt_bitvector.h +586 -0
  29. data/ext/isomorfeus_ferret_ext/frt_compound_io.c +374 -0
  30. data/ext/isomorfeus_ferret_ext/frt_config.h +44 -0
  31. data/ext/isomorfeus_ferret_ext/frt_document.c +134 -0
  32. data/ext/isomorfeus_ferret_ext/frt_document.h +52 -0
  33. data/ext/isomorfeus_ferret_ext/frt_except.c +95 -0
  34. data/ext/isomorfeus_ferret_ext/frt_except.h +188 -0
  35. data/ext/isomorfeus_ferret_ext/frt_field_index.c +233 -0
  36. data/ext/isomorfeus_ferret_ext/frt_field_index.h +42 -0
  37. data/ext/isomorfeus_ferret_ext/frt_filter.c +157 -0
  38. data/ext/isomorfeus_ferret_ext/frt_fs_store.c +502 -0
  39. data/ext/isomorfeus_ferret_ext/frt_global.c +427 -0
  40. data/ext/isomorfeus_ferret_ext/frt_global.h +290 -0
  41. data/ext/isomorfeus_ferret_ext/frt_hash.c +518 -0
  42. data/ext/isomorfeus_ferret_ext/frt_hash.h +466 -0
  43. data/ext/isomorfeus_ferret_ext/frt_hashset.c +191 -0
  44. data/ext/isomorfeus_ferret_ext/frt_hashset.h +206 -0
  45. data/ext/isomorfeus_ferret_ext/frt_helper.c +62 -0
  46. data/ext/isomorfeus_ferret_ext/frt_helper.h +13 -0
  47. data/ext/isomorfeus_ferret_ext/frt_ind.c +353 -0
  48. data/ext/isomorfeus_ferret_ext/frt_ind.h +54 -0
  49. data/ext/isomorfeus_ferret_ext/frt_index.c +6377 -0
  50. data/ext/isomorfeus_ferret_ext/frt_index.h +880 -0
  51. data/ext/isomorfeus_ferret_ext/frt_lang.c +104 -0
  52. data/ext/isomorfeus_ferret_ext/frt_lang.h +44 -0
  53. data/ext/isomorfeus_ferret_ext/frt_mempool.c +87 -0
  54. data/ext/isomorfeus_ferret_ext/frt_mempool.h +33 -0
  55. data/ext/isomorfeus_ferret_ext/frt_multimapper.c +349 -0
  56. data/ext/isomorfeus_ferret_ext/frt_multimapper.h +52 -0
  57. data/ext/isomorfeus_ferret_ext/frt_posh.c +1006 -0
  58. data/ext/isomorfeus_ferret_ext/frt_posh.h +973 -0
  59. data/ext/isomorfeus_ferret_ext/frt_priorityqueue.c +147 -0
  60. data/ext/isomorfeus_ferret_ext/frt_priorityqueue.h +147 -0
  61. data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +1612 -0
  62. data/ext/isomorfeus_ferret_ext/frt_q_const_score.c +157 -0
  63. data/ext/isomorfeus_ferret_ext/frt_q_filtered_query.c +209 -0
  64. data/ext/isomorfeus_ferret_ext/frt_q_fuzzy.c +281 -0
  65. data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +147 -0
  66. data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +672 -0
  67. data/ext/isomorfeus_ferret_ext/frt_q_parser.c +3084 -0
  68. data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +1182 -0
  69. data/ext/isomorfeus_ferret_ext/frt_q_prefix.c +98 -0
  70. data/ext/isomorfeus_ferret_ext/frt_q_range.c +665 -0
  71. data/ext/isomorfeus_ferret_ext/frt_q_span.c +2386 -0
  72. data/ext/isomorfeus_ferret_ext/frt_q_term.c +311 -0
  73. data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +166 -0
  74. data/ext/isomorfeus_ferret_ext/frt_ram_store.c +460 -0
  75. data/ext/isomorfeus_ferret_ext/frt_scanner.c +899 -0
  76. data/ext/isomorfeus_ferret_ext/frt_scanner.h +28 -0
  77. data/ext/isomorfeus_ferret_ext/frt_scanner_mb.c +6705 -0
  78. data/ext/isomorfeus_ferret_ext/frt_scanner_utf8.c +4419 -0
  79. data/ext/isomorfeus_ferret_ext/frt_search.c +1824 -0
  80. data/ext/isomorfeus_ferret_ext/frt_search.h +924 -0
  81. data/ext/isomorfeus_ferret_ext/frt_similarity.c +150 -0
  82. data/ext/isomorfeus_ferret_ext/frt_similarity.h +79 -0
  83. data/ext/isomorfeus_ferret_ext/frt_sort.c +796 -0
  84. data/ext/isomorfeus_ferret_ext/frt_stopwords.c +395 -0
  85. data/ext/isomorfeus_ferret_ext/frt_store.c +680 -0
  86. data/ext/isomorfeus_ferret_ext/frt_store.h +789 -0
  87. data/ext/isomorfeus_ferret_ext/frt_term_vectors.c +72 -0
  88. data/ext/isomorfeus_ferret_ext/frt_threading.h +23 -0
  89. data/ext/isomorfeus_ferret_ext/frt_win32.h +54 -0
  90. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +409 -0
  91. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +95 -0
  92. data/ext/isomorfeus_ferret_ext/libstemmer.c +93 -0
  93. data/ext/isomorfeus_ferret_ext/libstemmer.h +73 -0
  94. data/ext/isomorfeus_ferret_ext/q_parser.y +1366 -0
  95. data/ext/isomorfeus_ferret_ext/scanner.h +28 -0
  96. data/ext/isomorfeus_ferret_ext/scanner.in +43 -0
  97. data/ext/isomorfeus_ferret_ext/scanner.rl +84 -0
  98. data/ext/isomorfeus_ferret_ext/scanner_mb.rl +200 -0
  99. data/ext/isomorfeus_ferret_ext/scanner_utf8.rl +85 -0
  100. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.c +324 -0
  101. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.h +7 -0
  102. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.c +610 -0
  103. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.h +6 -0
  104. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.c +1104 -0
  105. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.h +6 -0
  106. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.c +749 -0
  107. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.h +7 -0
  108. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.c +1233 -0
  109. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.h +6 -0
  110. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.c +490 -0
  111. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.h +6 -0
  112. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.c +1217 -0
  113. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.h +7 -0
  114. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.c +1052 -0
  115. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.h +6 -0
  116. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.c +283 -0
  117. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.h +6 -0
  118. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.c +735 -0
  119. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.h +6 -0
  120. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.c +1003 -0
  121. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.h +7 -0
  122. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.c +1079 -0
  123. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.h +6 -0
  124. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.c +293 -0
  125. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.h +6 -0
  126. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.c +984 -0
  127. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.h +6 -0
  128. data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.c +686 -0
  129. data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.h +6 -0
  130. data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.c +325 -0
  131. data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.h +6 -0
  132. data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.c +620 -0
  133. data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.h +6 -0
  134. data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.c +1111 -0
  135. data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.h +6 -0
  136. data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.c +754 -0
  137. data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.h +6 -0
  138. data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.c +1242 -0
  139. data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.h +6 -0
  140. data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.c +495 -0
  141. data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.h +6 -0
  142. data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.c +1220 -0
  143. data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.h +6 -0
  144. data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.c +1059 -0
  145. data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.h +6 -0
  146. data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.c +285 -0
  147. data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.h +6 -0
  148. data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.c +741 -0
  149. data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.h +6 -0
  150. data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.c +1009 -0
  151. data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.h +6 -0
  152. data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.c +990 -0
  153. data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.h +6 -0
  154. data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.c +680 -0
  155. data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.h +6 -0
  156. data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.c +1083 -0
  157. data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.h +6 -0
  158. data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.c +294 -0
  159. data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.h +6 -0
  160. data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.c +2191 -0
  161. data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.h +6 -0
  162. data/ext/isomorfeus_ferret_ext/stem_api.c +66 -0
  163. data/ext/isomorfeus_ferret_ext/stem_api.h +26 -0
  164. data/ext/isomorfeus_ferret_ext/stem_header.h +57 -0
  165. data/ext/isomorfeus_ferret_ext/stem_modules.h +190 -0
  166. data/ext/isomorfeus_ferret_ext/stem_modules.txt +50 -0
  167. data/ext/isomorfeus_ferret_ext/stem_utilities.c +478 -0
  168. data/ext/isomorfeus_ferret_ext/test.c +850 -0
  169. data/ext/isomorfeus_ferret_ext/test.h +416 -0
  170. data/ext/isomorfeus_ferret_ext/test_1710.c +63 -0
  171. data/ext/isomorfeus_ferret_ext/test_analysis.c +1221 -0
  172. data/ext/isomorfeus_ferret_ext/test_array.c +272 -0
  173. data/ext/isomorfeus_ferret_ext/test_bitvector.c +600 -0
  174. data/ext/isomorfeus_ferret_ext/test_compound_io.c +170 -0
  175. data/ext/isomorfeus_ferret_ext/test_document.c +156 -0
  176. data/ext/isomorfeus_ferret_ext/test_except.c +244 -0
  177. data/ext/isomorfeus_ferret_ext/test_fields.c +522 -0
  178. data/ext/isomorfeus_ferret_ext/test_file_deleter.c +185 -0
  179. data/ext/isomorfeus_ferret_ext/test_filter.c +331 -0
  180. data/ext/isomorfeus_ferret_ext/test_fs_store.c +25 -0
  181. data/ext/isomorfeus_ferret_ext/test_global.c +299 -0
  182. data/ext/isomorfeus_ferret_ext/test_hash.c +485 -0
  183. data/ext/isomorfeus_ferret_ext/test_hashset.c +288 -0
  184. data/ext/isomorfeus_ferret_ext/test_helper.c +47 -0
  185. data/ext/isomorfeus_ferret_ext/test_highlighter.c +548 -0
  186. data/ext/isomorfeus_ferret_ext/test_index.c +2323 -0
  187. data/ext/isomorfeus_ferret_ext/test_lang.c +74 -0
  188. data/ext/isomorfeus_ferret_ext/test_mempool.c +102 -0
  189. data/ext/isomorfeus_ferret_ext/test_multimapper.c +64 -0
  190. data/ext/isomorfeus_ferret_ext/test_priorityqueue.c +213 -0
  191. data/ext/isomorfeus_ferret_ext/test_q_const_score.c +84 -0
  192. data/ext/isomorfeus_ferret_ext/test_q_filtered.c +61 -0
  193. data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +241 -0
  194. data/ext/isomorfeus_ferret_ext/test_q_parser.c +464 -0
  195. data/ext/isomorfeus_ferret_ext/test_q_span.c +575 -0
  196. data/ext/isomorfeus_ferret_ext/test_ram_store.c +77 -0
  197. data/ext/isomorfeus_ferret_ext/test_search.c +1874 -0
  198. data/ext/isomorfeus_ferret_ext/test_segments.c +167 -0
  199. data/ext/isomorfeus_ferret_ext/test_similarity.c +25 -0
  200. data/ext/isomorfeus_ferret_ext/test_sort.c +333 -0
  201. data/ext/isomorfeus_ferret_ext/test_store.c +591 -0
  202. data/ext/isomorfeus_ferret_ext/test_store.h +3 -0
  203. data/ext/isomorfeus_ferret_ext/test_term.c +351 -0
  204. data/ext/isomorfeus_ferret_ext/test_term_vectors.c +373 -0
  205. data/ext/isomorfeus_ferret_ext/test_test.c +83 -0
  206. data/ext/isomorfeus_ferret_ext/test_threading.c +188 -0
  207. data/ext/isomorfeus_ferret_ext/testhelper.c +561 -0
  208. data/ext/isomorfeus_ferret_ext/testhelper.h +25 -0
  209. data/ext/isomorfeus_ferret_ext/tests_all.h +87 -0
  210. data/ext/isomorfeus_ferret_ext/uchar-ucs4.rl +1854 -0
  211. data/ext/isomorfeus_ferret_ext/uchar-utf8.rl +1999 -0
  212. data/ext/isomorfeus_ferret_ext/url.rl +27 -0
  213. data/ext/isomorfeus_ferret_ext/word_list.h +15156 -0
  214. data/lib/isomorfeus/ferret/document.rb +132 -0
  215. data/lib/isomorfeus/ferret/field_symbol.rb +85 -0
  216. data/lib/isomorfeus/ferret/index/field_infos.rb +48 -0
  217. data/lib/isomorfeus/ferret/index/index.rb +970 -0
  218. data/lib/isomorfeus/ferret/monitor.rb +323 -0
  219. data/lib/isomorfeus/ferret/stdlib_patches.rb +151 -0
  220. data/lib/isomorfeus/ferret/version.rb +5 -0
  221. data/lib/isomorfeus-ferret.rb +8 -0
  222. metadata +307 -0
@@ -0,0 +1,132 @@
1
+ module Isomorfeus
2
+ module Ferret
3
+ # Instead of using documents to add data to an index you can use Hashes and
4
+ # Arrays. The only real benefits of using a Document over a Hash are pretty
5
+ # printing and the boost attribute. You can add the boost attribute to
6
+ # Hashes and arrays using the BoostMixin. For example;
7
+ #
8
+ # class Hash
9
+ # include BoostMixin
10
+ # end
11
+ #
12
+ # class Array
13
+ # include BoostMixin
14
+ # end
15
+ #
16
+ # class String
17
+ # include BoostMixin
18
+ # end
19
+ module BoostMixin
20
+ attr_accessor :boost
21
+ end
22
+
23
+ # Documents are the unit of indexing and search.
24
+ #
25
+ # A Document is a set of fields. Each field has a name and an array of
26
+ # textual values. If you are coming from a Lucene background you should note
27
+ # that Fields don't have any properties except for the boost property. You
28
+ # should use the Ferret::Index::FieldInfos class to set field properties
29
+ # across the whole index instead.
30
+ #
31
+ # === Boost
32
+ #
33
+ # The boost attribute makes a Document more important in the index. That is,
34
+ # you can increase the score of a match for queries that match a particular
35
+ # document, making it more likely to appear at the top of search results.
36
+ # You may, for example, want to boost products that have a higher user
37
+ # rating so that they are more likely to appear in search results.
38
+ #
39
+ # Note: that fields which are _not_ stored (see Ferret::Index::FieldInfos)
40
+ # are _not_ available in documents retrieved from the index, e.g.
41
+ # Ferret::Search::Searcher#doc or Ferret::Index::IndexReader#doc.
42
+ #
43
+ # Note: that modifying a Document retrieved from the index will not modify
44
+ # the document contained within the index. You need to delete the old
45
+ # version of the document and add the new version of the document.
46
+ class Document < Hash
47
+ include BoostMixin
48
+
49
+ # Create a new Document object with a boost. The boost defaults to 1.0.
50
+ def initialize(boost = 1.0)
51
+ @boost = boost
52
+ end
53
+
54
+ # Return true if the documents are equal, ie they have the same fields
55
+ def eql?(o)
56
+ return (o.is_a? Document and (o.boost == @boost) and
57
+ (self.keys == o.keys) and (self.values == o.values))
58
+ end
59
+ alias :== :eql?
60
+
61
+ # Create a string representation of the document
62
+ def to_s
63
+ buf = ["Document {"]
64
+ self.keys.sort_by {|key| key.to_s}.each do |key|
65
+ val = self[key]
66
+ val_str = if val.instance_of? Array then %{["#{val.join('", "')}"]}
67
+ elsif val.is_a? Field then val.to_s
68
+ else %{"#{val.to_s}"}
69
+ end
70
+ buf << " :#{key} => #{val_str}"
71
+ end
72
+ buf << ["}#{@boost == 1.0 ? "" : "^" + @boost.to_s}"]
73
+ return buf.join("\n")
74
+ end
75
+ end
76
+
77
+ # A Field is a section of a Document. A Field is basically an array with a
78
+ # boost attribute. It also provides pretty printing of the field with the
79
+ # #to_s method.
80
+ #
81
+ # === Boost
82
+ #
83
+ # The boost attribute makes a field more important in the index. That is,
84
+ # you can increase the score of a match for queries that match terms in a
85
+ # boosted field. You may, for example, want to boost a title field so that
86
+ # matches that match in the :title field score more highly than matches that
87
+ # match in the :contents field.
88
+ #
89
+ # Note: If you'd like to use boosted fields without having to use
90
+ # the Field class you can just include the BoostMixin in the Array class.
91
+ # See BoostMixin.
92
+ class Field < Array
93
+ include BoostMixin
94
+
95
+ # Create a new Field object. You can pass data to the field as either a
96
+ # string;
97
+ #
98
+ # f = Field.new("This is the fields data")
99
+ #
100
+ # or as an array of strings;
101
+ #
102
+ # f = Field.new(["this", "is", "an", "array", "of", "field", "data"])
103
+ #
104
+ # Of course Fields can also be boosted;
105
+ #
106
+ # f = Field.new("field data", 1000.0)
107
+ def initialize(data = [], boost = 1.0)
108
+ @boost = boost
109
+ if data.is_a? Array
110
+ data.each {|v| self << v}
111
+ else
112
+ self << data.to_s
113
+ end
114
+ end
115
+
116
+ def eql?(o)
117
+ return (o.is_a? Field and (o.boost == @boost) and super(o))
118
+ end
119
+ alias :== :eql?
120
+
121
+ def +(o)
122
+ return Field.new(super(o), self.boost)
123
+ end
124
+
125
+ def to_s
126
+ buf = %{["#{self.join('", "')}"]}
127
+ buf << "^#@boost" if @boost != 1.0
128
+ return buf
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,85 @@
1
+ module Isomorfeus
2
+ module Ferret
3
+ FIELD_TYPES = %w(integer float string byte).map{|t| t.to_sym}
4
+
5
+ class BlankSlate < BasicObject
6
+ end
7
+
8
+ # The FieldSymbolMethods module contains the methods that are added to both
9
+ # the Symbol class and the FieldSymbol class. These methods allow you to
10
+ # easily set the type of a field by calling a method on a symbol.
11
+ #
12
+ # Right now this is only useful for Sorting and grouping, but some day Ferret
13
+ # may have typed fields, in which case these this methods will come in handy.
14
+ #
15
+ # The available types are specified in Ferret::FIELD_TYPES.
16
+ #
17
+ # == Examples
18
+ #
19
+ # index.search(query, :sort => :title.string.desc)
20
+ #
21
+ # index.search(query, :sort => [:price.float, :count.integer.desc])
22
+ #
23
+ # index.search(query, :group_by => :catalogue.string)
24
+ #
25
+ # == Note
26
+ #
27
+ # If you set the field type multiple times, the last type specified will be
28
+ # the type used. For example;
29
+ #
30
+ # puts :title.integer.float.byte.string.type.inspect # => :string
31
+ #
32
+ # Calling #desc twice will set desc? to false
33
+ #
34
+ # puts :title.desc? # => false
35
+ # puts :title.desc.desc? # => true
36
+ # puts :title.desc.desc.desc? # => false
37
+ module FieldSymbolMethods
38
+ FIELD_TYPES.each do |method|
39
+ define_method(method) do
40
+ fsym = FieldSymbol.new(self, respond_to?(:desc?) ? desc? : false)
41
+ fsym.type = method
42
+ fsym
43
+ end
44
+ end
45
+
46
+ # Set a field to be a descending field. This only makes sense in sort
47
+ # specifications.
48
+ def desc
49
+ fsym = FieldSymbol.new(self, respond_to?(:desc?) ? !desc? : true)
50
+ fsym.type = respond_to?(:type) ? type : nil
51
+ fsym
52
+ end
53
+
54
+ # Return whether or not this field should be a descending field
55
+ def desc?
56
+ self.class == FieldSymbol and @desc == true
57
+ end
58
+
59
+ # Return the type of this field
60
+ def type
61
+ self.class == FieldSymbol ? @type : nil
62
+ end
63
+ end
64
+
65
+ # See FieldSymbolMethods
66
+ class FieldSymbol < BlankSlate
67
+ include FieldSymbolMethods
68
+
69
+ def initialize(symbol, desc = false)
70
+ @symbol = symbol
71
+ @desc = desc
72
+ end
73
+
74
+ def method_missing(method, *args)
75
+ @symbol.__send__(method, *args)
76
+ end
77
+
78
+ def class
79
+ FieldSymbol
80
+ end
81
+
82
+ attr_writer :type, :desc
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,48 @@
1
+ require 'yaml'
2
+
3
+ module Isomorfeus
4
+ module Ferret
5
+ module Index
6
+ class FieldInfos
7
+ # Load FieldInfos from a YAML file. The YAML file should look something like
8
+ # this:
9
+ # default:
10
+ # store: :yes
11
+ # index: :yes
12
+ # term_vector: :no
13
+ #
14
+ # fields:
15
+ # id:
16
+ # index: :untokenized
17
+ # term_vector: :no
18
+ #
19
+ # title:
20
+ # boost: 20.0
21
+ # term_vector: :no
22
+ #
23
+ # content:
24
+ # term_vector: :with_positions_offsets
25
+ #
26
+ def self.load(yaml_str)
27
+ info = YAML.load(yaml_str)
28
+ convert_strings_to_symbols(info)
29
+ fis = FieldInfos.new(info[:default])
30
+ fields = info[:fields]
31
+ fields.keys.each {|key| fis.add_field(key, fields[key])} if fields
32
+ fis
33
+ end
34
+
35
+ private
36
+ def self.convert_strings_to_symbols(hash)
37
+ hash.keys.each do |key|
38
+ convert_strings_to_symbols(hash[key]) if hash[key].is_a?(Hash)
39
+ if key.is_a?(String)
40
+ hash[key.intern] = hash[key]
41
+ hash.delete(key)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end