spontaneous 0.2.0.beta1 → 0.2.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/.locat +42 -0
- data/.travis/gemfiles/Gemfile.empty +7 -0
- data/.travis.yml +18 -0
- data/Gemfile +12 -8
- data/LICENSE +1 -1
- data/Rakefile +15 -157
- data/Readme.markdown +1 -1
- data/application/css/core.css.scss +22 -146
- data/application/css/definitions.css.scss +7 -3
- data/application/css/dialogue.css.scss +26 -1
- data/application/css/editing.css.scss +70 -28
- data/application/css/font.css.scss +1 -1
- data/application/css/popover.css.scss +2 -0
- data/application/css/top.css.scss +231 -0
- data/application/js/add_alias_dialogue.js +1 -1
- data/application/js/add_home_dialogue.js +1 -1
- data/application/js/ajax.js +61 -31
- data/application/js/box.js +4 -4
- data/application/js/conflicted_field_dialogue.js +1 -1
- data/application/js/content.js +5 -5
- data/application/js/dom.js +5 -0
- data/application/js/edit_panel.js +1 -0
- data/application/js/editing.js +1 -1
- data/application/js/extensions.js +8 -0
- data/application/js/field/boolean.js +31 -0
- data/application/js/field/file.js +32 -4
- data/application/js/field/image.js +24 -9
- data/application/js/field/markdown.js +87 -59
- data/application/js/field/select.js +1 -1
- data/application/js/field/webvideo.js +6 -1
- data/application/js/init.js +2 -2
- data/application/js/jquery-selection-position.js +130 -0
- data/application/js/location.js +4 -25
- data/application/js/meta_view/user_admin.js +2 -2
- data/application/js/metadata.js +2 -2
- data/application/js/page_browser.js +1 -1
- data/application/js/panel/root_menu.js +0 -1
- data/application/js/popover.js +27 -12
- data/application/js/popover_view.js +20 -4
- data/application/js/preview.js +31 -16
- data/application/js/progress.js +22 -21
- data/application/js/publish.js +18 -7
- data/application/js/sharded_upload.js +9 -6
- data/application/js/spontaneous.js +3 -1
- data/application/js/top_bar.js +264 -173
- data/application/js/upload.js +12 -5
- data/application/js/upload_manager.js +4 -3
- data/application/js/user.js +1 -2
- data/application/js/views/box_view.js +1 -1
- data/application/js/views/page_view.js +16 -5
- data/application/js/views/piece_view.js +5 -4
- data/application/static/font/fontawesome-webfont-1c66a4738b40ef0f6b1abca0ba9a796d.ttf +0 -0
- data/application/views/index.erb +6 -14
- data/application/views/login.erb +6 -25
- data/application/views/schema_modification_error.html.erb +3 -7
- data/db/migrations/20130114120000_create_revision_tables.rb +2 -2
- data/db/migrations/20130813111009_increase_path_length.rb +14 -0
- data/gem-public_cert.pem +20 -0
- data/lib/spontaneous/asset/app_compiler.rb +44 -0
- data/lib/spontaneous/asset/environment.rb +225 -0
- data/lib/spontaneous/asset.rb +2 -67
- data/lib/spontaneous/box.rb +0 -1
- data/lib/spontaneous/capistrano/deploy.rb +2 -2
- data/lib/spontaneous/capistrano/sync.rb +1 -1
- data/lib/spontaneous/cli/init.rb +36 -13
- data/lib/spontaneous/cli/server.rb +0 -1
- data/lib/spontaneous/cli/site.rb +2 -1
- data/lib/spontaneous/cli.rb +3 -1
- data/lib/spontaneous/collections/entry_set.rb +4 -12
- data/lib/spontaneous/collections/hash_with_fallback.rb +20 -0
- data/lib/spontaneous/collections/prototype_set.rb +6 -5
- data/lib/spontaneous/crypt.rb +2 -2
- data/lib/spontaneous/data_mapper/content_model/associations.rb +115 -63
- data/lib/spontaneous/data_mapper.rb +1 -1
- data/lib/spontaneous/errors.rb +6 -0
- data/lib/spontaneous/extensions/object_space.rb +6 -0
- data/lib/spontaneous/facet.rb +1 -0
- data/lib/spontaneous/field/base.rb +86 -13
- data/lib/spontaneous/field/boolean.rb +65 -0
- data/lib/spontaneous/field/file.rb +17 -6
- data/lib/spontaneous/field/html.rb +13 -0
- data/lib/spontaneous/field/image/size.rb +76 -0
- data/lib/spontaneous/field/image.rb +99 -414
- data/lib/spontaneous/field/tags.rb +36 -0
- data/lib/spontaneous/field/update.rb +1 -1
- data/lib/spontaneous/field/webvideo/fallback.rb +41 -0
- data/lib/spontaneous/field/webvideo/vimeo.rb +113 -0
- data/lib/spontaneous/field/webvideo/vine.rb +94 -0
- data/lib/spontaneous/field/webvideo/youtube.rb +133 -0
- data/lib/spontaneous/field/webvideo.rb +100 -250
- data/lib/spontaneous/field.rb +1 -1
- data/lib/spontaneous/generators/site/Gemfile.tt +5 -14
- data/lib/spontaneous/generators/site/assets/README.md +20 -0
- data/lib/spontaneous/generators/site/assets/css/site.scss +8 -0
- data/lib/spontaneous/generators/site/assets/js/site.js +6 -0
- data/lib/spontaneous/generators/site/config/deploy.rb.tt +9 -0
- data/lib/spontaneous/generators/site/config/user_levels.yml +14 -3
- data/lib/spontaneous/generators/site/public/README.md +12 -0
- data/lib/spontaneous/generators/site/templates/layouts/standard.html.cut.tt +2 -2
- data/lib/spontaneous/generators/site.rb +77 -35
- data/lib/spontaneous/layout.rb +6 -7
- data/lib/spontaneous/loader.rb +21 -13
- data/lib/spontaneous/media/file.rb +22 -9
- data/lib/spontaneous/media/image/attributes.rb +33 -0
- data/lib/spontaneous/media/image/format/gif.rb +4 -0
- data/lib/spontaneous/media/image/format/jpg.rb +17 -0
- data/lib/spontaneous/media/image/format/png.rb +4 -0
- data/lib/spontaneous/media/image/format/webp.rb +26 -0
- data/lib/spontaneous/media/image/format.rb +79 -0
- data/lib/spontaneous/media/image/optimizer.rb +69 -0
- data/lib/spontaneous/media/image/processor.rb +17 -0
- data/lib/spontaneous/media/image/renderable.rb +52 -0
- data/lib/spontaneous/media/image/skeptick.rb +70 -0
- data/lib/spontaneous/media/image.rb +50 -0
- data/lib/spontaneous/media/temp_file.rb +4 -0
- data/lib/spontaneous/media.rb +1 -0
- data/lib/spontaneous/model/core/aliases.rb +14 -8
- data/lib/spontaneous/model/core/boxes.rb +5 -2
- data/lib/spontaneous/model/core/entries.rb +4 -0
- data/lib/spontaneous/model/core/entry.rb +1 -0
- data/lib/spontaneous/model/core/fields.rb +5 -2
- data/lib/spontaneous/model/core/locks.rb +16 -0
- data/lib/spontaneous/model/core/media.rb +1 -15
- data/lib/spontaneous/model/core.rb +31 -1
- data/lib/spontaneous/model/page/controllers.rb +2 -2
- data/lib/spontaneous/model/page/formats.rb +1 -4
- data/lib/spontaneous/model/page/layouts.rb +6 -2
- data/lib/spontaneous/model/page/locks.rb +8 -2
- data/lib/spontaneous/model/page/page_tree.rb +2 -2
- data/lib/spontaneous/model/page/paths.rb +74 -9
- data/lib/spontaneous/model/page.rb +11 -3
- data/lib/spontaneous/model.rb +6 -6
- data/lib/spontaneous/output/context/render_cache.rb +23 -0
- data/lib/spontaneous/output/context.rb +56 -30
- data/lib/spontaneous/output/helpers/script_helper.rb +9 -53
- data/lib/spontaneous/output/helpers/stylesheet_helper.rb +8 -40
- data/lib/spontaneous/output/template/renderer.rb +17 -5
- data/lib/spontaneous/output.rb +0 -1
- data/lib/spontaneous/paths.rb +6 -2
- data/lib/spontaneous/permissions/access_key.rb +18 -0
- data/lib/spontaneous/permissions/user.rb +1 -1
- data/lib/spontaneous/permissions.rb +4 -1
- data/lib/spontaneous/plugins/application/state.rb +19 -12
- data/lib/spontaneous/prototypes/field_prototype.rb +14 -8
- data/lib/spontaneous/published_revision.rb +7 -0
- data/lib/spontaneous/publishing/immediate.rb +43 -34
- data/lib/spontaneous/publishing/revision.rb +9 -6
- data/lib/spontaneous/rack/asset_server.rb +20 -0
- data/lib/spontaneous/rack/back/alias.rb +46 -0
- data/lib/spontaneous/rack/back/application_assets.rb +28 -0
- data/lib/spontaneous/rack/back/base.rb +34 -0
- data/lib/spontaneous/rack/back/changes.rb +19 -0
- data/lib/spontaneous/rack/back/content.rb +54 -0
- data/lib/spontaneous/rack/back/events.rb +38 -0
- data/lib/spontaneous/rack/back/field.rb +37 -0
- data/lib/spontaneous/rack/back/file.rb +118 -0
- data/lib/spontaneous/rack/back/helpers.rb +71 -0
- data/lib/spontaneous/rack/back/index.rb +16 -0
- data/lib/spontaneous/rack/back/login.rb +47 -0
- data/lib/spontaneous/rack/back/map.rb +24 -0
- data/lib/spontaneous/rack/back/page.rb +46 -0
- data/lib/spontaneous/rack/back/preview.rb +43 -0
- data/lib/spontaneous/rack/back/schema.rb +30 -0
- data/lib/spontaneous/rack/back/site.rb +25 -0
- data/lib/spontaneous/rack/back/site_assets.rb +13 -0
- data/lib/spontaneous/rack/back/unsupported_browser.rb +7 -0
- data/lib/spontaneous/rack/{user_admin.rb → back/user_admin.rb} +2 -5
- data/lib/spontaneous/rack/back.rb +85 -764
- data/lib/spontaneous/rack/cacheable_file.rb +3 -3
- data/lib/spontaneous/rack/front.rb +16 -9
- data/lib/spontaneous/rack/middleware/authenticate.rb +65 -0
- data/lib/spontaneous/rack/middleware/csrf.rb +66 -0
- data/lib/spontaneous/rack/middleware/reloader.rb +52 -0
- data/lib/spontaneous/rack/middleware/scope.rb +60 -0
- data/lib/spontaneous/rack/middleware.rb +6 -0
- data/lib/spontaneous/rack/page_controller.rb +18 -5
- data/lib/spontaneous/rack/public.rb +17 -11
- data/lib/spontaneous/rack.rb +34 -24
- data/lib/spontaneous/revision.rb +29 -2
- data/lib/spontaneous/schema/uid.rb +4 -3
- data/lib/spontaneous/schema/uid_map.rb +5 -24
- data/lib/spontaneous/schema.rb +1 -0
- data/lib/spontaneous/search/database.rb +8 -0
- data/lib/spontaneous/search/field.rb +1 -1
- data/lib/spontaneous/search/index.rb +3 -5
- data/lib/spontaneous/server.rb +1 -1
- data/lib/spontaneous/simultaneous.rb +1 -1
- data/lib/spontaneous/site/features.rb +4 -5
- data/lib/spontaneous/site/helpers.rb +22 -5
- data/lib/spontaneous/site/instance.rb +2 -2
- data/lib/spontaneous/site/selectors.rb +22 -3
- data/lib/spontaneous/storage/cloud.rb +13 -9
- data/lib/spontaneous/storage/local.rb +11 -6
- data/lib/spontaneous/style.rb +40 -23
- data/lib/spontaneous/utils/database/mysql_dumper.rb +1 -1
- data/lib/spontaneous/utils/smush_it.rb +1 -1
- data/lib/spontaneous/version.rb +1 -1
- data/lib/spontaneous.rb +35 -33
- data/spontaneous.gemspec +53 -787
- data/test/experimental/test_crypt.rb +56 -56
- data/test/experimental/test_features.rb +16 -27
- data/test/fixtures/assets/public1/css/data.css.scss +3 -0
- data/test/fixtures/assets/public1/css/image1.css.scss +4 -0
- data/test/fixtures/assets/public1/css/import.css.scss +1 -0
- data/test/fixtures/assets/public1/css/urlhash.css.scss +3 -0
- data/test/fixtures/assets/public1/js/a.js +1 -1
- data/test/fixtures/assets/public1/js/all.js +4 -0
- data/test/fixtures/assets/public1/js/{m.coffee → m.js.coffee} +1 -0
- data/test/fixtures/assets/public1/x.js +1 -0
- data/test/fixtures/assets/public2/css/all.css +4 -0
- data/test/fixtures/assets/public2/css/missing.css.scss +3 -0
- data/test/fixtures/assets/public2/i/y.png +0 -0
- data/test/fixtures/assets/public2/js/b.js +1 -1
- data/test/fixtures/assets/public2/js/c.js +1 -1
- data/test/fixtures/images/size.extended.webp +0 -0
- data/test/fixtures/images/size.lossless.webp +0 -0
- data/test/fixtures/images/size.lossy.webp +0 -0
- data/test/fixtures/schema/before.yml +4 -4
- data/test/fixtures/schema/schema.yml +1 -1
- data/test/fixtures/templates/aliases/aaa.html.cut +0 -0
- data/test/fixtures/templates/extended/partial_with_renderer.html.cut +1 -0
- data/test/fixtures/templates/extended/with_includes_and_renderer.html.cut +2 -0
- data/test/functional/test_application.rb +108 -106
- data/test/functional/test_back.rb +924 -930
- data/test/functional/test_front.rb +285 -238
- data/test/functional/test_user_manager.rb +75 -100
- data/test/integration/test_installation.rb +1 -1
- data/test/support/matchers.rb +12 -0
- data/test/support/minitest.rb +121 -0
- data/test/support/rack.rb +45 -0
- data/test/support/test_start_finish.rb +103 -0
- data/test/test_helper.rb +21 -68
- data/test/test_integration_helper.rb +1 -3
- data/test/unit/test_alias.rb +432 -408
- data/test/unit/test_asset_bundler.rb +58 -58
- data/test/unit/test_assets.rb +485 -155
- data/test/unit/test_async.rb +16 -37
- data/test/unit/test_authentication.rb +425 -457
- data/test/unit/test_boxes.rb +191 -191
- data/test/unit/test_changesets.rb +244 -254
- data/test/unit/test_config.rb +128 -142
- data/test/unit/test_content.rb +313 -359
- data/test/unit/test_content_inheritance.rb +29 -30
- data/test/unit/test_datamapper.rb +1205 -1080
- data/test/unit/test_datamapper_content.rb +49 -51
- data/test/unit/test_extensions.rb +23 -23
- data/test/unit/test_fields.rb +1488 -1180
- data/test/unit/test_formats.rb +158 -158
- data/test/unit/test_generators.rb +98 -40
- data/test/unit/test_helpers.rb +73 -76
- data/test/unit/test_image_size.rb +53 -22
- data/test/unit/test_images.rb +164 -165
- data/test/unit/test_layouts.rb +133 -122
- data/test/unit/test_logger.rb +14 -17
- data/test/unit/test_media.rb +69 -84
- data/test/unit/test_modifications.rb +513 -525
- data/test/unit/test_page.rb +462 -361
- data/test/unit/test_permissions.rb +379 -364
- data/test/unit/test_piece.rb +67 -75
- data/test/unit/test_plugins.rb +82 -89
- data/test/unit/test_prototype_set.rb +215 -216
- data/test/unit/test_prototypes.rb +114 -124
- data/test/unit/test_publishing.rb +252 -289
- data/test/unit/test_render.rb +167 -115
- data/test/unit/test_revisions.rb +436 -444
- data/test/unit/test_schema.rb +339 -309
- data/test/unit/test_search.rb +577 -574
- data/test/unit/test_serialisation.rb +136 -147
- data/test/unit/test_site.rb +252 -227
- data/test/unit/test_skeptick.rb +130 -0
- data/test/unit/test_storage.rb +46 -40
- data/test/unit/test_structure.rb +57 -66
- data/test/unit/test_styles.rb +104 -104
- data/test/unit/test_templates.rb +72 -57
- data/test/unit/test_type_hierarchy.rb +15 -16
- data/test/unit/test_visibility.rb +239 -257
- metadata +455 -326
- data/application/js/vendor/JS.Class-2.1.5/CHANGELOG +0 -283
- data/application/js/vendor/JS.Class-2.1.5/MIT-LICENSE +0 -30
- data/application/js/vendor/JS.Class-2.1.5/README +0 -30
- data/application/js/vendor/JS.Class-2.1.5/min/command.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/comparable.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/constant_scope.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/decorator.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/enumerable.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/forwardable.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/hash.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/linked_list.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/loader.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/method_chain.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/observable.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/package.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/proxy.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/ruby.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/set.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/stack_trace.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/state.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/stdlib.js +0 -16
- data/application/js/vendor/jquery-1.6.2.min.js +0 -18
- data/application/js/vendor/jquery-ui-1.8.16.custom.min.js +0 -791
- data/application/js/vendor/jquery-ui-1.8.9.custom.min.js +0 -415
- data/application/static/font/fontawesome-webfont-5c5c21100a346972a82c34c5e96ffcfe.ttf +0 -0
- data/application/static/select-arrow-6e7dd3745b00e934b0d7a3250c46558b.png +0 -0
- data/bin/limit-upload +0 -5
- data/bin/unlimit-upload +0 -3
- data/lib/spontaneous/asset/file.rb +0 -25
- data/lib/spontaneous/asset/source.rb +0 -28
- data/lib/spontaneous/image_size.rb +0 -123
- data/lib/spontaneous/output/assets/compression.rb +0 -58
- data/lib/spontaneous/output/assets.rb +0 -32
- data/lib/spontaneous/rack/around_back.rb +0 -20
- data/lib/spontaneous/rack/around_front.rb +0 -27
- data/lib/spontaneous/rack/around_preview.rb +0 -22
- data/lib/spontaneous/rack/assets.rb +0 -126
- data/lib/spontaneous/rack/authentication.rb +0 -20
- data/lib/spontaneous/rack/cookie_authentication.rb +0 -38
- data/lib/spontaneous/rack/helpers.rb +0 -52
- data/lib/spontaneous/rack/http.rb +0 -18
- data/lib/spontaneous/rack/media.rb +0 -30
- data/lib/spontaneous/rack/query_authentication.rb +0 -35
- data/lib/spontaneous/rack/reloader.rb +0 -45
- data/lib/spontaneous/rack/user_helpers.rb +0 -28
- /data/{README → application/js/field/markdown/text_command.js} +0 -0
- /data/application/js/vendor/{JS.Class-2.1.5/min/core.js → js.class-2.1.5.min.js} +0 -0
- /data/test/fixtures/assets/public1/css/{a.scss → a.css.scss} +0 -0
- /data/{lib/spontaneous/generators/site/public/css/site.scss → test/fixtures/assets/public1/x.css} +0 -0
- /data/{lib/spontaneous/generators/site/public/js/.empty_directory → test/fixtures/assets/public1/x.png} +0 -0
- /data/test/fixtures/assets/public2/css/{b.scss → b.css.scss} +0 -0
- /data/test/fixtures/assets/public2/js/{n.coffee → n.js.coffee} +0 -0
- /data/test/fixtures/back/{public → assets}/css/sass_include.scss +0 -0
- /data/test/fixtures/back/{public → assets}/css/sass_template.scss +0 -0
- /data/test/fixtures/back/{public → assets}/js/coffeescript.coffee +0 -0
- /data/{lib/spontaneous/generators/site/public/js/site.js → test/fixtures/templates/aliases/aa_alias.html.cut} +0 -0
data/test/unit/test_search.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require File.expand_path('../../test_helper', __FILE__)
|
4
4
|
|
5
|
-
|
5
|
+
describe "Search" do
|
6
6
|
|
7
7
|
# search should be defined by DSL
|
8
8
|
# DSL should
|
@@ -23,673 +23,676 @@ class SearchTest < MiniTest::Spec
|
|
23
23
|
#
|
24
24
|
# - Indexing is done by page
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
def self.startup
|
29
|
-
# make sure that S::Piece & S::Page are removed from the schema
|
30
|
-
# setup_site
|
31
|
-
# *ids = S::Page.schema_id, S::Piece.schema_id
|
32
|
-
# Object.const_set(:Site, Class.new(S::Site))
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.shutdown
|
36
|
-
# Object.send(:remove_const, :Site) rescue nil
|
37
|
-
end
|
38
|
-
|
39
|
-
def setup
|
26
|
+
before do
|
40
27
|
@site = setup_site
|
28
|
+
Content.delete
|
29
|
+
|
30
|
+
|
31
|
+
# class ::Piece < S::Piece; end
|
32
|
+
# class ::Page < S::Page; end
|
33
|
+
b = ::Page.box :pages
|
34
|
+
# instantiate box instance class to it gets added to schema
|
35
|
+
::Page.boxes.pages.instance_class.schema_id
|
36
|
+
|
37
|
+
class ::PageClass1 < ::Page; end
|
38
|
+
class ::PageClass2 < ::Page; end
|
39
|
+
class ::PageClass3 < ::PageClass1; end
|
40
|
+
class ::PageClass4 < ::PageClass2; end
|
41
|
+
class ::PageClass5 < ::PageClass3; end
|
42
|
+
class ::PageClass6 < ::PageClass5; end
|
43
|
+
|
44
|
+
class ::PieceClass1 < ::Piece; end
|
45
|
+
class ::PieceClass2 < ::Piece; end
|
46
|
+
class ::PieceClass3 < ::Piece; end
|
47
|
+
|
48
|
+
@all_page_classes = [::Page, ::PageClass1, ::PageClass2, ::PageClass3, ::PageClass4, ::PageClass5, ::PageClass6]
|
49
|
+
@all_piece_classes = [::Piece, ::PieceClass1, ::PieceClass2, ::PieceClass3]
|
50
|
+
@all_box_classes = [ ::Box, ::Page::PagesBox ]
|
51
|
+
@all_classes = @all_page_classes + @all_piece_classes + @all_box_classes
|
52
|
+
|
53
|
+
@root0 = ::Page.create(:uid => "root")
|
54
|
+
@page1 = ::PageClass1.create(:slug => "page1", :uid => "page1")
|
55
|
+
@root0.pages << @page1
|
56
|
+
@page2 = ::PageClass2.create(:slug => "page2", :uid => "page2")
|
57
|
+
@root0.pages << @page2
|
58
|
+
@page3 = ::PageClass3.create(:slug => "page3", :uid => "page3")
|
59
|
+
@root0.pages << @page3
|
60
|
+
@page4 = ::PageClass4.create(:slug => "page4", :uid => "page4")
|
61
|
+
@root0.pages << @page4
|
62
|
+
@page5 = ::PageClass5.create(:slug => "page5", :uid => "page5")
|
63
|
+
@root0.pages << @page5
|
64
|
+
@page6 = ::PageClass6.create(:slug => "page6", :uid => "page6")
|
65
|
+
@root0.pages << @page6
|
66
|
+
|
67
|
+
@page7 = ::PageClass1.create(:slug => "page7", :uid => "page7")
|
68
|
+
@page1.pages << @page7
|
69
|
+
@page8 = ::PageClass6.create(:slug => "page8", :uid => "page8")
|
70
|
+
@page1.pages << @page8
|
71
|
+
|
72
|
+
@page9 = ::PageClass1.create(:slug => "page9", :uid => "page9")
|
73
|
+
@page8.pages << @page9
|
74
|
+
@page10 = ::PageClass2.create(:slug => "page10", :uid => "page10")
|
75
|
+
@page8.pages << @page10
|
76
|
+
@page11 = ::PageClass3.create(:slug => "page11", :uid => "page11")
|
77
|
+
@page8.pages << @page11
|
78
|
+
@page12 = ::PageClass4.create(:slug => "page12", :uid => "page12")
|
79
|
+
@page8.pages << @page12
|
80
|
+
|
81
|
+
@all_pages = [@root0, @page1, @page2, @page3, @page4, @page5, @page6, @page7, @page8, @page9, @page10, @page11, @page12]
|
82
|
+
@all_pages.each { |page| page.save; page.reload }
|
41
83
|
end
|
42
84
|
|
43
|
-
|
85
|
+
after do
|
86
|
+
(@all_classes.map { |k| k.name.to_sym }).each { |klass|
|
87
|
+
Object.send(:remove_const, klass) rescue nil
|
88
|
+
} rescue nil
|
89
|
+
Content.delete
|
44
90
|
teardown_site
|
45
91
|
end
|
46
92
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
::
|
57
|
-
|
58
|
-
|
59
|
-
class ::PageClass2 < ::Page; end
|
60
|
-
class ::PageClass3 < ::PageClass1; end
|
61
|
-
class ::PageClass4 < ::PageClass2; end
|
62
|
-
class ::PageClass5 < ::PageClass3; end
|
63
|
-
class ::PageClass6 < ::PageClass5; end
|
64
|
-
|
65
|
-
class ::PieceClass1 < ::Piece; end
|
66
|
-
class ::PieceClass2 < ::Piece; end
|
67
|
-
class ::PieceClass3 < ::Piece; end
|
68
|
-
|
69
|
-
@all_page_classes = [::Page, ::PageClass1, ::PageClass2, ::PageClass3, ::PageClass4, ::PageClass5, ::PageClass6]
|
70
|
-
@all_piece_classes = [::Piece, ::PieceClass1, ::PieceClass2, ::PieceClass3]
|
71
|
-
@all_box_classes = [ ::Box, ::Page::PagesBox ]
|
72
|
-
@all_classes = @all_page_classes + @all_piece_classes + @all_box_classes
|
73
|
-
|
74
|
-
@root0 = ::Page.create(:uid => "root")
|
75
|
-
@page1 = ::PageClass1.create(:slug => "page1", :uid => "page1")
|
76
|
-
@root0.pages << @page1
|
77
|
-
@page2 = ::PageClass2.create(:slug => "page2", :uid => "page2")
|
78
|
-
@root0.pages << @page2
|
79
|
-
@page3 = ::PageClass3.create(:slug => "page3", :uid => "page3")
|
80
|
-
@root0.pages << @page3
|
81
|
-
@page4 = ::PageClass4.create(:slug => "page4", :uid => "page4")
|
82
|
-
@root0.pages << @page4
|
83
|
-
@page5 = ::PageClass5.create(:slug => "page5", :uid => "page5")
|
84
|
-
@root0.pages << @page5
|
85
|
-
@page6 = ::PageClass6.create(:slug => "page6", :uid => "page6")
|
86
|
-
@root0.pages << @page6
|
87
|
-
|
88
|
-
@page7 = ::PageClass1.create(:slug => "page7", :uid => "page7")
|
89
|
-
@page1.pages << @page7
|
90
|
-
@page8 = ::PageClass6.create(:slug => "page8", :uid => "page8")
|
91
|
-
@page1.pages << @page8
|
92
|
-
|
93
|
-
@page9 = ::PageClass1.create(:slug => "page9", :uid => "page9")
|
94
|
-
@page8.pages << @page9
|
95
|
-
@page10 = ::PageClass2.create(:slug => "page10", :uid => "page10")
|
96
|
-
@page8.pages << @page10
|
97
|
-
@page11 = ::PageClass3.create(:slug => "page11", :uid => "page11")
|
98
|
-
@page8.pages << @page11
|
99
|
-
@page12 = ::PageClass4.create(:slug => "page12", :uid => "page12")
|
100
|
-
@page8.pages << @page12
|
101
|
-
|
102
|
-
@all_pages = [@root0, @page1, @page2, @page3, @page4, @page5, @page6, @page7, @page8, @page9, @page10, @page11, @page12]
|
103
|
-
@all_pages.each { |page| page.save; page.reload }
|
104
|
-
end
|
105
|
-
|
106
|
-
teardown do
|
107
|
-
(@all_classes.map { |k| k.name.to_sym }).each { |klass|
|
108
|
-
Object.send(:remove_const, klass) rescue nil
|
109
|
-
} rescue nil
|
110
|
-
Content.delete
|
111
|
-
end
|
112
|
-
|
113
|
-
context "indexes" do
|
114
|
-
|
115
|
-
should "be retrievable by name" do
|
116
|
-
index = S::Site.index :arthur
|
117
|
-
S::Site.indexes[:arthur].must_be_instance_of Spontaneous::Search::Index
|
118
|
-
S::Site.indexes[:arthur].name.should == :arthur
|
119
|
-
S::Site.indexes[:arthur].should == index
|
120
|
-
end
|
93
|
+
describe "indexes" do
|
94
|
+
it "be retrievable by name" do
|
95
|
+
index = S::Site.index :arthur
|
96
|
+
S::Site.indexes[:arthur].must_be_instance_of Spontaneous::Search::Index
|
97
|
+
S::Site.indexes[:arthur].name.must_equal :arthur
|
98
|
+
S::Site.indexes[:arthur].must_equal index
|
99
|
+
end
|
100
|
+
|
101
|
+
it "default to indexing all content classes" do
|
102
|
+
index = S::Site.index :all
|
103
|
+
assert_has_elements (@all_classes), index.search_types
|
104
|
+
end
|
121
105
|
|
122
|
-
|
123
|
-
|
124
|
-
|
106
|
+
it "allow restriction to particular classes" do
|
107
|
+
index = S::Site.index :all do
|
108
|
+
include_types ::PageClass1, "PageClass2", :PageClass3
|
125
109
|
end
|
110
|
+
assert_has_elements [::PageClass1, ::PageClass2, ::PageClass3], index.search_types
|
111
|
+
end
|
126
112
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
end
|
131
|
-
assert_same_elements [::PageClass1, ::PageClass2, ::PageClass3], index.search_types
|
113
|
+
it "allow restriction to a class & its subclasses" do
|
114
|
+
index = S::Site.index :all do
|
115
|
+
include_types ">= PageClass1"
|
132
116
|
end
|
117
|
+
assert_has_elements [::PageClass1, ::PageClass3, ::PageClass5, ::PageClass6], index.search_types
|
118
|
+
end
|
133
119
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
end
|
138
|
-
assert_same_elements [::PageClass1, ::PageClass3, ::PageClass5, ::PageClass6], index.search_types
|
120
|
+
it "allow restriction to a class's subclasses" do
|
121
|
+
index = S::Site.index :all do
|
122
|
+
include_types "> PageClass1"
|
139
123
|
end
|
124
|
+
assert_has_elements [::PageClass3, ::PageClass5, ::PageClass6], index.search_types
|
125
|
+
end
|
140
126
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
end
|
145
|
-
assert_same_elements [::PageClass3, ::PageClass5, ::PageClass6], index.search_types
|
127
|
+
it "allow removal of particular classes" do
|
128
|
+
index = S::Site.index :all do
|
129
|
+
exclude_types ::PageClass1, "PageClass2"
|
146
130
|
end
|
131
|
+
assert_has_elements (@all_classes - [PageClass1, PageClass2]), index.search_types
|
132
|
+
end
|
147
133
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
end
|
152
|
-
assert_same_elements (@all_classes - [PageClass1, PageClass2]), index.search_types
|
134
|
+
it "allow removal of a class and its subclasses" do
|
135
|
+
index = S::Site.index :all do
|
136
|
+
exclude_types ">= PageClass1", PieceClass1
|
153
137
|
end
|
138
|
+
assert_has_elements (@all_classes - [::PageClass1, ::PageClass3, ::PageClass5, ::PageClass6, PieceClass1]), index.search_types
|
139
|
+
end
|
154
140
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
end
|
159
|
-
assert_same_elements (@all_classes - [::PageClass1, ::PageClass3, ::PageClass5, ::PageClass6, PieceClass1]), index.search_types
|
141
|
+
it "allow removal of a class's subclasses" do
|
142
|
+
index = S::Site.index :all do
|
143
|
+
exclude_types "> PageClass1"
|
160
144
|
end
|
145
|
+
assert_has_elements (@all_classes - [::PageClass3, ::PageClass5, ::PageClass6]), index.search_types
|
146
|
+
end
|
161
147
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
assert_same_elements (@all_classes - [::PageClass3, ::PageClass5, ::PageClass6]), index.search_types
|
148
|
+
it "default to including all content" do
|
149
|
+
index = S::Site.index :all
|
150
|
+
@all_pages.each do |page|
|
151
|
+
assert index.include?(page)
|
167
152
|
end
|
153
|
+
end
|
168
154
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
155
|
+
it "allow restriction to a set of specific pages" do
|
156
|
+
id = @root0.id
|
157
|
+
path = @page8.path
|
158
|
+
index = S::Site.index :all do
|
159
|
+
include_pages id, "$page11", path
|
174
160
|
end
|
175
161
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
index = S::Site.index :all do
|
180
|
-
include_pages id, "#page11", path
|
181
|
-
end
|
162
|
+
included = @all_pages.map{ |page| index.include?(page) }
|
163
|
+
included.must_equal [true,false,false,false,false,false,false,false,true,false,false,true,false]
|
164
|
+
end
|
182
165
|
|
183
|
-
|
184
|
-
|
166
|
+
it "allow restriction to a page and its children" do
|
167
|
+
index = S::Site.index :all do
|
168
|
+
include_pages ">= $page8"
|
185
169
|
end
|
186
170
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
end
|
171
|
+
included = @all_pages.map{ |page| index.include?(page) }
|
172
|
+
included.must_equal [false,false,false,false,false,false,false,false,true,true,true,true,true]
|
173
|
+
end
|
191
174
|
|
192
|
-
|
193
|
-
|
175
|
+
it "allow restriction to a page's children" do
|
176
|
+
index = S::Site.index :all do
|
177
|
+
include_pages "> $page8"
|
194
178
|
end
|
195
179
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
end
|
180
|
+
included = @all_pages.map{ |page| index.include?(page) }
|
181
|
+
included.must_equal [false,false,false,false,false,false,false,false,false,true,true,true,true]
|
182
|
+
end
|
200
183
|
|
201
|
-
|
202
|
-
|
184
|
+
it "allow removal of specific pages" do
|
185
|
+
index = S::Site.index :all do
|
186
|
+
exclude_pages "$page8", "/page1"
|
203
187
|
end
|
204
188
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
end
|
189
|
+
included = @all_pages.map{ |page| index.include?(page) }
|
190
|
+
included.must_equal [true,false,true,true,true,true,true,true,false,true,true,true,true]
|
191
|
+
end
|
209
192
|
|
210
|
-
|
211
|
-
|
193
|
+
it "allow removal of a page and its children" do
|
194
|
+
index = S::Site.index :all do
|
195
|
+
exclude_pages "/page1", ">= $page8"
|
212
196
|
end
|
213
197
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
end
|
198
|
+
included = @all_pages.map{ |page| index.include?(page) }
|
199
|
+
included.must_equal [true,false,true,true,true,true,true,true,false,false,false,false,false]
|
200
|
+
end
|
218
201
|
|
219
|
-
|
220
|
-
|
202
|
+
it "allow removal of a page's children" do
|
203
|
+
index = S::Site.index :all do
|
204
|
+
exclude_pages "/page1", "> $page8"
|
221
205
|
end
|
222
206
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
end
|
207
|
+
included = @all_pages.map{ |page| index.include?(page) }
|
208
|
+
included.must_equal [true,false,true,true,true,true,true,true,true,false,false,false,false]
|
209
|
+
end
|
227
210
|
|
228
|
-
|
229
|
-
|
211
|
+
it "allow multiple, mixed, page restrictions" do
|
212
|
+
index = S::Site.index :all do
|
213
|
+
include_pages "$page1", "> $page8"
|
230
214
|
end
|
231
215
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
end
|
216
|
+
included = @all_pages.map{ |page| index.include?(page) }
|
217
|
+
included.must_equal [false,true,false,false,false,false,false,false,false,true,true,true,true]
|
218
|
+
end
|
236
219
|
|
237
|
-
|
238
|
-
|
220
|
+
it "allow combining of class and page restrictions" do
|
221
|
+
index = S::Site.index :all do
|
222
|
+
exclude_types PageClass3, PageClass4
|
223
|
+
include_pages "$page1", "> $page8"
|
224
|
+
exclude_pages "$page10"
|
239
225
|
end
|
226
|
+
included = @all_pages.map{ |page| index.include?(page) }
|
227
|
+
included.must_equal [false,true,false,false,false,false,false,false,false,true,false,false,false]
|
228
|
+
end
|
229
|
+
end
|
240
230
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
231
|
+
describe "Fields definitions" do
|
232
|
+
# Inclusion of field in indexes.
|
233
|
+
# Default is not to include field
|
234
|
+
# By adding the following clause:
|
235
|
+
#
|
236
|
+
# field :title, :index => true
|
237
|
+
#
|
238
|
+
# you include the :title field in all indexes with a search weight of 1. this is equivalent to the following:
|
239
|
+
#
|
240
|
+
# field :title, :index => { :name => :*, :weight => 1, :group => nil }
|
241
|
+
#
|
242
|
+
# If you only want to include this field in a specific index, then you do the following:
|
243
|
+
#
|
244
|
+
# field :title, :index => :tags
|
245
|
+
#
|
246
|
+
# this is equivalent to
|
247
|
+
#
|
248
|
+
# field :title, :index => { :name => :tags, :weight => 1, :group => nil }
|
249
|
+
#
|
250
|
+
# or if you want to include it into more than one index:
|
251
|
+
#
|
252
|
+
# field :title, :index => [:tags, :content]
|
253
|
+
#
|
254
|
+
# this is equivalent to
|
255
|
+
#
|
256
|
+
# field :title, :index => [
|
257
|
+
# { :name => :tags, :weight => 1, :group => nil },
|
258
|
+
# { :name => :content, :weight => 1, :group => nil }]
|
259
|
+
#
|
260
|
+
# Groups:
|
261
|
+
#
|
262
|
+
# Normally field values are grouped by content types. Indexes are generated from a page by iterating through
|
263
|
+
# all it's pieces and creating a single aggregate value for each field of each type found
|
264
|
+
#
|
265
|
+
# Groups are a way of joining disparate fields from different types into a single, addressable/searchable
|
266
|
+
# index
|
267
|
+
#
|
268
|
+
# weight:
|
269
|
+
#
|
270
|
+
# weight defines how much priority is given to a field. I.e. if your search term occurs in a field
|
271
|
+
# with a high weight value then it will apear higher in the results list than in a page where the
|
272
|
+
# term appears in a lower weight field
|
273
|
+
#
|
274
|
+
# :store = 0 : store but don't index (makes value available to results lister without loading page from db)
|
275
|
+
# :normal = 1 : default weight
|
276
|
+
# :high = 2 : high weight
|
277
|
+
# :higher = 4 : higher weight
|
278
|
+
# :highest = 8 : higest
|
279
|
+
#
|
280
|
+
# actual weight are powers of 10: 10, 100, 10000, 100000000 (unless this is different from Ferret)
|
281
|
+
#
|
282
|
+
#
|
283
|
+
before do
|
284
|
+
@index1 = S::Site.index(:one)
|
285
|
+
@index2 = S::Site.index(:two)
|
286
|
+
@index3 = S::Site.index(:three) do
|
287
|
+
include_types PageClass1
|
249
288
|
end
|
250
289
|
end
|
251
290
|
|
252
|
-
|
253
|
-
|
254
|
-
# Default is not to include field
|
255
|
-
# By adding the following clause:
|
256
|
-
#
|
257
|
-
# field :title, :index => true
|
258
|
-
#
|
259
|
-
# you include the :title field in all indexes with a search weight of 1. this is equivalent to the following:
|
260
|
-
#
|
261
|
-
# field :title, :index => { :name => :*, :weight => 1, :group => nil }
|
262
|
-
#
|
263
|
-
# If you only want to include this field in a specific index, then you do the following:
|
264
|
-
#
|
265
|
-
# field :title, :index => :tags
|
266
|
-
#
|
267
|
-
# this is equivalent to
|
268
|
-
#
|
269
|
-
# field :title, :index => { :name => :tags, :weight => 1, :group => nil }
|
270
|
-
#
|
271
|
-
# or if you want to include it into more than one index:
|
272
|
-
#
|
273
|
-
# field :title, :index => [:tags, :content]
|
274
|
-
#
|
275
|
-
# this is equivalent to
|
276
|
-
#
|
277
|
-
# field :title, :index => [
|
278
|
-
# { :name => :tags, :weight => 1, :group => nil },
|
279
|
-
# { :name => :content, :weight => 1, :group => nil }]
|
280
|
-
#
|
281
|
-
# Groups:
|
282
|
-
#
|
283
|
-
# Normally field values are grouped by content types. Indexes are generated from a page by iterating through
|
284
|
-
# all it's pieces and creating a single aggregate value for each field of each type found
|
285
|
-
#
|
286
|
-
# Groups are a way of joining disparate fields from different types into a single, addressable/searchable
|
287
|
-
# index
|
288
|
-
#
|
289
|
-
# weight:
|
290
|
-
#
|
291
|
-
# weight defines how much priority is given to a field. I.e. if your search term occurs in a field
|
292
|
-
# with a high weight value then it will apear higher in the results list than in a page where the
|
293
|
-
# term appears in a lower weight field
|
294
|
-
#
|
295
|
-
# :store = 0 : store but don't index (makes value available to results lister without loading page from db)
|
296
|
-
# :normal = 1 : default weight
|
297
|
-
# :high = 2 : high weight
|
298
|
-
# :higher = 4 : higher weight
|
299
|
-
# :highest = 8 : higest
|
300
|
-
#
|
301
|
-
# actual weight are powers of 10: 10, 100, 10000, 100000000 (unless this is different from Ferret)
|
302
|
-
#
|
303
|
-
#
|
304
|
-
setup do
|
305
|
-
@index1 = S::Site.index(:one)
|
306
|
-
@index2 = S::Site.index(:two)
|
307
|
-
@index3 = S::Site.index(:three) do
|
308
|
-
include_types PageClass1
|
309
|
-
end
|
310
|
-
end
|
291
|
+
after do
|
292
|
+
end
|
311
293
|
|
312
|
-
|
313
|
-
|
294
|
+
it "be included in all indexes if :index is set to true" do
|
295
|
+
prototype_a = PageClass1.field :a, :index => true
|
296
|
+
assert prototype_a.in_index?(@index1)
|
297
|
+
assert prototype_a.in_index?(@index2)
|
298
|
+
assert prototype_a.in_index?(@index3)
|
299
|
+
end
|
314
300
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
301
|
+
it "must be included in all indexes with if passed a hash with no name key" do
|
302
|
+
prototype_a = PageClass1.field :a, :index => {weight: 16}
|
303
|
+
assert prototype_a.in_index?(@index1)
|
304
|
+
assert prototype_a.in_index?(@index2)
|
305
|
+
assert prototype_a.in_index?(@index3)
|
306
|
+
[:one, :two, :three].each do |name|
|
307
|
+
index = S::Site.indexes[name]
|
308
|
+
index.fields[PageClass1.fields[:a].schema_id.to_s][:weight].must_equal 16
|
320
309
|
end
|
310
|
+
end
|
321
311
|
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
312
|
+
it "be included in indexes referenced by name" do
|
313
|
+
prototype_a = PageClass1.field :a, :index => [:one, :two]
|
314
|
+
assert prototype_a.in_index?(@index1)
|
315
|
+
assert prototype_a.in_index?(@index2)
|
316
|
+
refute prototype_a.in_index?(@index3)
|
317
|
+
end
|
328
318
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
319
|
+
it "be included in indexes referenced as hash" do
|
320
|
+
prototype_a = PageClass1.field :a, :index => {:name => :two}
|
321
|
+
refute prototype_a.in_index?(@index1)
|
322
|
+
assert prototype_a.in_index?(@index2)
|
323
|
+
refute prototype_a.in_index?(@index3)
|
324
|
+
end
|
335
325
|
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
326
|
+
it "be included in indexes listed in hash" do
|
327
|
+
prototype_a = PageClass1.field :a, :index => [{:name => :one}, {:name => :two}]
|
328
|
+
assert prototype_a.in_index?(@index1)
|
329
|
+
assert prototype_a.in_index?(@index2)
|
330
|
+
refute prototype_a.in_index?(@index3)
|
331
|
+
end
|
342
332
|
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
333
|
+
it "return the field's schema id as its index name by default" do
|
334
|
+
prototype_a = PageClass1.field :a, :index => [{:name => :one}, {:name => :two, :group => :a}]
|
335
|
+
prototype_a.index_id(@index1).must_equal prototype_a.schema_id.to_s
|
336
|
+
prototype_a.index_id(@index2).must_equal :a
|
337
|
+
end
|
348
338
|
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
end
|
339
|
+
it "produce a field list in a xapian-fu compatible format" do
|
340
|
+
a = PageClass1.field :a, :index => [{:name => :one, :weight => :store},
|
341
|
+
{:name => :two, :group => :a, :weight => 2}]
|
342
|
+
b = PageClass2.field :b, :index => :one
|
343
|
+
c = ::Piece.field :c, :index => [{:name => :one, :weight => 4}, {:name => :two, :group => :a}]
|
344
|
+
d = ::Piece.field :d, :index => :three
|
345
|
+
e = ::PageClass1.field :e, :index => :three
|
346
|
+
f = ::PageClass2.field :f, :index => :three
|
347
|
+
g = ::Piece.field :g, :index => {:weight => :highest}
|
348
|
+
|
349
|
+
h = ::PageClass1.boxes.pages.instance_class.field :h, :index => :two
|
350
|
+
|
351
|
+
S::Site.indexes[:one].fields.must_equal({
|
352
|
+
a.schema_id.to_s => { :type => String, :store => true, :index => false},
|
353
|
+
b.schema_id.to_s => { :type => String, :store => true, :weight => 1, :index => true},
|
354
|
+
c.schema_id.to_s => { :type => String, :store => true, :weight => 4, :index => true},
|
355
|
+
g.schema_id.to_s => { :type => String, :store => true, :weight => 16, :index => true}
|
356
|
+
})
|
357
|
+
|
358
|
+
S::Site.indexes[:two].fields.must_equal({
|
359
|
+
:a => { :type => String, :store => true, :weight => 2, :index => true},
|
360
|
+
g.schema_id.to_s => { :type => String, :store => true, :weight => 16, :index => true},
|
361
|
+
h.schema_id.to_s => { :type => String, :store => true, :weight => 1, :index => true}
|
362
|
+
})
|
363
|
+
|
364
|
+
S::Site.indexes[:three].fields.must_equal({
|
365
|
+
e.schema_id.to_s => { :type => String, :store => true, :weight => 1, :index => true}
|
366
|
+
})
|
378
367
|
end
|
368
|
+
end
|
379
369
|
|
380
|
-
|
381
|
-
|
382
|
-
|
370
|
+
describe "indexing" do
|
371
|
+
before do
|
372
|
+
@revision = 99
|
383
373
|
|
384
|
-
|
385
|
-
|
386
|
-
end
|
387
|
-
@index2 = S::Site.index :two
|
388
|
-
|
389
|
-
@a = PageClass1.field :a, :index => true
|
390
|
-
@b = PageClass2.field :b, :index => true
|
391
|
-
@c = PageClass3.field :c, :index => true
|
392
|
-
@d = PageClass4.field :d, :index => true
|
393
|
-
@e = PageClass5.field :e, :index => true
|
394
|
-
@f = PageClass6.field :f, :index => true
|
395
|
-
@g = PieceClass1.field :g, :index => true
|
396
|
-
@h = PieceClass2.field :h, :index => true
|
397
|
-
@i = PieceClass3.field :i, :index => {:group => :i}
|
398
|
-
@j = PieceClass3.field :j, :index => {:group => :i}
|
399
|
-
@k = PieceClass3.field :k
|
400
|
-
|
401
|
-
@l = ::PageClass1.boxes.pages.instance_class.field :l, :index => true
|
402
|
-
|
403
|
-
@page1.a = "a value 1"
|
404
|
-
@page1.pages.first.a = "a value 2"
|
405
|
-
@page1.pages.l = "l value 1"
|
406
|
-
|
407
|
-
@piece1 = PieceClass1.new(:g => "g value 1")
|
408
|
-
@page1.pages << @piece1
|
409
|
-
@piece2 = PieceClass1.new(:g => "g value 2")
|
410
|
-
@page1.pages << @piece2
|
411
|
-
@piece3 = PieceClass1.new(:g => "g value 3")
|
412
|
-
@page1.pages << @piece3
|
413
|
-
@piece4 = PieceClass2.new(:h => "h value 1")
|
414
|
-
@page1.pages << @piece4
|
415
|
-
@piece5 = PieceClass2.new(:h => "h value 2")
|
416
|
-
@page1.pages << @piece5
|
417
|
-
@piece6 = PieceClass3.new(:i => "i value 1", :j => "j value 1", :k => "k value 1")
|
418
|
-
@page1.pages << @piece6
|
419
|
-
@piece7 = PieceClass3.new(:i => "i value 2", :j => "j value 2", :k => "k value 2")
|
420
|
-
@page1.pages << @piece7
|
421
|
-
|
422
|
-
@page2.b = "b value 1"
|
423
|
-
@page3.c = "c value 1"
|
424
|
-
@page1.save
|
374
|
+
@index1 = S::Site.index :one do
|
375
|
+
exclude_types PageClass3
|
425
376
|
end
|
377
|
+
@index2 = S::Site.index :two
|
426
378
|
|
427
|
-
|
428
|
-
|
379
|
+
@a = PageClass1.field :a, :index => true
|
380
|
+
@b = PageClass2.field :b, :index => true
|
381
|
+
@c = PageClass3.field :c, :index => true
|
382
|
+
@d = PageClass4.field :d, :index => true
|
383
|
+
@e = PageClass5.field :e, :index => true
|
384
|
+
@f = PageClass6.field :f, :index => true
|
385
|
+
@g = PieceClass1.field :g, :index => true
|
386
|
+
@h = PieceClass2.field :h, :index => true
|
387
|
+
@i = PieceClass3.field :i, :index => {:group => :i}
|
388
|
+
@j = PieceClass3.field :j, :index => {:group => :i}
|
389
|
+
@k = PieceClass3.field :k
|
429
390
|
|
430
|
-
|
431
|
-
@page1.a.expects(:indexable_value).returns("(a value 1)")
|
432
|
-
@index1.indexable_content(@page1).should == {
|
433
|
-
:id => @page1.id,
|
434
|
-
@a.schema_id.to_s => "(a value 1)",
|
435
|
-
@g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
|
436
|
-
@h.schema_id.to_s => "h value 1\nh value 2",
|
437
|
-
:i => "i value 1\nj value 1\ni value 2\nj value 2",
|
438
|
-
@l.schema_id.to_s => "l value 1",
|
439
|
-
}
|
440
|
-
end
|
391
|
+
@l = ::PageClass1.boxes.pages.instance_class.field :l, :index => true
|
441
392
|
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
393
|
+
@page1.a = "a value 1"
|
394
|
+
@page1.pages.first.a = "a value 2"
|
395
|
+
@page1.pages.l = "l value 1"
|
396
|
+
|
397
|
+
@piece1 = PieceClass1.new(:g => "g value 1")
|
398
|
+
@page1.pages << @piece1
|
399
|
+
@piece2 = PieceClass1.new(:g => "g value 2")
|
400
|
+
@page1.pages << @piece2
|
401
|
+
@piece3 = PieceClass1.new(:g => "g value 3")
|
402
|
+
@page1.pages << @piece3
|
403
|
+
@piece4 = PieceClass2.new(:h => "h value 1")
|
404
|
+
@page1.pages << @piece4
|
405
|
+
@piece5 = PieceClass2.new(:h => "h value 2")
|
406
|
+
@page1.pages << @piece5
|
407
|
+
@piece6 = PieceClass3.new(:i => "i value 1", :j => "j value 1", :k => "k value 1")
|
408
|
+
@page1.pages << @piece6
|
409
|
+
@piece7 = PieceClass3.new(:i => "i value 2", :j => "j value 2", :k => "k value 2")
|
410
|
+
@page1.pages << @piece7
|
411
|
+
|
412
|
+
@page2.b = "b value 1"
|
413
|
+
@page3.c = "c value 1"
|
414
|
+
@page1.save
|
415
|
+
end
|
446
416
|
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
417
|
+
after do
|
418
|
+
end
|
419
|
+
|
420
|
+
it "correctly extract content from pages" do
|
421
|
+
@page1.a.expects(:indexable_value).returns("(a value 1)")
|
422
|
+
@index1.indexable_content(@page1).must_equal({
|
423
|
+
:id => @page1.id,
|
424
|
+
@a.schema_id.to_s => "(a value 1)",
|
425
|
+
@g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
|
426
|
+
@h.schema_id.to_s => "h value 1\nh value 2",
|
427
|
+
:i => "i value 1\nj value 1\ni value 2\nj value 2",
|
428
|
+
@l.schema_id.to_s => "l value 1",
|
429
|
+
})
|
430
|
+
end
|
431
|
+
|
432
|
+
it "only include specified pieces" do
|
433
|
+
index = S::Site.index :four do
|
434
|
+
include_types PageClass1, PieceClass1
|
452
435
|
end
|
453
436
|
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
437
|
+
index.indexable_content(@page1).must_equal({
|
438
|
+
:id => @page1.id,
|
439
|
+
@a.schema_id.to_s => "a value 1",
|
440
|
+
@g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
|
441
|
+
})
|
442
|
+
end
|
443
|
+
|
444
|
+
it "allow for page types to append their own custom indexable values" do
|
445
|
+
index = S::Site.index :four do
|
446
|
+
include_types PageClass1, PieceClass1
|
447
|
+
end
|
448
|
+
class ::PageClass1
|
449
|
+
def additional_search_values
|
450
|
+
{ "search_key1" => "value 1",
|
451
|
+
"search_key2" => "value 2" }
|
463
452
|
end
|
464
|
-
index.indexable_content(@page1).should == {
|
465
|
-
:id => @page1.id,
|
466
|
-
@a.schema_id.to_s => "a value 1",
|
467
|
-
@g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
|
468
|
-
"search_key1" => "value 1",
|
469
|
-
"search_key2" => "value 2"
|
470
|
-
}
|
471
453
|
end
|
454
|
+
index.indexable_content(@page1).must_equal({
|
455
|
+
:id => @page1.id,
|
456
|
+
@a.schema_id.to_s => "a value 1",
|
457
|
+
@g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
|
458
|
+
"search_key1" => "value 1",
|
459
|
+
"search_key2" => "value 2"
|
460
|
+
})
|
461
|
+
end
|
472
462
|
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
463
|
+
it "deal with arrays of additional search index values" do
|
464
|
+
index = S::Site.index :four do
|
465
|
+
include_types PageClass1, PieceClass1
|
466
|
+
end
|
467
|
+
class ::PageClass1
|
468
|
+
def additional_search_values
|
469
|
+
[ { "search_key1" => "value 1",
|
470
|
+
"search_key2" => "value 2" },
|
481
471
|
{ "search_key1" => "value 3",
|
482
472
|
"search_key2" => "value 4" } ]
|
483
|
-
end
|
484
473
|
end
|
485
|
-
index.indexable_content(@page1).should == {
|
486
|
-
:id => @page1.id,
|
487
|
-
@a.schema_id.to_s => "a value 1",
|
488
|
-
@g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
|
489
|
-
"search_key1" => "value 1\nvalue 3",
|
490
|
-
"search_key2" => "value 2\nvalue 4"
|
491
|
-
}
|
492
474
|
end
|
475
|
+
index.indexable_content(@page1).must_equal({
|
476
|
+
:id => @page1.id,
|
477
|
+
@a.schema_id.to_s => "a value 1",
|
478
|
+
@g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
|
479
|
+
"search_key1" => "value 1\nvalue 3",
|
480
|
+
"search_key2" => "value 2\nvalue 4"
|
481
|
+
})
|
482
|
+
end
|
493
483
|
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
end
|
498
|
-
class ::PieceClass1
|
499
|
-
def additional_search_values
|
500
|
-
{ "search_key3" => "value 3",
|
501
|
-
"search_key4" => "value 4" }
|
502
|
-
end
|
503
|
-
end
|
504
|
-
index.indexable_content(@page1).should == {
|
505
|
-
:id => @page1.id,
|
506
|
-
@a.schema_id.to_s => "a value 1",
|
507
|
-
@g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
|
508
|
-
"search_key3" => "value 3\nvalue 3\nvalue 3",
|
509
|
-
"search_key4" => "value 4\nvalue 4\nvalue 4"
|
510
|
-
}
|
484
|
+
it "allow for pieces to append their own custom indexable values" do
|
485
|
+
index = S::Site.index :four do
|
486
|
+
include_types PageClass1, PieceClass1
|
511
487
|
end
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
mset.stubs(:matches).returns([])
|
518
|
-
xapian = mock()
|
519
|
-
xapian.expects(:<<).with(@index1.indexable_content(@page1))
|
520
|
-
xapian.expects(:search).with('"value 2"', {}).returns(XapianFu::ResultSet.new(:mset => mset))
|
521
|
-
xapian.expects(:flush)
|
522
|
-
|
523
|
-
XapianFu::XapianDb.expects(:new).with(has_entries({
|
524
|
-
:dir => db_path,
|
525
|
-
:create => true,
|
526
|
-
:overwrite => true,
|
527
|
-
:language => :english,
|
528
|
-
:fields => @index1.fields,
|
529
|
-
:spelling => true
|
530
|
-
})).returns(xapian)
|
531
|
-
|
532
|
-
db = @index1.create_db(@revision)
|
533
|
-
assert File.directory?(db_path)
|
534
|
-
db << @page1
|
535
|
-
db << @page3
|
536
|
-
db.close
|
537
|
-
db.search('"value 2"')
|
538
|
-
FileUtils.rm_r(db_path)
|
488
|
+
class ::PieceClass1
|
489
|
+
def additional_search_values
|
490
|
+
{ "search_key3" => "value 3",
|
491
|
+
"search_key4" => "value 4" }
|
492
|
+
end
|
539
493
|
end
|
494
|
+
index.indexable_content(@page1).must_equal({
|
495
|
+
:id => @page1.id,
|
496
|
+
@a.schema_id.to_s => "a value 1",
|
497
|
+
@g.schema_id.to_s => "g value 1\ng value 2\ng value 3",
|
498
|
+
"search_key3" => "value 3\nvalue 3\nvalue 3",
|
499
|
+
"search_key4" => "value 4\nvalue 4\nvalue 4"
|
500
|
+
})
|
501
|
+
end
|
540
502
|
|
541
|
-
|
542
|
-
|
503
|
+
it "create database in the right directory" do
|
504
|
+
db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
|
505
|
+
Site.stubs(:published_revision).returns(@revision)
|
506
|
+
mset = mock()
|
507
|
+
mset.stubs(:matches).returns([])
|
508
|
+
xapian = mock()
|
509
|
+
xapian.expects(:<<).with(@index1.indexable_content(@page1))
|
510
|
+
xapian.expects(:search).with('"value 2"', {}).returns(XapianFu::ResultSet.new(:mset => mset))
|
511
|
+
xapian.expects(:flush)
|
512
|
+
|
513
|
+
XapianFu::XapianDb.expects(:new).with(has_entries({
|
514
|
+
:dir => db_path,
|
515
|
+
:create => true,
|
516
|
+
:overwrite => true,
|
517
|
+
:language => :english,
|
518
|
+
:fields => @index1.fields,
|
519
|
+
:spelling => true
|
520
|
+
})).returns(xapian)
|
521
|
+
|
522
|
+
db = @index1.create_db(@revision)
|
523
|
+
assert File.directory?(db_path)
|
524
|
+
db << @page1
|
525
|
+
db << @page3
|
526
|
+
db.close
|
527
|
+
db.search('"value 2"')
|
528
|
+
FileUtils.rm_r(db_path)
|
529
|
+
end
|
543
530
|
|
544
|
-
|
545
|
-
|
546
|
-
end
|
531
|
+
it "pass on index configuration to the xapian db" do
|
532
|
+
db_path = @site.revision_dir(@revision) / 'indexes' / 'name'
|
547
533
|
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
:overwrite => true,
|
552
|
-
:language => :italian,
|
553
|
-
:fields => index.fields,
|
554
|
-
:spelling => true
|
555
|
-
}))
|
556
|
-
|
557
|
-
db = index.create_db(@revision)
|
558
|
-
|
559
|
-
index = Site.index :name do
|
560
|
-
language :french
|
561
|
-
stopper false
|
562
|
-
stemmer false
|
563
|
-
end
|
534
|
+
index = Site.index :name do
|
535
|
+
language :italian
|
536
|
+
end
|
564
537
|
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
:spelling => true
|
574
|
-
}))
|
538
|
+
XapianFu::XapianDb.expects(:new).with(has_entries({
|
539
|
+
:dir => db_path,
|
540
|
+
:create => true,
|
541
|
+
:overwrite => true,
|
542
|
+
:language => :italian,
|
543
|
+
:fields => index.fields,
|
544
|
+
:spelling => true
|
545
|
+
}))
|
575
546
|
|
576
|
-
|
547
|
+
db = index.create_db(@revision)
|
577
548
|
|
578
|
-
|
549
|
+
index = Site.index :name do
|
550
|
+
language :french
|
551
|
+
stopper false
|
552
|
+
stemmer false
|
579
553
|
end
|
580
554
|
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
results.must_be_instance_of S::Search::Results
|
592
|
-
results.each do |result|
|
593
|
-
result.class.should < Content::Page
|
594
|
-
end
|
555
|
+
XapianFu::XapianDb.expects(:new).with(has_entries({
|
556
|
+
:dir => db_path,
|
557
|
+
:create => true,
|
558
|
+
:overwrite => true,
|
559
|
+
:language => :french,
|
560
|
+
:stemmer => false,
|
561
|
+
:stopper => false,
|
562
|
+
:fields => index.fields,
|
563
|
+
:spelling => true
|
564
|
+
}))
|
595
565
|
|
596
|
-
|
597
|
-
results.current_page.should == 1
|
598
|
-
results.per_page.should == 1
|
599
|
-
results.total_pages.should == 2
|
600
|
-
results.next_page.should == 2
|
601
|
-
results.offset.should == 0
|
602
|
-
results.previous_page.should == nil
|
603
|
-
results.total_entries.should == 2
|
566
|
+
db = index.create_db(@revision)
|
604
567
|
|
605
|
-
|
606
|
-
|
607
|
-
results.total_entries.should == 0
|
568
|
+
FileUtils.rm_r(db_path)
|
569
|
+
end
|
608
570
|
|
609
|
-
|
610
|
-
|
611
|
-
|
571
|
+
it "return (reasonable) results to searches" do
|
572
|
+
db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
|
573
|
+
S::Site.stubs(:published_revision).returns(@revision)
|
574
|
+
db = @index1.create_db(@revision)
|
575
|
+
db << @page1
|
576
|
+
db << @page2
|
577
|
+
db << @page3
|
578
|
+
db.close
|
579
|
+
|
580
|
+
results = @index1.search('+valeu', :limit => 1, :autocorrect => true)
|
581
|
+
results.must_be_instance_of S::Search::Results
|
582
|
+
results.each do |result|
|
583
|
+
result.class.must_be :<, Content::Page
|
584
|
+
end
|
585
|
+
|
586
|
+
results.corrected_query.must_equal '+value'
|
587
|
+
results.current_page.must_equal 1
|
588
|
+
results.per_page.must_equal 1
|
589
|
+
results.total_pages.must_equal 2
|
590
|
+
results.next_page.must_equal 2
|
591
|
+
results.offset.must_equal 0
|
592
|
+
results.previous_page.must_equal nil
|
593
|
+
results.total_entries.must_equal 2
|
594
|
+
|
595
|
+
results = @index1.search('valeu', :limit => 1, :autocorrect => false)
|
596
|
+
results.corrected_query.must_equal 'value'
|
597
|
+
results.total_entries.must_equal 0
|
598
|
+
|
599
|
+
results = @index1.search('value', :limit => 1)
|
600
|
+
results.corrected_query.must_equal ''
|
601
|
+
results.total_entries.must_equal 2
|
602
|
+
|
603
|
+
FileUtils.rm_r(db_path)
|
604
|
+
end
|
612
605
|
|
613
|
-
|
614
|
-
|
606
|
+
it "returns pages based on the contents of their boxes" do
|
607
|
+
db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
|
608
|
+
S::Site.stubs(:published_revision).returns(@revision)
|
609
|
+
db = @index1.create_db(@revision)
|
610
|
+
db << @page1
|
611
|
+
db << @page2
|
612
|
+
db << @page3
|
613
|
+
db.close
|
614
|
+
|
615
|
+
results = @index1.search('h value')
|
616
|
+
results.to_a.first.id.must_equal @page1.id
|
617
|
+
end
|
615
618
|
|
616
|
-
should "respect weighting factors given to fields" do
|
617
|
-
db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
|
618
|
-
S::Site.stubs(:published_revision).returns(@revision)
|
619
|
-
db = @index1.create_db(@revision)
|
620
|
-
@w = PieceClass1.field :w, :index => { :weight => 100 }
|
621
|
-
@page1.pages << PieceClass1.new(:w => "findme")
|
622
|
-
@page2.pages << PieceClass2.new(:h => "findme findme")
|
623
|
-
@page2.pages << PieceClass2.new(:h => "findme findme")
|
624
|
-
@page5.pages << PieceClass2.new(:h => "findme")
|
625
|
-
@page5.pages << PieceClass2.new(:h => "findme")
|
626
|
-
|
627
|
-
@page1.save
|
628
|
-
@page2.save
|
629
|
-
@page5.save
|
630
|
-
db << @page1
|
631
|
-
db << @page2
|
632
|
-
db << @page5
|
633
|
-
db.close
|
634
|
-
results = @index1.search('findme', :limit => 5)
|
635
|
-
results.map(&:id).should == [@page1.id, @page2.id, @page5.id]
|
636
|
-
end
|
637
619
|
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
db.close
|
660
|
-
results = index.search('findme', :limit => 5)
|
661
|
-
results.map(&:id).should == [@page2.id, @page5.id, @page1.id]
|
662
|
-
end
|
620
|
+
it "respect weighting factors given to fields" do
|
621
|
+
db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
|
622
|
+
S::Site.stubs(:published_revision).returns(@revision)
|
623
|
+
db = @index1.create_db(@revision)
|
624
|
+
@w = PieceClass1.field :w, :index => { :weight => 100 }
|
625
|
+
@page1.pages << PieceClass1.new(:w => "findme")
|
626
|
+
@page2.pages << PieceClass2.new(:h => "findme findme")
|
627
|
+
@page2.pages << PieceClass2.new(:h => "findme findme")
|
628
|
+
@page5.pages << PieceClass2.new(:h => "findme")
|
629
|
+
@page5.pages << PieceClass2.new(:h => "findme")
|
630
|
+
|
631
|
+
@page1.save
|
632
|
+
@page2.save
|
633
|
+
@page5.save
|
634
|
+
db << @page1
|
635
|
+
db << @page2
|
636
|
+
db << @page5
|
637
|
+
db.close
|
638
|
+
results = @index1.search('findme', :limit => 5)
|
639
|
+
results.map(&:id).must_equal [@page1.id, @page2.id, @page5.id]
|
640
|
+
end
|
663
641
|
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
642
|
+
it "use the weighting specific to a subclass" do
|
643
|
+
db_path = @site.revision_dir(@revision) / 'indexes' / 'one'
|
644
|
+
S::Site.stubs(:published_revision).returns(@revision)
|
645
|
+
@w = PieceClass1.field :w, :index => { :weight => 100 }
|
646
|
+
WeightedPiece = Class.new(PieceClass1)
|
647
|
+
WeightedPiece.field :w, :index => { :weight => 1}
|
648
|
+
index = Site.index :weighted do
|
649
|
+
end
|
650
|
+
@page1.pages << WeightedPiece.new(:w => "findme")
|
651
|
+
@page2.pages << PieceClass2.new(:h => "findme findme")
|
652
|
+
@page2.pages << PieceClass2.new(:h => "findme findme")
|
653
|
+
@page5.pages << PieceClass2.new(:h => "findme")
|
654
|
+
@page5.pages << PieceClass2.new(:h => "findme")
|
655
|
+
|
656
|
+
@page1.save
|
657
|
+
@page2.save
|
658
|
+
@page5.save
|
659
|
+
db = index.create_db(@revision)
|
660
|
+
db << @page1
|
661
|
+
db << @page2
|
662
|
+
db << @page5
|
663
|
+
db.close
|
664
|
+
results = index.search('findme', :limit => 5)
|
665
|
+
results.map(&:id).must_equal [@page2.id, @page5.id, @page1.id]
|
678
666
|
end
|
679
667
|
|
680
|
-
|
681
|
-
|
682
|
-
|
668
|
+
it "provide a convenient way to add documents to multiple indexes" do
|
669
|
+
db1 = mock()
|
670
|
+
db2 = mock()
|
671
|
+
@index1.expects(:create_db).with(@revision).returns(db1)
|
672
|
+
@index2.expects(:create_db).with(@revision).returns(db2)
|
673
|
+
db1.expects(:<<).with(@page1)
|
674
|
+
db2.expects(:<<).with(@page1)
|
675
|
+
db1.expects(:close)
|
676
|
+
db2.expects(:close)
|
677
|
+
S::Site.indexer(@revision) do |indexer|
|
678
|
+
indexer.length.must_equal 2
|
679
|
+
indexer << @page1
|
683
680
|
end
|
681
|
+
end
|
682
|
+
end
|
684
683
|
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
684
|
+
describe "initialization" do
|
685
|
+
before do
|
686
|
+
FileUtils.cp_r(File.expand_path("../../fixtures/search/config", __FILE__), @site.root)
|
687
|
+
end
|
688
|
+
|
689
|
+
it "load the config/indexes.rb file" do
|
690
|
+
@site.expects(:connect_to_database!)
|
691
|
+
@site.initialize!
|
692
|
+
index = @site.indexes[:fast]
|
693
|
+
index.must_be_instance_of S::Search::Index
|
694
|
+
index.name.must_equal :fast
|
695
|
+
index.search_types.must_equal [PageClass1, PageClass2, PageClass3]
|
693
696
|
end
|
694
697
|
end
|
695
698
|
end
|