workarea-content_search 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  4. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.gitignore +13 -0
  7. data/CHANGELOG.md +131 -0
  8. data/CODE_OF_CONDUCT.md +3 -0
  9. data/CONTRIBUTING.md +3 -0
  10. data/Gemfile +9 -0
  11. data/LICENSE +52 -0
  12. data/README.md +45 -0
  13. data/Rakefile +31 -0
  14. data/app/controllers/workarea/.keep +0 -0
  15. data/app/controllers/workarea/storefront/searches_controller.decorator +17 -0
  16. data/app/models/workarea/search/storefront/content.rb +55 -0
  17. data/app/models/workarea/search/storefront.decorator +10 -0
  18. data/app/queries/workarea/search/content_search.rb +96 -0
  19. data/app/queries/workarea/search/search_suggestions.decorator +9 -0
  20. data/app/queries/workarea/search/storefront_search/response.decorator +24 -0
  21. data/app/queries/workarea/search/storefront_search/spelling_correction_with_content.rb +20 -0
  22. data/app/queries/workarea/search/storefront_search/template_with_content.rb +28 -0
  23. data/app/view_models/workarea/storefront/content_search_results.rb +21 -0
  24. data/app/view_models/workarea/storefront/content_search_view_model.rb +49 -0
  25. data/app/views/workarea/storefront/searches/_search_type_toggle.html.haml +8 -0
  26. data/app/views/workarea/storefront/searches/content.html.haml +71 -0
  27. data/app/workers/workarea/bulk_index_content.rb +29 -0
  28. data/app/workers/workarea/clean_content.rb +35 -0
  29. data/app/workers/workarea/index_content.rb +46 -0
  30. data/bin/rails +16 -0
  31. data/config/initializers/appends.rb +4 -0
  32. data/config/initializers/configuration.rb +19 -0
  33. data/config/locales/en.yml +7 -0
  34. data/config/routes.rb +9 -0
  35. data/lib/tasks/content_search_tasks.rake +8 -0
  36. data/lib/workarea/content_search/engine.rb +15 -0
  37. data/lib/workarea/content_search/version.rb +5 -0
  38. data/lib/workarea/content_search.rb +11 -0
  39. data/test/dummy/Rakefile +6 -0
  40. data/test/dummy/app/assets/config/manifest.js +4 -0
  41. data/test/dummy/app/assets/images/.keep +0 -0
  42. data/test/dummy/app/assets/javascripts/application.js +13 -0
  43. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  44. data/test/dummy/app/controllers/application_controller.rb +3 -0
  45. data/test/dummy/app/controllers/concerns/.keep +0 -0
  46. data/test/dummy/app/helpers/application_helper.rb +2 -0
  47. data/test/dummy/app/jobs/application_job.rb +2 -0
  48. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  49. data/test/dummy/app/models/concerns/.keep +0 -0
  50. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  51. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  52. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  53. data/test/dummy/bin/bundle +3 -0
  54. data/test/dummy/bin/rails +4 -0
  55. data/test/dummy/bin/rake +4 -0
  56. data/test/dummy/bin/setup +34 -0
  57. data/test/dummy/bin/update +29 -0
  58. data/test/dummy/config/application.rb +18 -0
  59. data/test/dummy/config/boot.rb +5 -0
  60. data/test/dummy/config/cable.yml +9 -0
  61. data/test/dummy/config/environment.rb +5 -0
  62. data/test/dummy/config/environments/development.rb +54 -0
  63. data/test/dummy/config/environments/production.rb +83 -0
  64. data/test/dummy/config/environments/test.rb +43 -0
  65. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  66. data/test/dummy/config/initializers/assets.rb +11 -0
  67. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  68. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  69. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  70. data/test/dummy/config/initializers/inflections.rb +16 -0
  71. data/test/dummy/config/initializers/mime_types.rb +4 -0
  72. data/test/dummy/config/initializers/session_store.rb +5 -0
  73. data/test/dummy/config/initializers/workarea.rb +5 -0
  74. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  75. data/test/dummy/config/locales/en.yml +23 -0
  76. data/test/dummy/config/puma.rb +47 -0
  77. data/test/dummy/config/routes.rb +5 -0
  78. data/test/dummy/config/secrets.yml +22 -0
  79. data/test/dummy/config.ru +5 -0
  80. data/test/dummy/lib/assets/.keep +0 -0
  81. data/test/dummy/log/.keep +0 -0
  82. data/test/dummy/public/404.html +67 -0
  83. data/test/dummy/public/422.html +67 -0
  84. data/test/dummy/public/500.html +66 -0
  85. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  86. data/test/dummy/public/apple-touch-icon.png +0 -0
  87. data/test/dummy/public/favicon.ico +1 -0
  88. data/test/models/workarea/search/storefront/content_test.rb +28 -0
  89. data/test/queries/workarea/search/content_search_test.rb +74 -0
  90. data/test/system/workarea/storefront/content_search_system_test.rb +103 -0
  91. data/test/test_helper.rb +10 -0
  92. data/test/view_models/workarea/storefront/content_search_results_test.rb +35 -0
  93. data/test/view_models/workarea/storefront/content_search_view_model_test.rb +63 -0
  94. data/test/workers/workarea/bulk_index_content_test.rb +18 -0
  95. data/test/workers/workarea/clean_content_test.rb +42 -0
  96. data/test/workers/workarea/index_content_test.rb +51 -0
  97. data/workarea-content_search.gemspec +21 -0
  98. metadata +153 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 12449ee4b459998e0083ff6daedaa711d577c7ac21c062c3b498a5c946ce8ca1
