diff options
| author | hukl <contact@smyck.org> | 2009-04-28 00:15:53 +0200 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-05-01 17:14:02 +0200 |
| commit | 4bd16f053847f2efe347ebda9136ef2233ee0d2c (patch) | |
| tree | f4c11f89455de991c8d87726d5757b752e7129e2 /vendor/plugins/thinking-sphinx/lib/thinking_sphinx/facet.rb | |
| parent | d3a9b46ba5c863a0ff377dcffae9a494fe476e02 (diff) | |
added thinking_sphinx plugin for fulltext search on nodes and heads
Diffstat (limited to 'vendor/plugins/thinking-sphinx/lib/thinking_sphinx/facet.rb')
| -rw-r--r-- | vendor/plugins/thinking-sphinx/lib/thinking_sphinx/facet.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/vendor/plugins/thinking-sphinx/lib/thinking_sphinx/facet.rb b/vendor/plugins/thinking-sphinx/lib/thinking_sphinx/facet.rb new file mode 100644 index 0000000..e2db449 --- /dev/null +++ b/vendor/plugins/thinking-sphinx/lib/thinking_sphinx/facet.rb | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | module ThinkingSphinx | ||
| 2 | class Facet | ||
| 3 | attr_reader :reference | ||
| 4 | |||
| 5 | def initialize(reference) | ||
| 6 | @reference = reference | ||
| 7 | |||
| 8 | if reference.columns.length != 1 | ||
| 9 | raise "Can't translate Facets on multiple-column field or attribute" | ||
| 10 | end | ||
| 11 | end | ||
| 12 | |||
| 13 | def name | ||
| 14 | reference.unique_name | ||
| 15 | end | ||
| 16 | |||
| 17 | def attribute_name | ||
| 18 | # @attribute_name ||= case @reference | ||
| 19 | # when Attribute | ||
| 20 | # @reference.unique_name.to_s | ||
| 21 | # when Field | ||
| 22 | @attribute_name ||= @reference.unique_name.to_s + "_facet" | ||
| 23 | # end | ||
| 24 | end | ||
| 25 | |||
| 26 | def value(object, attribute_value) | ||
| 27 | return translate(object, attribute_value) if @reference.is_a?(Field) | ||
| 28 | |||
| 29 | case @reference.type | ||
| 30 | when :string | ||
| 31 | translate(object, attribute_value) | ||
| 32 | when :datetime | ||
| 33 | Time.at(attribute_value) | ||
| 34 | when :boolean | ||
| 35 | attribute_value > 0 | ||
| 36 | else | ||
| 37 | attribute_value | ||
| 38 | end | ||
| 39 | end | ||
| 40 | |||
| 41 | def to_s | ||
| 42 | name | ||
| 43 | end | ||
| 44 | |||
| 45 | private | ||
| 46 | |||
| 47 | def translate(object, attribute_value) | ||
| 48 | column.__stack.each { |method| | ||
| 49 | object = object.send(method) | ||
| 50 | } | ||
| 51 | object.send(column.__name) | ||
| 52 | end | ||
| 53 | |||
| 54 | def column | ||
| 55 | @reference.columns.first | ||
| 56 | end | ||
| 57 | end | ||
| 58 | end \ No newline at end of file | ||
