xapit 0.2.7 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. data/{CHANGELOG → CHANGELOG.rdoc} +7 -2
  2. data/Gemfile +19 -0
  3. data/LICENSE +4 -4
  4. data/README.rdoc +61 -108
  5. data/Rakefile +11 -10
  6. data/features/facets.feature +93 -82
  7. data/features/finding.feature +196 -138
  8. data/features/indexing.feature +35 -37
  9. data/features/remote_server.feature +10 -0
  10. data/features/step_definitions/xapit_steps.rb +53 -25
  11. data/features/suggestions.feature +20 -14
  12. data/features/support/env.rb +13 -6
  13. data/features/support/xapit_helpers.rb +8 -9
  14. data/lib/generators/xapit/install_generator.rb +14 -0
  15. data/lib/generators/xapit/templates/xapit.ru +6 -0
  16. data/lib/generators/xapit/templates/xapit.yml +11 -0
  17. data/lib/xapit.rb +106 -64
  18. data/lib/xapit/client/collection.rb +150 -0
  19. data/lib/xapit/client/facet.rb +11 -0
  20. data/lib/xapit/client/facet_option.rb +29 -0
  21. data/lib/xapit/client/index_builder.rb +67 -0
  22. data/lib/xapit/client/membership.rb +46 -0
  23. data/lib/xapit/client/model_adapters/abstract_model_adapter.rb +30 -0
  24. data/lib/xapit/client/model_adapters/active_record_adapter.rb +27 -0
  25. data/lib/xapit/client/model_adapters/default_model_adapter.rb +7 -0
  26. data/lib/xapit/client/railtie.rb +18 -0
  27. data/lib/xapit/client/remote_database.rb +21 -0
  28. data/lib/xapit/client/tasks.rb +18 -0
  29. data/lib/xapit/server/app.rb +27 -0
  30. data/lib/xapit/server/database.rb +47 -0
  31. data/lib/xapit/server/indexer.rb +138 -0
  32. data/lib/xapit/server/query.rb +240 -0
  33. data/spec/fixtures/blankdb/flintlock +0 -0
  34. data/spec/fixtures/blankdb/iamchert +1 -0
  35. data/spec/fixtures/blankdb/postlist.DB +0 -0
  36. data/spec/fixtures/blankdb/postlist.baseA +0 -0
  37. data/spec/fixtures/blankdb/record.DB +0 -0
  38. data/spec/fixtures/blankdb/record.baseA +0 -0
  39. data/spec/fixtures/blankdb/termlist.DB +0 -0
  40. data/spec/fixtures/blankdb/termlist.baseA +0 -0
  41. data/spec/fixtures/xapit.ru +13 -0
  42. data/spec/fixtures/xapit.yml +4 -0
  43. data/spec/spec_helper.rb +8 -9
  44. data/spec/support/spec_macros.rb +6 -0
  45. data/spec/{xapit_member.rb → support/xapit_member.rb} +14 -16
  46. data/spec/xapit/client/collection_spec.rb +63 -0
  47. data/spec/xapit/client/facet_option_spec.rb +26 -0
  48. data/spec/xapit/client/facet_spec.rb +13 -0
  49. data/spec/xapit/client/index_builder_spec.rb +66 -0
  50. data/spec/xapit/client/membership_spec.rb +43 -0
  51. data/spec/xapit/client/model_adapters/active_record_adapter_spec.rb +62 -0
  52. data/spec/xapit/client/model_adapters/default_model_adapter_spec.rb +7 -0
  53. data/spec/xapit/client/remote_database_spec.rb +19 -0
  54. data/spec/xapit/server/app_spec.rb +22 -0
  55. data/spec/xapit/server/database_spec.rb +37 -0
  56. data/spec/xapit/server/indexer_spec.rb +82 -0
  57. data/spec/xapit/server/query_spec.rb +43 -0
  58. data/spec/xapit/xapit_spec.rb +28 -0
  59. metadata +124 -93
  60. data/Manifest +0 -60
  61. data/features/sorting.feature +0 -29
  62. data/init.rb +0 -1
  63. data/install.rb +0 -8
  64. data/lib/xapit/adapters/abstract_adapter.rb +0 -47
  65. data/lib/xapit/adapters/active_record_adapter.rb +0 -20
  66. data/lib/xapit/adapters/data_mapper_adapter.rb +0 -10
  67. data/lib/xapit/collection.rb +0 -187
  68. data/lib/xapit/config.rb +0 -84
  69. data/lib/xapit/facet.rb +0 -67
  70. data/lib/xapit/facet_blueprint.rb +0 -59
  71. data/lib/xapit/facet_option.rb +0 -56
  72. data/lib/xapit/index_blueprint.rb +0 -147
  73. data/lib/xapit/indexers/abstract_indexer.rb +0 -116
  74. data/lib/xapit/indexers/classic_indexer.rb +0 -29
  75. data/lib/xapit/indexers/simple_indexer.rb +0 -38
  76. data/lib/xapit/membership.rb +0 -137
  77. data/lib/xapit/query.rb +0 -89
  78. data/lib/xapit/query_parsers/abstract_query_parser.rb +0 -174
  79. data/lib/xapit/query_parsers/classic_query_parser.rb +0 -29
  80. data/lib/xapit/query_parsers/simple_query_parser.rb +0 -75
  81. data/lib/xapit/rake_tasks.rb +0 -13
  82. data/rails_generators/xapit/USAGE +0 -13
  83. data/rails_generators/xapit/templates/setup_xapit.rb +0 -1
  84. data/rails_generators/xapit/templates/xapit.rake +0 -4
  85. data/rails_generators/xapit/xapit_generator.rb +0 -20
  86. data/spec/xapit/adapters/active_record_adapter_spec.rb +0 -31
  87. data/spec/xapit/adapters/data_mapper_adapter_spec.rb +0 -10
  88. data/spec/xapit/collection_spec.rb +0 -176
  89. data/spec/xapit/config_spec.rb +0 -62
  90. data/spec/xapit/facet_blueprint_spec.rb +0 -29
  91. data/spec/xapit/facet_option_spec.rb +0 -80
  92. data/spec/xapit/facet_spec.rb +0 -73
  93. data/spec/xapit/index_blueprint_spec.rb +0 -112
  94. data/spec/xapit/indexers/abstract_indexer_spec.rb +0 -111
  95. data/spec/xapit/indexers/classic_indexer_spec.rb +0 -35
  96. data/spec/xapit/indexers/simple_indexer_spec.rb +0 -69
  97. data/spec/xapit/membership_spec.rb +0 -55
  98. data/spec/xapit/query_parsers/abstract_query_parser_spec.rb +0 -60
  99. data/spec/xapit/query_parsers/classic_query_parser_spec.rb +0 -20
  100. data/spec/xapit/query_parsers/simple_query_parser_spec.rb +0 -86
  101. data/spec/xapit/query_spec.rb +0 -60
  102. data/tasks/spec.rb +0 -9
  103. data/tasks/xapit.rake +0 -1
  104. data/uninstall.rb +0 -5
  105. data/xapit.gemspec +0 -30