4
+ data.tar.gz: d90f4ccf145aad771d2681ecbd0e64563bbde18537e6b22fb4d64b5f8eaff0d4
5
+ SHA512:
6
+ metadata.gz: bebeb905089554408bf71691ef17f9cc5c12195281297014129e11155f93d0de9f43ab7c3ba507f95fefba8b86e143ac0442e43dd7a4186f27422c603c01e969
7
+ data.tar.gz: 0a59facf22c4e352d205fe60a7c5523d58952f7c29daea918165d4ce0ffc6eb965cab5e5cffabf887baf2facf4bbe9ea67fda4b92f52cec7ff623dbb1d3c475f
data/.editorconfig ADDED
@@ -0,0 +1,20 @@
1
+ # editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ indent_style = space
7
+ end_of_line = lf
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [{*.rb,*.haml,*.decorator,*.yml,*.yaml,*.jbuilder}]
12
+ indent_size = 2
13
+ indent_style = space
14
+
15
+ [{*.js,*.jst,*.ejs,*.scss}]
16
+ indent_size = 4
17
+
18
+ [*.md]
19
+ indent_size = 4
20
+ trim_trailing_whitespace = false
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve Workarea
4
+ title: ''
5
+ labels: bug
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ ⚠️**Before you create**⚠️
11
+ Please verify the issue you're experiencing is not part of your Workarea project customizations. The best way to do this is with a [vanilla Workarea installation](https://developer.workarea.com/articles/create-a-new-host-application.html). This will help us spend time on fixes/improvements for the whole community. Thank you!
12
+
13
+ **Describe the bug**
14
+ A clear and concise description of what the bug is.
15
+
16
+ **To Reproduce**
17
+ Steps to reproduce the behavior:
18
+ 1. Go to '...'
19
+ 2. Click on '....'
20
+ 3. Scroll down to '....'
21
+ 4. See error
22
+
23
+ **Expected behavior**
24
+ A clear and concise description of what you expected to happen.
25
+
26
+ **Workarea Setup (please complete the following information):**
27
+ - Workarea Version: [e.g. v3.4.6]
28
+ - Plugins [e.g. workarea-blog, workarea-sitemaps]
29
+
30
+ **Attachments**
31
+ If applicable, add any attachments to help explain your problem, things like:
32
+ - screenshots
33
+ - Gemfile.lock
34
+ - test cases
35
+
36
+ **Additional context**
37
+ Add any other context about the problem here.
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: Documentation request
3
+ about: Suggest documentation
4
+ title: ''
5
+ labels: documentation
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your documentation related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm confused by [...]
12
+
13
+ **Describe the article you'd like**
14
+ A clear and concise description of what would be in the documentation article.
15
+
16
+ **Additional context**
17
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for Workarea
4
+ title: ''
5
+ labels: enhancement
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/db/*.sqlite3-journal
6
+ test/dummy/log/*.log
7
+ test/dummy/tmp/
8
+ test/dummy/public/system/
9
+ Gemfile.lock
10
+ node_modules
11
+ test/reports
12
+ package.json
13
+ yarn.lock
data/CHANGELOG.md ADDED
@@ -0,0 +1,131 @@
1
+ Workarea Content Search 1.0.8 (2019-07-09)
2
+ --------------------------------------------------------------------------------
3
+
4
+ * Open Source!
5
+
6
+
7
+ Workarea Content Search 1.0.7 (2019-07-09)
8
+ --------------------------------------------------------------------------------
9
+
10
+ * Choose Default Search Response Template When Sorting Without Type
11
+
12
+ When no `:type` is given, and search results are being sorted, assume
13
+ that this sort was triggered from the "default" product search and not
14
+ content search, and render the default search results template rather
15
+ than the one for content search. This prevents a bug whereby a customer
16
+ was not able to sort product results if more content results were found
17
+ than products, because the search page would always render the content
18
+ template rather than the products search template.
19
+
20
+ CONTSEARCH-12
21
+ Tom Scott
22
+
23
+
24
+
25
+ Workarea Content Search 1.0.6 (2019-05-28)
26
+ --------------------------------------------------------------------------------
27
+
28
+ * Ensure BulkIndexContent documents array does not contain nil objects
29
+
30
+ CONTSEARCH-15
31
+ Matt Duffy
32
+
33
+
34
+
35
+ Workarea Content Search 1.0.5 (2019-05-14)
36
+ --------------------------------------------------------------------------------
37
+
38
+ * Fix Models Excluded From Index Appearing in Content Search
39
+
40
+ Refactor the `IndexContent.skip_index?` method as
41
+ `Search::Storefront::Content#should_be_indexed?`, a core feature that
42
+ allows Elasticsearch documents to control whether they can be indexed or
43
+ not. In the `Search::Storefront` base document class, this method returns
44
+ `true`, but here in `Workarea::ContentSearch` it should be dependent on
45
+ the configuration. Update the `CleanContent` and `IndexContent` jobs to
46
+ call this method before attempting to save a piece of content into the
47
+ index.
48
+
49
+ CONTSEARCH-13
50
+ Tom Scott
51
+
52
+ * Allows sort submission to return to the current search type
53
+
54
+ CONTSEARCH-12
55
+ Lucas Boyd
56
+
57
+
58
+
59
+ Workarea Content Search 1.0.4 (2019-02-05)
60
+ --------------------------------------------------------------------------------
61
+
62
+ * Update indexing behavior for storefront content
63
+
64
+ Trigger indexing of content when blocks are changed and
65
+ allow contentable changes to trigger a reindex of the content
66
+
67
+ CONTSEARCH-8
68
+ Matt Duffy
69
+
70
+ * Update for workarea v3.4 compatibility
71
+
72
+ CONTSEARCH-11
73
+ Matt Duffy
74
+
75
+ * Remove content from search index when Contentable is deleted
76
+
77
+ CleanContent can sometimes be passed an BSON::ObjectId as a string,
78
+ causing the lookup of the content to fail. Querying for the id as
79
+ either an BSON::ObjectId or String.
80
+
81
+ CONTSEARCH-7
82
+ Matt Duffy
83
+
84
+ * Remove Content From Search Index When Contentable is Removed
85
+
86
+ When a `Contentable` object is removed from the search index for
87
+ whatever reason, ensure that its content is also removed from the index.
88
+ Prevents 404s on the storefront when clicking links to contentables that
89
+ either no longer exist, or are no longer active.
90
+
91
+ CONTSEARCH-7
92
+ Tom Scott
93
+
94
+
95
+
96
+ Workarea Content Search 1.0.3 (2018-07-10)
97
+ --------------------------------------------------------------------------------
98
+
99
+ * Fix Gemfile
100
+
101
+ Curt Howard
102
+
103
+ * Remove use of .percolate method for es index
104
+
105
+ CONTSEARCH-6
106
+ Matt Duffy
107
+
108
+ * Leverage Workarea Changelog task
109
+
110
+ ECOMMERCE-5355
111
+ Curt Howard
112
+
113
+
114
+
115
+ Workarea Content Search 1.0.1 (2017-05-30)
116
+ --------------------------------------------------------------------------------
117
+
118
+ * Initialization clean up, exclude content from search suggestions
119
+
120
+ CONTSEARCH-4
121
+ Matt Duffy
122
+
123
+ * Decorate core test to update assertions affected by content search
124
+
125
+ CONTSEARCH-4
126
+ Matt Duffy
127
+
128
+
129
+ Workarea Content Search 1.0.0 (2017-05-04)
130
+ --------------------------------------------------------------------------------
131
+
@@ -0,0 +1,3 @@
1
+ View this plugin's code of conduct here:
2
+
3
+ <https://github.com/workarea-commerce/workarea/blob/master/CODE_OF_CONDUCT.md>
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,3 @@
1
+ View this plugin's contribution guidelines here:
2
+
3
+ <https://github.com/workarea-commerce/workarea/blob/master/CONTRIBUTING.md>
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "git@github.com:#{repo}.git" }
3
+
4
+ gemspec
5
+
6
+ # To use a debugger
7
+ # gem 'byebug', group: [:development, :test]
8
+
9
+ gem 'workarea', github: 'workarea-commerce/workarea'
data/LICENSE ADDED
@@ -0,0 +1,52 @@
1
+ WebLinc
2
+ Business Source License
3
+
4
+ Licensor: WebLinc Corporation, 22 S. 3rd Street, 2nd Floor, Philadelphia PA 19106
5
+
6
+ Licensed Work: Workarea Commerce Platform
7
+ The Licensed Work is (c) 2019 WebLinc Corporation
8
+
9
+ Additional Use Grant:
10
+ You may make production use of the Licensed Work without an additional license agreement with WebLinc so long as you do not use the Licensed Work for a Commerce Service.
11
+
12
+ A "Commerce Service" is a commercial offering that allows third parties (other than your employees and contractors) to access the functionality of the Licensed Work by creating or managing commerce functionality, the products, taxonomy, assets and/or content of which are controlled by such third parties.
13
+
14
+ For information about obtaining an additional license agreement with WebLinc, contact licensing@workarea.com.
15
+
16
+ Change Date: 2019-08-20
17
+
18
+ Change License: Version 2.0 or later of the GNU General Public License as published by the Free Software Foundation
19
+
20
+ Terms
21
+
22
+ The Licensor hereby grants you the right to copy, modify, create derivative works, redistribute, and make non-production use of the Licensed Work. The Licensor may make an Additional Use Grant, above, permitting limited production use.
23
+
24
+ Effective on the Change Date, or the fourth anniversary of the first publicly available distribution of a specific version of the Licensed Work under this License, whichever comes first, the Licensor hereby grants you rights under the terms of the Change License, and the rights granted in the paragraph above terminate.
25
+
26
+ If your use of the Licensed Work does not comply with the requirements currently in effect as described in this License, you must purchase a commercial license from the Licensor, its affiliated entities, or authorized resellers, or you must refrain from using the Licensed Work.
27
+
28
+ All copies of the original and modified Licensed Work, and derivative works of the Licensed Work, are subject to this License. This License applies separately for each version of the Licensed Work and the Change Date may vary for each version of the Licensed Work released by Licensor.
29
+
30
+ You must conspicuously display this License on each original or modified copy of the Licensed Work. If you receive the Licensed Work in original or modified form from a third party, the terms and conditions set forth in this License apply to your use of that work.
31
+
32
+ Any use of the Licensed Work in violation of this License will automatically terminate your rights under this License for the current and all other versions of the Licensed Work.
33
+
34
+ This License does not grant you any right in any trademark or logo of Licensor or its affiliates (provided that you may use a trademark or logo of Licensor as expressly required by this License). TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE. MariaDB hereby grants you permission to use this License’s text to license your works and to refer to it using the trademark "Business Source License" as long as you comply with the Covenants of Licensor below.
35
+
36
+ Covenants of Licensor
37
+ In consideration of the right to use this License’s text and the "Business Source License" name and trademark, Licensor covenants to MariaDB, and to all other recipients of the licensed work to be provided by Licensor:
38
+
39
+ To specify as the Change License the GPL Version 2.0 or any later version, or a license that is compatible with GPL Version 2.0 or a later version, where "compatible" means that software provided under the Change License can be included in a program with software provided under GPL Version 2.0 or a later version. Licensor may specify additional Change Licenses without limitation.
40
+
41
+ To either: (a) specify an additional grant of rights to use that does not impose any additional restriction on the right granted in this License, as the Additional Use Grant; or (b) insert the text "None."
42
+
43
+ To specify a Change Date.
44
+
45
+ Not to modify this License in any other way.
46
+
47
+ Notice
48
+ The Business Source License (this document, or the "License") is not an Open Source license. However, the Licensed Work will eventually be made available under an Open Source License, as stated in this License.
49
+
50
+ For more information on the use of the Business Source License generally, please visit the Adopting and Developing Business Source License FAQ.
51
+
52
+ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved. "Business Source License" is a trademark of MariaDB Corporation Ab.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ Workarea Content Search
2
+ ================================================================================
3
+
4
+ A Workarea Commerce plugin that enables visitors of your site to use the site-wide search to find content pages.
5
+
6
+ Overview
7
+ --------------------------------------------------------------------------------
8
+
9
+ * Indexes content pages in Elasticsearch
10
+ * Enables returning both product and content search results on the storefront
11
+ * Adds the ability for visitors to toggle between content and product results
12
+
13
+ Getting Started
14
+ --------------------------------------------------------------------------------
15
+
16
+ Add the gem to your application's Gemfile:
17
+
18
+ ```ruby
19
+ # ...
20
+ gem 'workarea-content_search'
21
+ # ...
22
+ ```
23
+
24
+ Update your application's bundle.
25
+
26
+ ```bash
27
+ cd path/to/application
28
+ bundle
29
+ ```
30
+
31
+ If you are adding this to an existing site, reindex the storefront.
32
+
33
+ ```bash
34
+ bin/rails workarea:search_index:storefront
35
+ ```
36
+
37
+ Workarea Commerce Documentation
38
+ --------------------------------------------------------------------------------
39
+
40
+ See [https://developer.workarea.com](https://developer.workarea.com) for Workarea Commerce documentation.
41
+
42
+ License
43
+ --------------------------------------------------------------------------------
44
+
45
+ Workarea Content Search is released under the [Business Software License](LICENSE)
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
8
+ load 'rails/tasks/engine.rake'
9
+ load 'rails/tasks/statistics.rake'
10
+ load 'workarea/changelog.rake'
11
+
12
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
13
+ require 'workarea/content_search/version'
14
+
15
+ desc "Release version #{Workarea::ContentSearch::VERSION} of the gem"
16
+ task :release do
17
+ host = "https://#{ENV['BUNDLE_GEMS__WEBLINC__COM']}@gems.weblinc.com"
18
+
19
+ #Rake::Task['workarea:changelog'].execute
20
+ #system 'git add CHANGELOG.md'
21
+ #system 'git commit -m "Update CHANGELOG"'
22
+ #system 'git push origin HEAD'
23
+
24
+ system "git tag -a v#{Workarea::ContentSearch::VERSION} -m 'Tagging #{Workarea::ContentSearch::VERSION}'"
25
+ system 'git push --tags'
26
+
27
+ system 'gem build workarea-content_search.gemspec'
28
+ system "gem push workarea-content_search-#{Workarea::ContentSearch::VERSION}.gem"
29
+ system "gem push workarea-content_search-#{Workarea::ContentSearch::VERSION}.gem --host #{host}"
30
+ system "rm workarea-content_search-#{Workarea::ContentSearch::VERSION}.gem"
31
+ end
File without changes
@@ -0,0 +1,17 @@
1
+ module Workarea
2
+ decorate Storefront::SearchesController, with: :content_search do
3
+ def content
4
+ response = Search::StorefrontSearch.new(params.to_unsafe_h).response
5
+ response.template = 'content'
6
+ handle_search_response(response)
7
+ end
8
+
9
+ def set_search(response)
10
+ if response.template == 'content'
11
+ @search = Storefront::ContentSearchViewModel.new(response, view_model_options)
12
+ else
13
+ super
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,55 @@
1
+ module Workarea
2
+ module Search
3
+ class Storefront
4
+ class Content < Workarea::Search::Storefront
5
+ # TODO: rename method ensure_dynamic_mappings
6
+ def self.percolate_null_content
7
+ content = new(Workarea::Content.new)
8
+ content.save
9
+
10
+ Storefront.delete(content.id)
11
+ end
12
+
13
+ def content
14
+ { name: name, text: text, summary: text }
15
+ end
16
+
17
+ def sorts
18
+ { has_text: text.present? ? 1 : 0 }
19
+ end
20
+
21
+ def cache
22
+ { resource_name: resource_name }
23
+ end
24
+
25
+ def name
26
+ model.contentable.try(:name)
27
+ end
28
+
29
+ def text
30
+ @text ||= ExtractContentBlockText.new(model.blocks).text
31
+ end
32
+
33
+ def suggestion_content
34
+ "#{name} #{text}"
35
+ end
36
+
37
+ def slug
38
+ model.contentable.try(:slug)
39
+ end
40
+
41
+ def resource_name
42
+ return nil unless model.contentable_type.present?
43
+ model.contentable_type.underscore.split('/').last
44
+ end
45
+
46
+ def should_be_indexed?
47
+ !model.system? &&
48
+ !model.contentable.class.name.in?(
49
+ Workarea.config.exclude_from_content_search_index
50
+ )
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,10 @@
1
+ module Workarea
2
+ decorate Search::Storefront, with: :content_search do
3
+ class_methods do
4
+ def ensure_dynamic_mappings
5
+ super
6
+ Search::Storefront::Content.percolate_null_content
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,96 @@
1
+ module Workarea
2
+ module Search
3
+ class ContentSearch
4
+ include Query
5
+ include QuerySuggestions
6
+ include Pagination
7
+
8
+ document Search::Storefront
9
+
10
+ def self.available_sorts
11
+ Sort::Collection.new(Sort.relevance, Sort.newest)
12
+ end
13
+
14
+ def customization
15
+ @customization ||= Customization.find_by_query(params[:q])
16
+ end
17
+
18
+ def rewritten_query
19
+ if customization.rewrite?
20
+ customization.rewrite
21
+ else
22
+ query_string.sanitized
23
+ end
24
+ end
25
+
26
+ def query
27
+ if params[:q].present? && !query_string.all?
28
+ {
29
+ multi_match: {
30
+ query: rewritten_query,
31
+ type: 'cross_fields',
32
+ fields: %w(content.name^2 content.text^0.75),
33
+ tie_breaker: Workarea.config.search_dismax_tie_breaker
34
+ }
35
+ }
36
+ else
37
+ super
38
+ end
39
+ end
40
+
41
+ def post_filter
42
+ filters = super
43
+ filters[:bool] ||= {}
44
+ filters[:bool][:must] ||= []
45
+ filters[:bool][:must] << { term: { type: 'content' } }
46
+ filters
47
+ end
48
+
49
+ def sort
50
+ result = []
51
+ selected_sort = self.class.available_sorts.find(params[:sort])
52
+
53
+ if selected_sort.field.present?
54
+ result << { selected_sort.field => selected_sort.direction }
55
+ else
56
+ result << {
57
+ 'sorts.has_text' => {
58
+ order: 'desc',
59
+ missing: '_last',
60
+ unmapped_type: 'float'
61
+ }
62
+ }
63
+ result << { _score: :desc }
64
+ end
65
+
66
+ result
67
+ end
68
+
69
+ def results
70
+ @results ||=
71
+ begin
72
+ tmp = response['hits']['hits'].map do |result|
73
+ result['_source']
74
+ end
75
+
76
+ PagedArray.from(
77
+ tmp,
78
+ page,
79
+ per_page,
80
+ total
81
+ )
82
+ end
83
+ end
84
+
85
+ # (sadpanda) QuerySuggestions looks to product display rules for
86
+ # conditions to use when generating suggestions. We need content search
87
+ # to respond to the method to prevent any issues with suggestions for
88
+ # content.
89
+ #
90
+ # TODO: for v4, rework QuerySuggestions to not depend on another module
91
+ def product_display_query_clauses
92
+ []
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,9 @@
1
+ module Workarea
2
+ decorate Search::SearchSuggestions, with: :content_search do
3
+ def query
4
+ super.tap do |query|
5
+ query[:bool][:must_not] = { term: { type: 'content' } }
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ module Workarea
2
+ decorate Search::StorefrontSearch::Response, with: :content_search do
3
+
4
+ decorated do
5
+ attr_accessor :content_query
6
+ end
7
+
8
+ def reset!(params, by: nil)
9
+ # maintain compatiblity with workarea < 3.4 and 3.4+
10
+ # TODO: Remove if/when support for < 3.4 is not necessary
11
+ by.present? ? super : super(params)
12
+
13
+ @content_query = Search::ContentSearch.new(params)
14
+ end
15
+
16
+ def content_total
17
+ content_query.total
18
+ end
19
+
20
+ def query_suggestions
21
+ super + content_query.query_suggestions
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ module Workarea
2
+ module Search
3
+ class StorefrontSearch
4
+ class SpellingCorrectionWithContent < StorefrontSearch::SpellingCorrection
5
+ def find_spell_correction(response)
6
+ return nil if response.has_filters? || any_results?(response)
7
+
8
+ product_correction = response.query.query_suggestions.first
9
+ content_correction = response.content_query.query_suggestions.first
10
+
11
+ product_correction.presence || content_correction
12
+ end
13
+
14
+ def any_results?(response)
15
+ response.total > 0 || response.content_query.total > 0
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ module Workarea
2
+ module Search
3
+ class StorefrontSearch
4
+ class TemplateWithContent
5
+ include Middleware
6
+
7
+ def call(response)
8
+ if response.has_filters?
9
+ yield
10
+ return
11
+ end
12
+
13
+ if response.total.zero? && response.content_total.zero?
14
+ response.template = 'no_results'
15
+ elsif response.params[:type].present?
16
+ response.template = response.params[:type]
17
+ elsif response.params[:sort].present?
18
+ response.template = 'show'
19
+ elsif response.content_total > response.total
20
+ response.template = 'content'
21
+ else
22
+ yield
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end