@@ -1,29 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Xapit::FacetBlueprint do
4
- it "should generate unique identifier based on attribute and value" do
5
- facet1 = Xapit::FacetBlueprint.new(XapitMember, 0, :to_s)
6
- facet2 = Xapit::FacetBlueprint.new(XapitMember, 0, :length)
7
- facet1.identifiers_for("foo").first.length.should == 7
8
- facet1.identifiers_for("foo").should_not == facet1.identifiers_for("bar")
9
- facet1.identifiers_for("foo").should_not == facet2.identifiers_for("foo")
10
- end
11
-
12
- it "should generate unique identifiers for each value returned" do
13
- facet = Xapit::FacetBlueprint.new(XapitMember, 0, :to_a)
14
- facet.identifiers_for(["foo", "bar"]).size.should == 2
15
- end
16
-
17
- it "should humanize attribute for name if one isn't given" do
18
- Xapit::FacetBlueprint.new(XapitMember, 0, :visible).name.should == "Visible"
19
- end
20
-
21
- it "should use custom name if given" do
22
- Xapit::FacetBlueprint.new(XapitMember, 0, :visible, "custom").name.should == "custom"
23
- end
24
-
25
- it "should not have identifiers for blank values" do
26
- facet = Xapit::FacetBlueprint.new(XapitMember, 0, :to_a)
27
- facet.identifiers_for(["", nil, "bar"]).size.should == 1
28
- end
29
- end
@@ -1,80 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Xapit::FacetOption do
4
- it "should combine previous identifiers with current one on to_param" do
5
- option = Xapit::FacetOption.new(nil, nil, nil)
6
- option.existing_facet_identifiers = ["abc", "123"]
7
- stub(option).identifier { "foo" }
8
- option.to_param.should == "abc-123-foo"
9
- end
10
-
11
- it "should remove current identifier from previous identifiers if it exists" do
12
- Xapit.setup(:breadcrumb_facets => false)
13
- option = Xapit::FacetOption.new(nil, nil, nil)
14
- option.existing_facet_identifiers = ["abc", "123", "foo"]
15
- stub(option).identifier { "foo" }
16
- option.to_param.should == "abc-123"
17
- end
18
-
19
- it "should support breadcrumb style facets" do
20
- Xapit.setup(:breadcrumb_facets => true)
21
- option = Xapit::FacetOption.new(nil, nil, nil)
22
- option.existing_facet_identifiers = ["abc", "123", "foo"]
23
- stub(option).identifier { "123" }
24
- option.to_param.should == "abc-123"
25
- end
26
-
27
- describe "with database" do
28
- before(:each) do
29
- XapitMember.xapit do |index|
30
- index.facet :age, "Person Age"
31
- index.facet :category
32
- end
33
- end
34
-
35
- it "should have identifier hashing name and value" do
36
- option = Xapit::FacetOption.new("XapitMember", "age", "17")
37
- option.identifier.should == "0c93ee1"
38
- end
39
-
40
- it "should find facet option from database given id" do
41
- doc = Xapian::Document.new
42
- doc.data = "XapitMember|||age|||17"
43
- doc.add_term("QXapit::FacetOption-abc123")
44
- Xapit::Config.writable_database.add_document(doc)
45
- option = Xapit::FacetOption.find("abc123")
46
- option.name.should == "17"
47
- option.facet.name.should == "Person Age"
48
- end
49
-
50
- it "should save facet to database" do
51
- Xapit::Config.writable_database # make sure there's a database setup in case we try to read from it
52
- option = Xapit::FacetOption.new(nil, nil, nil)
53
- option.facet = XapitMember.xapit_facet_blueprint("age")
54
- option.name = "23"
55
- option.save
56
- Xapit::FacetOption.find(option.identifier).should_not be_nil
57
- end
58
-
59
- it "should not save facet if it already exists" do
60
- doc = Xapian::Document.new
61
- doc.data = "XapitMember|||age|||17"
62
- doc.add_term("QXapit::FacetOption-abc123")
63
- Xapit::Config.writable_database.add_document(doc)
64
- stub(Xapit::Config.writable_database).add_document { raise "should not add doc" }
65
- option = Xapit::FacetOption.new(XapitMember, nil, nil)
66
- stub(option).identifier { "abc123" }
67
- option.save
68
- end
69
-
70
- it "should find facet option which doesn't have a value" do
71
- doc = Xapian::Document.new
72
- doc.data = "XapitMember|||age|||"
73
- doc.add_term("QXapit::FacetOption-abc123")
74
- Xapit::Config.writable_database.add_document(doc)
75
- option = Xapit::FacetOption.find("abc123")
76
- option.name.should == ""
77
- option.facet.name.should == "Person Age"
78
- end
79
- end
80
- end
@@ -1,73 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Xapit::Facet do
4
- describe "with database" do
5
- before(:each) do
6
- XapitMember.xapit do |index|
7
- index.facet :visible
8
- end
9
- end
10
-
11
- describe "indexed" do
12
- before(:each) do
13
- @visible1 = XapitMember.new(:visible => true)
14
- @visible2 = XapitMember.new(:visible => true)
15
- @invisible = XapitMember.new(:visible => false)
16
- Xapit.index_all
17
- end
18
-
19
- describe "facet from empty search" do
20
- before(:each) do
21
- @facet = XapitMember.search("").facets.first
22
- end
23
-
24
- it "should have the name of 'Visible'" do
25
- @facet.name.should == 'Visible'
26
- end
27
-
28
- it "should have true and false options" do
29
- @facet.options.map(&:name).sort.should == %w[false true]
30
- end
31
-
32
- it "should have record count" do
33
- @facet.options.detect { |o| o.name == 'true' }.count.should == 2
34
- @facet.options.detect { |o| o.name == 'false' }.count.should == 1
35
- end
36
-
37
- it "should have identifier for options" do
38
- blueprint = Xapit::FacetBlueprint.new(XapitMember, 0, :visible)
39
- @facet.options.detect { |o| o.name == 'true' }.identifier.should == blueprint.identifiers_for(@visible1).first
40
- @facet.options.detect { |o| o.name == 'false' }.identifier.should == blueprint.identifiers_for(@invisible).first
41
- end
42
-
43
- it "should have matching identifiers" do
44
- blueprint = Xapit::FacetBlueprint.new(XapitMember, 0, :visible)
45
- hash = { blueprint.identifiers_for(@visible1).first => 2, blueprint.identifiers_for(@invisible).first => 1 }
46
- @facet.matching_identifiers.should == hash
47
- end
48
-
49
- it "should not include matching identifiers that are current" do
50
- blueprint = Xapit::FacetBlueprint.new(XapitMember, 0, :visible)
51
- @facet.existing_facet_identifiers = blueprint.identifiers_for(@visible1)
52
- @facet.matching_identifiers.should == { blueprint.identifiers_for(@invisible).first => 1 }
53
- end
54
-
55
- it "should return identifier on to_param" do
56
- blueprint = Xapit::FacetBlueprint.new(XapitMember, 0, :visible)
57
- @facet.options.detect { |o| o.name == 'true' }.to_param.should == blueprint.identifiers_for(@visible1).first
58
- end
59
-
60
- it "should sort options in alphabetical order" do
61
- @facet.options.first.name.should == 'false'
62
- @facet.options.last.name.should == 'true'
63
- end
64
- end
65
-
66
- it "should not list facets if only one option is found" do
67
- blueprint = Xapit::FacetBlueprint.new(XapitMember, 0, :visible)
68
- facets = XapitMember.search(:facets => blueprint.identifiers_for(@visible1)).facets
69
- facets.should be_empty
70
- end
71
- end
72
- end
73
- end
@@ -1,112 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Xapit::IndexBlueprint do
4
- before(:each) do
5
- XapitMember.xapit { } # call so methods are generated
6
- @index = Xapit::IndexBlueprint.new(XapitMember)
7
- end
8
-
9
- it "should remember text attributes" do
10
- @index.text(:foo)
11
- @index.text(:bar, :blah)
12
- @index.text(:custom) { |t| t*t }
13
- @index.text_attributes.keys.should include(:foo, :bar, :blah, :custom)
14
- @index.text_attributes[:foo][:proc].should be_nil
15
- @index.text_attributes[:custom][:proc].should be_kind_of(Proc)
16
- end
17
-
18
- it "should remember field attributes" do
19
- @index.field(:foo)
20
- @index.field(:bar, :blah)
21
- @index.field_attributes.should include(:foo, :bar, :blah)
22
- end
23
-
24
- it "should remember facets" do
25
- @index.facet(:foo)
26
- @index.facet(:bar, "Baz")
27
- @index.facets.map(&:name).should == ["Foo", "Baz"]
28
- end
29
-
30
- it "should remember sortable attributes" do
31
- @index.sortable(:foo)
32
- @index.sortable(:bar, :blah)
33
- @index.sortable_attributes.should include(:foo, :bar, :blah)
34
- end
35
-
36
- it "should have a sortable position offset by facets" do
37
- @index.facet(:foo)
38
- @index.facet(:test)
39
- @index.sortable(:bar, :blah)
40
- @index.position_of_sortable(:blah).should == 3
41
- end
42
-
43
- it "should have a field position offset by facets + sortable" do
44
- @index.facet(:foo)
45
- @index.sortable(:bar, :blah)
46
- @index.field(:bar, :blah)
47
- @index.position_of_field(:blah).should == 4
48
- end
49
-
50
- it "should index member document into database" do
51
- XapitMember.new
52
- @index.index_all
53
- Xapit::Config.writable_database.doccount.should >= 1
54
- Xapit::Config.writable_database.flush
55
- end
56
-
57
- it "should remember all blueprints and index each of them" do
58
- stub(Xapit::Config.writable_database).add_document
59
- mock(@index).index_all
60
- Xapit::IndexBlueprint.index_all
61
- end
62
-
63
- it "should pass in extra arguments to each method" do
64
- index = Xapit::IndexBlueprint.new(XapitMember, :foo, :bar => :blah)
65
- mock(XapitMember).find_each(:foo, :bar => :blah)
66
- index.index_all
67
- end
68
-
69
- it "should add a record from the index" do
70
- member = XapitMember.new(:name => "New Record!")
71
- @index.text :name
72
- @index.create_record(member.id)
73
- XapitMember.search("New Record").should == [member]
74
- end
75
-
76
- it "should remove a record from the index" do
77
- member = XapitMember.new(:name => "Bad Record!")
78
- @index.text :name
79
- @index.index_all
80
- @index.destroy_record(member.id)
81
- XapitMember.search("Bad Record").should == []
82
- end
83
-
84
- it "should update a record in the index" do
85
- member = XapitMember.new(:name => "New Record!")
86
- @index.text :name
87
- @index.index_all
88
- member.update_attribute(:name, "Changed Record!")
89
- @index.update_record(member.id)
90
- XapitMember.search("Changed Record").should == [member]
91
- end
92
-
93
- it "should not create record index if member isn't found" do
94
- Xapit::Config.writable_database # make sure the database is built
95
- member = XapitMember.new(:name => "New Record!")
96
- stub(XapitMember).find { nil }
97
- @index.text :name
98
- @index.create_record(member.id)
99
- XapitMember.search("New Record").should be_empty
100
- end
101
-
102
- it "should remove record from index when updating a member which doesn't exist" do
103
- member = XapitMember.new(:name => "New Record!")
104
- @index.text :name
105
- @index.index_all
106
- stub(XapitMember).find { nil }
107
- member.update_attribute(:name, "Changed Record!")
108
- @index.update_record(member.id)
109
- XapitMember.search("New Record").should be_empty
110
- XapitMember.search("Changed Record").should be_empty
111
- end
112
- end
@@ -1,111 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
-
3
- describe Xapit::AbstractIndexer do
4
- before(:each) do
5
- XapitMember.xapit { } # to ensure methods are included
6
- @index = Xapit::IndexBlueprint.new(XapitMember)
7
- @indexer = Xapit::SimpleIndexer.new(@index)
8
- end
9
-
10
- it "should map field to term with 'X' prefix" do
11
- member = Object.new
12
- stub(member).category { "Water" }
13
- @index.field(:category)
14
- @indexer.field_terms(member).should == %w[Xcategory-water]
15
- end
16
-
17
- it "should add terms separately when array is returned" do
18
- member = Object.new
19
- stub(member).category { ["Water", "Liquid"] }
20
- @index.field(:category)
21
- @indexer.field_terms(member).should == %w[Xcategory-water Xcategory-liquid]
22
- end
23
-
24
- it "should have base terms with class name and id" do
25
- member = Object.new
26
- stub(member).id { 123 }
27
- @indexer.base_terms(member).should == %w[CObject QObject-123]
28
- end
29
-
30
- it "should add terms, values and options for facets" do
31
- Xapit::Config.writable_database # force xapit to use a writable database at the beginning
32
- stub(XapitMember).xapit_index_blueprint { @index }
33
- member = XapitMember.new(:foo => ["ABC", "DEF"])
34
- ids = Xapit::FacetBlueprint.new(XapitMember, 0, :foo).identifiers_for(member)
35
- @index.facet(:foo)
36
- @indexer.facet_terms(member).should == ids.map { |id| "F#{id}" }
37
- @indexer.values(member).should == [ids.join('-')]
38
- @indexer.save_facet_options_for(member)
39
- ids.map { |id| Xapit::FacetOption.find(id).name }.should == ["ABC", "DEF"]
40
- end
41
-
42
- it "should add values for sortable fields" do
43
- member = Object.new
44
- stub(member).name { "Foo" }
45
- @index.sortable(:name)
46
- @indexer.values(member).should == ["foo"]
47
- end
48
-
49
- it "should add terms and values to xapian document" do
50
- member = Object.new
51
- stub(member).id { 123 }
52
- stub(@indexer).values.returns(%w[value list])
53
- stub(@indexer).other_terms { %w[term list] }
54
- doc = @indexer.document_for(member)
55
- doc.should be_kind_of(Xapian::Document)
56
- doc.data.should == "Object-123"
57
- doc.values.map(&:value).sort.should == %w[value list].sort
58
- doc.terms.map(&:term).sort.should == %w[term list].sort
59
- end
60
-
61
- it "should convert time to integer before saving as field term" do
62
- member = Object.new
63
- stub(member).created_at { Time.now }
64
- @index.field(:created_at)
65
- @indexer.field_terms(member).should == ["Xcreated_at-#{member.created_at.to_i}"]
66
- end
67
-
68
- it "should convert date to time then integer before saving as field term" do
69
- member = Object.new
70
- stub(member).created_on { Date.today }
71
- @index.field(:created_on)
72
- @indexer.field_terms(member).should == ["Xcreated_on-#{member.created_on.to_time.to_i}"]
73
- end
74
-
75
- it "should use sortable_serialze for numeric sortable" do
76
- member = Object.new
77
- stub(member).age { 7.89 }
78
- @index.sortable(:age)
79
- @indexer.values(member).should == [Xapian.sortable_serialise(7.89)]
80
- end
81
-
82
- it "should only use first value if sortable attribute is an array" do
83
- member = Object.new
84
- stub(member).age { [1, 2] }
85
- @index.sortable(:age)
86
- @indexer.values(member).should == [Xapian.sortable_serialise(1)]
87
- end
88
-
89
- it "should add sortable_serialze value for numeric field" do
90
- member = Object.new
91
- stub(member).age { [1, 2] }
92
- @index.field(:age)
93
- @indexer.values(member).should == [Xapian.sortable_serialise(1)]
94
- end
95
-
96
- it "should use sortable_serialze for date field" do
97
- date = Date.today
98
- member = Object.new
99
- stub(member).age { date }
100
- @index.field(:age)
101
- @indexer.values(member).should == [Xapian.sortable_serialise(date.to_time.to_i)]
102
- end
103
-
104
- it "should use sortable_serialze for time field" do
105
- time = Time.now
106
- member = Object.new
107
- stub(member).age { time }
108
- @index.field(:age)
109
- @indexer.values(member).should == [Xapian.sortable_serialise(time.to_i)]
110
- end
111
- end
@@ -1,35 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
-
3
- describe Xapit::ClassicIndexer do
4
- before(:each) do
5
- @index = Xapit::IndexBlueprint.new(XapitMember)
6
- @indexer = Xapit::ClassicIndexer.new(@index)
7
- end
8
-
9
- it "should add text terms to document when indexing attributes" do
10
- member = Object.new
11
- stub(member).name { "jumping high" }
12
- @index.text(:name)
13
- document = Xapian::Document.new
14
- @indexer.index_text_attributes(member, document)
15
- document.terms.map(&:term).sort.should == %w[Zjump Zhigh jumping high].sort
16
- end
17
-
18
- it "should use given block to generate text terms" do
19
- member = Object.new
20
- stub(member).name { "foobar" }
21
- @index.text(:name) { |t| [t.length] }
22
- document = Xapian::Document.new
23
- @indexer.index_text_attributes(member, document)
24
- document.terms.map(&:term).sort.should == %w[6].sort
25
- end
26
-
27
- it "should return terms separated by array" do
28
- member = Object.new
29
- stub(member).description { ["foo bar", 6, "", nil] }
30
- @index.text(:description)
31
- document = Xapian::Document.new
32
- @indexer.index_text_attributes(member, document)
33
- document.terms.map(&:term).sort.should == ["foo bar", "6"].sort
34
- end
35
- end
@@ -1,69 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
-
3
- describe Xapit::SimpleIndexer do
4
- before(:each) do
5
- @index = Xapit::IndexBlueprint.new(XapitMember)
6
- @indexer = Xapit::SimpleIndexer.new(@index)
7
- end
8
-
9
- it "should return terms for text attributes" do
10
- member = Object.new
11
- stub(member).description { "This is a test" }
12
- @index.text(:description)
13
- @indexer.terms_for_attribute(member, :description, {}).should == %w[this is a test]
14
- end
15
-
16
- it "should return text terms with stemming added" do
17
- member = Object.new
18
- stub(member).description { "jumping high" }
19
- @index.text(:description)
20
- @indexer.stemmed_terms_for_attribute(member, :description, {}).should == %w[Zjump Zhigh]
21
- end
22
-
23
- it "should convert attribute to string when converting text to terms" do
24
- member = Object.new
25
- stub(member).num { 123 }
26
- @index.text(:num)
27
- @indexer.terms_for_attribute(member, :num, {}).should == %w[123]
28
- end
29
-
30
- it "should add text terms to document when indexing attributes" do
31
- @index.text(:description)
32
- stub(@indexer).terms_for_attribute { %w[term list] }
33
- document = Xapian::Document.new
34
- @indexer.index_text_attributes(nil, document)
35
- document.terms.map(&:term).sort.should == %w[Zlist Zterm list term].sort
36
- end
37
-
38
- it "should use given block to generate text terms" do
39
- member = Object.new
40
- stub(member).name { "foobar" }
41
- proc = lambda { |t| [t.length] }
42
- @indexer.terms_for_attribute(member, :name, { :proc => proc }).should == ["6"]
43
- end
44
-
45
- it "should increment term frequency by weight option" do
46
- member = Object.new
47
- stub(member).description { "This is a test" }
48
- @index.text(:description, :weight => 10)
49
- document = Xapian::Document.new
50
- @indexer.index_text_attributes(member, document)
51
- document.terms.first.wdf.should == 10
52
- end
53
-
54
- it "should increment term frequency by weight option" do
55
- member = Object.new
56
- stub(member).description { "This is a test" }
57
- @index.text(:description, :weight => 10)
58
- document = Xapian::Document.new
59
- @indexer.index_text_attributes(member, document)
60
- document.terms.first.wdf.should == 10
61
- end
62
-
63
- it "should return terms separated by array" do
64
- member = Object.new
65
- stub(member).description { ["foo bar", 6, "", nil] }
66
- @index.text(:description)
67
- @indexer.terms_for_attribute(member, :description, {}).should == ["foo bar", "6"]
68
- end
69
- end