quick_search-core 0.0.1.test
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +168 -0
- data/Rakefile +6 -0
- data/app/assets/images/quick_search/askus.gif +0 -0
- data/app/assets/images/quick_search/favicon.ico +0 -0
- data/app/assets/images/quick_search/greybox.png +0 -0
- data/app/assets/images/quick_search/homescreen-icon-64x64.png +0 -0
- data/app/assets/images/quick_search/ncsu-library-logo-white.png +0 -0
- data/app/assets/javascripts/quick_search/appstats.js +8 -0
- data/app/assets/javascripts/quick_search/event_tracking.js.erb +257 -0
- data/app/assets/javascripts/quick_search/google_analytics.js.erb +8 -0
- data/app/assets/javascripts/quick_search/opensearch.js +2 -0
- data/app/assets/javascripts/quick_search/pages.js.coffee +3 -0
- data/app/assets/javascripts/quick_search/quicksearch.js +33 -0
- data/app/assets/javascripts/quick_search/realtime.js.erb +12 -0
- data/app/assets/javascripts/quick_search/search.js +3 -0
- data/app/assets/javascripts/quick_search/xhr_search.js +82 -0
- data/app/assets/javascripts/quick_search.js.erb +20 -0
- data/app/assets/stylesheets/foundation_and_overrides.scss +1327 -0
- data/app/assets/stylesheets/quick_search/appstats.css.scss +7 -0
- data/app/assets/stylesheets/quick_search/opensearch.css.scss +3 -0
- data/app/assets/stylesheets/quick_search/pages.css.scss +3 -0
- data/app/assets/stylesheets/quick_search/quick_search.css.scss +248 -0
- data/app/assets/stylesheets/quick_search/search.css.scss +3 -0
- data/app/assets/stylesheets/quick_search.css.scss.erb +7 -0
- data/app/controllers/concerns/quick_search/auth.rb +22 -0
- data/app/controllers/concerns/quick_search/doi_trap.rb +43 -0
- data/app/controllers/concerns/quick_search/encode_utf8.rb +12 -0
- data/app/controllers/concerns/quick_search/on_campus.rb +43 -0
- data/app/controllers/concerns/quick_search/query_filter.rb +25 -0
- data/app/controllers/concerns/quick_search/query_parser.rb +54 -0
- data/app/controllers/concerns/quick_search/searcher_concern.rb +101 -0
- data/app/controllers/concerns/quick_search/searcher_config.rb +16 -0
- data/app/controllers/quick_search/application_controller.rb +7 -0
- data/app/controllers/quick_search/appstats_controller.rb +210 -0
- data/app/controllers/quick_search/opensearch_controller.rb +9 -0
- data/app/controllers/quick_search/pages_controller.rb +18 -0
- data/app/controllers/quick_search/search_controller.rb +250 -0
- data/app/helpers/quick_search/application_helper.rb +68 -0
- data/app/helpers/quick_search/appstats_helper.rb +2 -0
- data/app/helpers/quick_search/opensearch_helper.rb +2 -0
- data/app/helpers/quick_search/pages_helper.rb +2 -0
- data/app/helpers/quick_search/search_helper.rb +2 -0
- data/app/models/event.rb +2 -0
- data/app/models/search.rb +11 -0
- data/app/searchers/quick_search/best_bets_searcher.rb +102 -0
- data/app/searchers/quick_search/searcher.rb +43 -0
- data/app/views/layouts/quick_search/_best_bets.html.erb +18 -0
- data/app/views/layouts/quick_search/_common_searches.html.erb +15 -0
- data/app/views/layouts/quick_search/_found_types.html.erb +13 -0
- data/app/views/layouts/quick_search/_google_analytics.html.erb +24 -0
- data/app/views/layouts/quick_search/_more_options.html.erb +10 -0
- data/app/views/layouts/quick_search/_page_title.html.erb +8 -0
- data/app/views/layouts/quick_search/_related_topics.html.erb +8 -0
- data/app/views/layouts/quick_search/_search_form.html.erb +19 -0
- data/app/views/layouts/quick_search/_spelling_suggestion.html.erb +13 -0
- data/app/views/layouts/quick_search/_topic_snippet.html.erb +5 -0
- data/app/views/layouts/quick_search/application.html.erb +40 -0
- data/app/views/quick_search/appstats/_click_count_table.html.erb +23 -0
- data/app/views/quick_search/appstats/_datatables.html.erb +12 -0
- data/app/views/quick_search/appstats/_date_range.html.erb +15 -0
- data/app/views/quick_search/appstats/_menu.html.erb +16 -0
- data/app/views/quick_search/appstats/_top_spot_report_table.html.erb +33 -0
- data/app/views/quick_search/appstats/clicks_overview.html.erb +20 -0
- data/app/views/quick_search/appstats/index.html.erb +31 -0
- data/app/views/quick_search/appstats/module_click_detail.html.erb +32 -0
- data/app/views/quick_search/appstats/realtime.html.erb +15 -0
- data/app/views/quick_search/appstats/top_searches.html.erb +38 -0
- data/app/views/quick_search/appstats/top_spot.html.erb +14 -0
- data/app/views/quick_search/appstats/top_spot_detail.html.erb +35 -0
- data/app/views/quick_search/kaminari/_first_page.html.erb +12 -0
- data/app/views/quick_search/kaminari/_gap.html.erb +11 -0
- data/app/views/quick_search/kaminari/_last_page.html.erb +12 -0
- data/app/views/quick_search/kaminari/_next_page.html.erb +12 -0
- data/app/views/quick_search/kaminari/_page.html.erb +13 -0
- data/app/views/quick_search/kaminari/_paginator.html.erb +25 -0
- data/app/views/quick_search/kaminari/_prev_page.html.erb +11 -0
- data/app/views/quick_search/opensearch/opensearch.xml.builder +11 -0
- data/app/views/quick_search/pages/about.html.erb +9 -0
- data/app/views/quick_search/pages/home.html.erb +6 -0
- data/app/views/quick_search/pages/realtime.html.erb +15 -0
- data/app/views/quick_search/search/_citation.html.erb +18 -0
- data/app/views/quick_search/search/_module.html.erb +37 -0
- data/app/views/quick_search/search/_module_with_paging.html.erb +14 -0
- data/app/views/quick_search/search/_no_results.html.erb +11 -0
- data/app/views/quick_search/search/_result.html.erb +17 -0
- data/app/views/quick_search/search/_result_details.html.erb +45 -0
- data/app/views/quick_search/search/_result_no_thumbnail.html.erb +3 -0
- data/app/views/quick_search/search/_result_title.html.erb +4 -0
- data/app/views/quick_search/search/_result_with_thumbnail.html.erb +21 -0
- data/app/views/quick_search/search/_search_error.html.erb +9 -0
- data/app/views/quick_search/search/_see_all.html.erb +11 -0
- data/app/views/quick_search/search/_xhr_response.html.erb +15 -0
- data/app/views/quick_search/search/_xhr_response.json.erb +14 -0
- data/app/views/quick_search/search/_xhr_response_with_paging.html.erb +1 -0
- data/app/views/quick_search/search/index.html.erb +100 -0
- data/config/application.rb +25 -0
- data/config/best_bets.yml +86 -0
- data/config/boot.rb +4 -0
- data/config/database.yml.example +31 -0
- data/config/locales/en.yml +30 -0
- data/config/quicksearch_config.yml.example +69 -0
- data/config/routes.rb +81 -0
- data/db/migrate/20140130202859_create_events.rb +11 -0
- data/db/migrate/20140130202944_create_searches.rb +9 -0
- data/db/migrate/20140225145441_add_page_to_searches.rb +5 -0
- data/db/schema.rb +31 -0
- data/db/seeds.rb +7 -0
- data/lib/benchmark_logger.rb +2 -0
- data/lib/capistrano/tasks/access_check.cap +10 -0
- data/lib/generators/quick_search/install_generator.rb +49 -0
- data/lib/generators/quick_search/templates/kaminari.rb +5 -0
- data/lib/generators/quick_search/templates/post_install.txt +8 -0
- data/lib/generators/quick_search/templates/quick_search_config.yml +58 -0
- data/lib/quick_search/engine.rb +16 -0
- data/lib/quick_search/version.rb +3 -0
- data/lib/quick_search.rb +12 -0
- data/lib/tasks/best_bets.rake +29 -0
- data/test/controllers/appstats_controller_test.rb +7 -0
- data/test/controllers/concerns/doi_trap_test.rb +19 -0
- data/test/controllers/concerns/on_campus_test.rb +19 -0
- data/test/controllers/concerns/query_parser_test.rb +47 -0
- data/test/controllers/opensearch_controller_test.rb +13 -0
- data/test/controllers/pages_controller_test.rb +7 -0
- data/test/controllers/search_controller_test.rb +15 -0
- data/test/fixtures/events.yml +11 -0
- data/test/fixtures/searches.yml +7 -0
- data/test/helpers/appstats_helper_test.rb +4 -0
- data/test/helpers/opensearch_helper_test.rb +4 -0
- data/test/helpers/pages_helper_test.rb +4 -0
- data/test/helpers/search_helper_test.rb +4 -0
- data/test/integration/catalog_search_test.rb +8 -0
- data/test/integration/google_analytics_test.rb +23 -0
- data/test/integration/landing_page_test.rb +8 -0
- data/test/integration/searching_test.rb +40 -0
- data/test/integration/smart_subjects_test.rb +8 -0
- data/test/integration/website_search_test.rb +8 -0
- data/test/models/event_test.rb +7 -0
- data/test/models/search_test.rb +7 -0
- data/test/searcher/best_bets_test.rb +35 -0
- data/test/searcher/catalog_test.rb +35 -0
- data/test/searcher/ematrix_database_test.rb +27 -0
- data/test/searcher/ematrix_journal_test.rb +27 -0
- data/test/searcher/faq_test.rb +27 -0
- data/test/searcher/smart_subjects_test.rb +27 -0
- data/test/searcher/summon_test.rb +13 -0
- data/test/searcher/website_test.rb +34 -0
- data/test/support/vcr_test.rb +40 -0
- data/test/test_helper.rb +42 -0
- metadata +366 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5a4fe03574132a5fd52dd32e79b0e74d7cc06dc0
|
4
|
+
data.tar.gz: 92f12db0d6fa66a458b6b1cbd7cb18ce0066adc5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: de01e59b12184ca86b394ed57fc19350e61c1ff1996135191bc2ae47cb71fef37738f971437b2465003f650763f2cce9795223a80fbaa485c1254216c8537639
|
7
|
+
data.tar.gz: c1aee7635f08ed91c973be3cf9cb5bab232890a7c5046cdbba05a37be91af04f514a219fed2e371bd1a9ded2e74ccb9b1ff6901bddc72a53edddeaf825b083bc
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 North Carolina State University
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
# QuickSearch
|
2
|
+
|
3
|
+
> Note: This code has recently been converted to a Rails Gem Engine. It is encouraged that you use this version, but if you are
|
4
|
+
> looking for the original release of QuickSearch as a standalone Rails project, it can be found here:
|
5
|
+
> https://github.com/NCSU-Libraries/quick_search/tree/pre-gem
|
6
|
+
|
7
|
+
QuickSearch is a customized federated search tool designed to connect people to a variety of library resources, services, and tools. QuickSearch is designed to complement and increase use of existing dedicated library resource discovery tools, such as the catalog, electronic resource search, and subject guides/portals, by directing people to them via an intuitive search interface. The aim of QuickSearch is to provide people with a quick and easy way to find the information they need.
|
8
|
+
|
9
|
+
For more information about NCSU Libraries' QuickSearch and the history of the project, see: http://www.lib.ncsu.edu/reports/quicksearch
|
10
|
+
|
11
|
+
For NCSU Libraries' implementation of QuickSearch, see:
|
12
|
+
http://search.lib.ncsu.edu
|
13
|
+
|
14
|
+
## Features
|
15
|
+
|
16
|
+
- Single search with bento-box style results
|
17
|
+
- Modular
|
18
|
+
- swap out searcher modules and themes easily
|
19
|
+
- choose from a variety of existing searchers or create your own
|
20
|
+
- Best Bets
|
21
|
+
- Search analytics
|
22
|
+
|
23
|
+
## Disclaimer
|
24
|
+
|
25
|
+
This code has been extracted from the code we have been running in
|
26
|
+
production, but still should be considered an early release.
|
27
|
+
|
28
|
+
## Installation
|
29
|
+
|
30
|
+
The aim of QuickSearch is to make it very easy to get up and running. There are several ways that you can go about installing it, depending on your situation.
|
31
|
+
|
32
|
+
### Vagrant
|
33
|
+
|
34
|
+
If you’re interested in trying out QuickSearch, or you’re a developer looking to get a development environment up and running, the easiest way is to use Vagrant to create a virtual environment which automatically installs QuickSearch and its dependencies in only a couple easy steps.
|
35
|
+
|
36
|
+
This method uses Ansible playbooks to provision the virtual environment
|
37
|
+
and install QuickSearch, so it is a good guide to see how you might
|
38
|
+
configure a server for a QuickSearch production envrionment.
|
39
|
+
|
40
|
+
#### Prerequisites
|
41
|
+
|
42
|
+
- Vagrant 1.8+ (http://www.vagrantup.com)
|
43
|
+
- VirtualBox (https://www.virtualbox.org/wiki/Downloads)
|
44
|
+
|
45
|
+
#### Instructions
|
46
|
+
|
47
|
+
##### Clone this repository
|
48
|
+
|
49
|
+
git clone git@github.com:ncsu-libraries/quick_search
|
50
|
+
|
51
|
+
##### Change into the cloned directory
|
52
|
+
|
53
|
+
cd quick_search
|
54
|
+
|
55
|
+
##### Run
|
56
|
+
|
57
|
+
vagrant up
|
58
|
+
|
59
|
+
> Note: sometimes the provisioning process will hang at the "dev-bundle |
|
60
|
+
bundle install" step. If this happens, press Ctrl+C to kill the process,
|
61
|
+
then run the following command to continue the provisioning process:
|
62
|
+
|
63
|
+
vagrant provision
|
64
|
+
|
65
|
+
#####Once this completes, you'll have a running instance of QuickSearch available at http://localhost:8888/
|
66
|
+
|
67
|
+
### Manual Installation
|
68
|
+
|
69
|
+
Follow these instructions to manually install QuickSearch for
|
70
|
+
development.
|
71
|
+
|
72
|
+
#### Prerequisites
|
73
|
+
|
74
|
+
- Rails 4.1
|
75
|
+
- Ruby 2.1
|
76
|
+
- MySQL development headers (mysql-devel package on CentOS)
|
77
|
+
- qtwebkit development headers (qtwebkit-devel package on CentOS)
|
78
|
+
|
79
|
+
#### Instructions
|
80
|
+
|
81
|
+
##### Create a new Rails app, cd into the directory:
|
82
|
+
|
83
|
+
rails new my_app
|
84
|
+
|
85
|
+
...
|
86
|
+
|
87
|
+
cd my_app
|
88
|
+
|
89
|
+
##### Add quick_search_core gem to your Gemfile:
|
90
|
+
|
91
|
+
gem 'quick_search_core'
|
92
|
+
|
93
|
+
> For development, use: gem 'quick_search_core', :git => 'git://github.com/NCSU-Libraries/quick_search.git'
|
94
|
+
|
95
|
+
##### Run 'bundle install'
|
96
|
+
|
97
|
+
##### Run the QuickSearch installation generator:
|
98
|
+
|
99
|
+
bundle exec rails generate quick_search:install
|
100
|
+
|
101
|
+
##### Configure QuickSearch (see [Configuring QuickSearch](docs/configuration.md))
|
102
|
+
|
103
|
+
##### Start the server:
|
104
|
+
|
105
|
+
bundle exec rails s
|
106
|
+
|
107
|
+
##### QuickSearch will be available at http://localhost:3000/
|
108
|
+
|
109
|
+
## Documentation
|
110
|
+
|
111
|
+
Find more in-depth documentation about QuickSearch in the [docs
|
112
|
+
directory](docs/README.md)
|
113
|
+
|
114
|
+
## Customizing QuickSearch
|
115
|
+
|
116
|
+
QuickSearch is built in a modular way, and is easy to modify or extend.
|
117
|
+
For more in-depth documentation about this, see:
|
118
|
+
|
119
|
+
- [Customizing QuickSearch Searchers](docs/customizing_searchers.md)
|
120
|
+
- [Customizing QuickSearch Themes](docs/customizing_themes.md)
|
121
|
+
|
122
|
+
### Searchers
|
123
|
+
|
124
|
+
Here are a list of searchers that have been created for QuickSearch so
|
125
|
+
far. Feel free to submit a pull request to add to this list.
|
126
|
+
|
127
|
+
|Searcher |Repository URL |
|
128
|
+
|------------------------|----------------------------------------------------------------------|
|
129
|
+
|arXiv |http://github.com/NCSU-Libraries/quick_search-arxiv_searcher |
|
130
|
+
|Wikipedia |http://github.com/NCSU-Libraries/quick_search-wikipedia_searcher |
|
131
|
+
|OpenLibrary |http://github.com/NCSU-Libraries/quick_search-open_library_searcher |
|
132
|
+
|Summon |Coming soon |
|
133
|
+
|NCSU Libraries' Catalog |Coming soon |
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
### Themes
|
138
|
+
|
139
|
+
|Theme |Repository URL |
|
140
|
+
|---------------|--------------------------------------------------------------------|
|
141
|
+
|Generic Theme |http://github.com/NCSU-Libraries/quicksearch-generic_theme |
|
142
|
+
|
143
|
+
|
144
|
+
## TODO
|
145
|
+
|
146
|
+
There are still some TODOs left in terms of extracting this code from
|
147
|
+
our production codebase:
|
148
|
+
|
149
|
+
- Fix tests
|
150
|
+
- Improve documentation
|
151
|
+
|
152
|
+
## Bugs, Feature Requests, etc.
|
153
|
+
|
154
|
+
To report bugs, or request features, please use GitHub issues. We also
|
155
|
+
welcome pull requests!
|
156
|
+
|
157
|
+
## Authors
|
158
|
+
|
159
|
+
Here are the people who have contributed code to this implementation of
|
160
|
+
QuickSearch (listed in alphabetical order)
|
161
|
+
|
162
|
+
- Kevin Beswick
|
163
|
+
- Cory Lown
|
164
|
+
- Jason Ronallo
|
165
|
+
|
166
|
+
## License
|
167
|
+
|
168
|
+
See MIT-LICENSE
|
data/Rakefile
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,8 @@
|
|
1
|
+
// Place all the behaviors and hooks related to the matching controller here.
|
2
|
+
// All this logic will automatically be available in application.js.
|
3
|
+
|
4
|
+
$(function () {
|
5
|
+
$('#appstats-date-showhide').click(function () {
|
6
|
+
$('#appstats-date-filter').toggle();
|
7
|
+
});
|
8
|
+
});
|
@@ -0,0 +1,257 @@
|
|
1
|
+
|
2
|
+
var quickSearchEventTracking = (function () {
|
3
|
+
|
4
|
+
// Configs
|
5
|
+
|
6
|
+
var config = {
|
7
|
+
clickTrackingContainer: '.quicksearch-ga-click-tracking',
|
8
|
+
serveTrackingContainer: '.quicksearch-ga-serve-tracking',
|
9
|
+
testingContainer: '#quicksearch-ga-debug',
|
10
|
+
seeAllClass: 'see-all-results',
|
11
|
+
categoryDataAttribute: 'quicksearch-ga-category',
|
12
|
+
actionDataAttribute: 'quicksearch-ga-action',
|
13
|
+
labelDataAttribute: 'quicksearch-ga-label',
|
14
|
+
logQueryDataAttribute: 'quicksearch-ga-query'
|
15
|
+
}
|
16
|
+
|
17
|
+
// Public Methods
|
18
|
+
|
19
|
+
function listenForClicks () {
|
20
|
+
$(document).on('click', config.clickTrackingContainer + ' a', function(e) {
|
21
|
+
var eventValuesDefined = eventValues($(this));
|
22
|
+
var link = $(this)[0];
|
23
|
+
|
24
|
+
// This ensures that ctrl and cmd click to open
|
25
|
+
// link in a new window/tab continues to function.
|
26
|
+
// No need to preventDefault in this case
|
27
|
+
// because the original page remains.
|
28
|
+
if (e.metaKey || e.ctrlKey) {
|
29
|
+
sendEventData(eventValuesDefined, '');
|
30
|
+
return;
|
31
|
+
} else {
|
32
|
+
sendEventData(eventValuesDefined, link);
|
33
|
+
e.preventDefault();
|
34
|
+
}
|
35
|
+
|
36
|
+
// In case the hitCallback isn't triggered soon enough we ensure the link is followed
|
37
|
+
// after this timeout in any case.
|
38
|
+
setTimeout(function() {
|
39
|
+
document.location.href = link.href;
|
40
|
+
}, 200);
|
41
|
+
});
|
42
|
+
}
|
43
|
+
|
44
|
+
function listenForServesOnPageChange () {
|
45
|
+
$(document).ready(function() {
|
46
|
+
serveTrackingDivs = $(config.serveTrackingContainer).get();
|
47
|
+
$.map(serveTrackingDivs, function(val) {
|
48
|
+
checkForServes(val);
|
49
|
+
});
|
50
|
+
});
|
51
|
+
}
|
52
|
+
|
53
|
+
function checkForServes(val) {
|
54
|
+
var link = $(val).find('a');
|
55
|
+
var eventValuesDefined = eventValues(link);
|
56
|
+
eventValuesDefined.category = eventValuesDefined.category + '-serve';
|
57
|
+
sendEventData(eventValuesDefined, '');
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
// Private Methods
|
63
|
+
|
64
|
+
function eventValues (link) {
|
65
|
+
var link = link;
|
66
|
+
var ga_event = {};
|
67
|
+
ga_event.category = eventCategory(link);
|
68
|
+
ga_event.action = eventAction(link);
|
69
|
+
ga_event.label = eventLabel(link);
|
70
|
+
return ga_event;
|
71
|
+
}
|
72
|
+
|
73
|
+
function eventCategory (link) {
|
74
|
+
// FIXME: There may be a better way to get the action from the parent.
|
75
|
+
var category;
|
76
|
+
if (link.data(config.categoryDataAttribute)) {
|
77
|
+
category = link.data(config.categoryDataAttribute);
|
78
|
+
} else if (link[0].id.length > 0) {
|
79
|
+
category = link[0].id;
|
80
|
+
} else {
|
81
|
+
category = link.parents('[id]:first')[0].id;
|
82
|
+
}
|
83
|
+
return category;
|
84
|
+
}
|
85
|
+
|
86
|
+
function eventAction (link) {
|
87
|
+
var action;
|
88
|
+
if (link.data(config.actionDataAttribute)) {
|
89
|
+
action = link.data(config.actionDataAttribute);
|
90
|
+
} else if (link.hasClass(config.seeAllClass)) {
|
91
|
+
action = 'see-all-results';
|
92
|
+
} else if (link.parent('h1,h2').length > 0) {
|
93
|
+
action = 'heading';
|
94
|
+
} else {
|
95
|
+
index = link.parents('li').index()
|
96
|
+
result = index + 1
|
97
|
+
action = 'result-' + result;
|
98
|
+
}
|
99
|
+
return action
|
100
|
+
}
|
101
|
+
|
102
|
+
function eventLabel (link) {
|
103
|
+
var label;
|
104
|
+
if (link.data(config.labelDataAttribute)) {
|
105
|
+
label = link.data(config.labelDataAttribute);
|
106
|
+
} else if (link.parents('body').data(config.logQueryDataAttribute)){
|
107
|
+
label = link.parents('body').data(config.logQueryDataAttribute);
|
108
|
+
} else {
|
109
|
+
label = link[0].href;
|
110
|
+
}
|
111
|
+
return label;
|
112
|
+
}
|
113
|
+
|
114
|
+
function sendEventData (eventValues, link) {
|
115
|
+
<% if Rails.env == 'development' %>
|
116
|
+
console.log('click_tracking', [eventValues.category, eventValues.action, eventValues.label]);
|
117
|
+
$.when(logEventToDatabase(eventValues)).then(function () {
|
118
|
+
if (link !== '') {
|
119
|
+
//document.location.href = link;
|
120
|
+
}
|
121
|
+
});
|
122
|
+
<% elsif Rails.env == 'production' or Rails.env == 'staging' %>
|
123
|
+
$.when(logEventToDatabase(eventValues)).then(function () {
|
124
|
+
sendDataToGoogleAnalytics(eventValues, link)
|
125
|
+
});
|
126
|
+
<% else %>
|
127
|
+
appendTestingData(eventValues);
|
128
|
+
<% end %>
|
129
|
+
}
|
130
|
+
|
131
|
+
function appendTestingData (eventValues) {
|
132
|
+
var debugBlock = $(config.testingContainer);
|
133
|
+
var debugList = $(config.testingContainer + ' ol');
|
134
|
+
debugList.empty();
|
135
|
+
$.map (eventValues, function(val) {
|
136
|
+
debugList.append('<li>' + val + '</li>');
|
137
|
+
});
|
138
|
+
debugBlock.show();
|
139
|
+
}
|
140
|
+
|
141
|
+
function sendDataToGoogleAnalytics (eventValues, link) {
|
142
|
+
|
143
|
+
// Universal Analytics
|
144
|
+
|
145
|
+
// ga('send', 'event', {
|
146
|
+
// 'hitType': 'event',
|
147
|
+
// 'eventCategory': eventValues.category,
|
148
|
+
// 'eventAction': eventValues.action,
|
149
|
+
// 'eventLabel': eventValues.label,
|
150
|
+
// 'hitCallback': function () {
|
151
|
+
// if (link !== '') {
|
152
|
+
// document.location = link;
|
153
|
+
// }
|
154
|
+
// }
|
155
|
+
// });
|
156
|
+
|
157
|
+
// Classic Analytics
|
158
|
+
_gaq.push(['_set','hitCallback',function() {
|
159
|
+
if (link !== '') {
|
160
|
+
document.location = link;
|
161
|
+
}
|
162
|
+
}]);
|
163
|
+
_gaq.push(['_trackEvent', eventValues.category, eventValues.action, eventValues.label]);
|
164
|
+
}
|
165
|
+
|
166
|
+
function logEventToDatabase(eventValues) {
|
167
|
+
|
168
|
+
url = logging_url('log_event');
|
169
|
+
|
170
|
+
return $.ajax({
|
171
|
+
url: url,
|
172
|
+
data: {
|
173
|
+
category: eventValues.category,
|
174
|
+
event_action: eventValues.action,
|
175
|
+
label: eventValues.label
|
176
|
+
}
|
177
|
+
});
|
178
|
+
}
|
179
|
+
|
180
|
+
function checkForSearch() {
|
181
|
+
if ($('body').data(config.logQueryDataAttribute)) {
|
182
|
+
var query = $('body').data(config.logQueryDataAttribute);
|
183
|
+
if (query != '') {
|
184
|
+
searchValuesDefined = searchValues(query);
|
185
|
+
logSearchToDatabase(searchValuesDefined);
|
186
|
+
}
|
187
|
+
}
|
188
|
+
}
|
189
|
+
|
190
|
+
function searchValues (query) {
|
191
|
+
var link = link;
|
192
|
+
var ga_search = {};
|
193
|
+
ga_search.query = query;
|
194
|
+
ga_search.page = searchPage();
|
195
|
+
return ga_search;
|
196
|
+
}
|
197
|
+
|
198
|
+
function searchPage() {
|
199
|
+
var pathname = window.location.pathname;
|
200
|
+
if (pathname == '/') {
|
201
|
+
var page = 'index';
|
202
|
+
} else if (pathname.indexOf('website') > -1) {
|
203
|
+
var page = 'search/website_search';
|
204
|
+
} else {
|
205
|
+
var page = pathname;
|
206
|
+
}
|
207
|
+
|
208
|
+
return page;
|
209
|
+
}
|
210
|
+
|
211
|
+
function logSearchToDatabase(searchValues) {
|
212
|
+
console.log(searchValues);
|
213
|
+
url = logging_url('log_search');
|
214
|
+
|
215
|
+
return $.ajax({
|
216
|
+
url: url,
|
217
|
+
data: {
|
218
|
+
query: searchValues.query,
|
219
|
+
page: searchValues.page
|
220
|
+
}
|
221
|
+
});
|
222
|
+
}
|
223
|
+
|
224
|
+
function logging_url(log_path) {
|
225
|
+
var pathname = window.location.pathname;
|
226
|
+
var url = pathname;
|
227
|
+
if (url.substr(-1) != '/'){
|
228
|
+
url += '/';
|
229
|
+
}
|
230
|
+
url += log_path;
|
231
|
+
|
232
|
+
return url;
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
return {
|
237
|
+
|
238
|
+
// Expose Public Methods
|
239
|
+
|
240
|
+
listenForClicks: listenForClicks,
|
241
|
+
listenForServesOnPageChange: listenForServesOnPageChange,
|
242
|
+
checkForServes: checkForServes,
|
243
|
+
checkForSearch: checkForSearch
|
244
|
+
|
245
|
+
};
|
246
|
+
|
247
|
+
})();
|
248
|
+
|
249
|
+
$( document ).ready(function() {
|
250
|
+
quickSearchEventTracking.checkForSearch();
|
251
|
+
if ($("body").hasClass("search-index")) {
|
252
|
+
quickSearchEventTracking.listenForClicks();
|
253
|
+
quickSearchEventTracking.listenForServesOnPageChange();
|
254
|
+
}
|
255
|
+
});
|
256
|
+
|
257
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%# if Rails.env == 'production' %>
|
2
|
+
// $(document).on('page:load', function() {
|
3
|
+
// // This way of determining the page comes from Google Universal Analytics documentation
|
4
|
+
// // var loc = window.location.protocol + '//' + window.location.hostname + window.location.pathname + window.location.search;
|
5
|
+
// var loc = window.location.pathname + window.location.search;
|
6
|
+
// ga('send', 'pageview', loc);
|
7
|
+
// });
|
8
|
+
<%# end %>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
$(document).ready(function() {
|
2
|
+
|
3
|
+
// Fade out best bet highlight after 3 seconds
|
4
|
+
if (window.innerWidth > 640) {
|
5
|
+
$('.highlight').delay( 6000 ).fadeOut( 500 );
|
6
|
+
} else {
|
7
|
+
$('.highlight').remove();
|
8
|
+
}
|
9
|
+
|
10
|
+
// remove some generic library website template content from DOM
|
11
|
+
$('#utility-search').remove();
|
12
|
+
$('#search-toggle').remove();
|
13
|
+
|
14
|
+
});
|
15
|
+
|
16
|
+
// This handles the highlighting of modules when a result types quide link is clicked
|
17
|
+
$(document).on('click', '.result-types a', function () {
|
18
|
+
|
19
|
+
// Grab the hash value
|
20
|
+
var hash = this.hash.substr(1);
|
21
|
+
|
22
|
+
// Remove any active highlight
|
23
|
+
$('.result-types-highlight').remove();
|
24
|
+
|
25
|
+
// Add the highlight
|
26
|
+
$('#' + hash + ' h2').prepend('<span class="result-types-highlight"><i class="fa fa-angle-double-right highlight"></i> </span>');
|
27
|
+
|
28
|
+
// Fade it away and then remove it.
|
29
|
+
$('#' + hash + ' .highlight').delay( 3000 ).animate({backgroundColor: 'transparent'}, 500 );
|
30
|
+
setTimeout(function() {
|
31
|
+
$('#' + hash + ' .result-types-highlight').remove();
|
32
|
+
}, 3550);
|
33
|
+
});
|
@@ -0,0 +1,12 @@
|
|
1
|
+
var realtime_host = "<%= QuickSearch::Engine::APP_CONFIG['realtime_url'] %>";
|
2
|
+
|
3
|
+
var socket = io.connect(realtime_host);
|
4
|
+
socket.emit('subscribe', {room: 'quicksearch-<%= Rails.env %>'});
|
5
|
+
|
6
|
+
socket.on('update', function(data){
|
7
|
+
console.log(data);
|
8
|
+
if ('q' in data) {
|
9
|
+
var item = '<li>' + data.q + "</li>";
|
10
|
+
$('#realtime_searches ul').prepend(item);
|
11
|
+
}
|
12
|
+
});
|
@@ -0,0 +1,82 @@
|
|
1
|
+
function remove_timedout_spinners(){
|
2
|
+
$('.fa-refresh').not('.icon-5x').remove();
|
3
|
+
$('#no-results-trying-again').remove();
|
4
|
+
}
|
5
|
+
|
6
|
+
function add_found_item_types(endpoint) {
|
7
|
+
var dasherized_endpoint = endpoint.replace("_", "-")
|
8
|
+
$('.result-types li.' + dasherized_endpoint + " .no-results-label")
|
9
|
+
.replaceWith('<a href="#' + dasherized_endpoint + '" data-quicksearch-ga-action="' +
|
10
|
+
dasherized_endpoint + '">' + I18n["en"][endpoint + "_search"]["display_name"]);
|
11
|
+
}
|
12
|
+
|
13
|
+
var xhr_searches = function(){
|
14
|
+
// We want to remove the spinners once all of the ajax requests are done. To do this we create an array of all of the ajax
|
15
|
+
// requests, which are promises. We can then apply this array so that all the promises are wrapped up together. When
|
16
|
+
// they're all done then the 'then' function runs removing the spinners.
|
17
|
+
$.when.apply(this,
|
18
|
+
$('.search-error').map(function(index){
|
19
|
+
var that = $(this);
|
20
|
+
var endpoint = that.data('quicksearchSearchEndpoint');
|
21
|
+
var params_q = $('#params-q').val();
|
22
|
+
var params_page = that.data('quicksearch-page');
|
23
|
+
var params_template = that.data('quicksearch-template');
|
24
|
+
if (!that.hasClass('silent-search-error')) {
|
25
|
+
var parent = that.parent('.module-contents');
|
26
|
+
var parent_id = parent[0].id;
|
27
|
+
}
|
28
|
+
var pathname = window.location.pathname;
|
29
|
+
|
30
|
+
var url = pathname;
|
31
|
+
|
32
|
+
if (url.substr(-1) != '/'){
|
33
|
+
url += '/';
|
34
|
+
}
|
35
|
+
url += 'xhr_search.html?q=' + encodeURIComponent(params_q) + '&endpoint=' + endpoint + '&page=' + params_page + '&template=' + params_template;
|
36
|
+
|
37
|
+
if (!that.hasClass('silent-search-error')) {
|
38
|
+
parent.append('<div class="trying_again"><i class="fa fa-refresh fa-spin"></i> Just a few more seconds </div>');
|
39
|
+
}
|
40
|
+
|
41
|
+
return $.ajax({
|
42
|
+
url: url,
|
43
|
+
timeout: 15000,
|
44
|
+
success: function(response){
|
45
|
+
var response_object = jQuery.parseJSON(response);
|
46
|
+
|
47
|
+
if (!that.hasClass('silent-search-error')) {
|
48
|
+
parent.replaceWith(response_object[endpoint]);
|
49
|
+
if (response_object[endpoint].indexOf("search-error-message") <= -1) {
|
50
|
+
add_found_item_types(endpoint);
|
51
|
+
}
|
52
|
+
if (response_object.spelling_suggestion != ' ') {
|
53
|
+
$('#spelling-suggestion').append(response_object.spelling_suggestion).removeClass('hidden');
|
54
|
+
}
|
55
|
+
if (response_object.related_topics != ' ') {
|
56
|
+
$('#related-topics').append(response_object.related_topics).removeClass('hidden');
|
57
|
+
}
|
58
|
+
} else {
|
59
|
+
that.replaceWith(response_object[endpoint]);
|
60
|
+
if ($.trim(response_object[endpoint]) !== '') {
|
61
|
+
add_found_item_types(endpoint);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
},
|
65
|
+
error: function(){
|
66
|
+
if (!that.hasClass('silent-search-error')) {
|
67
|
+
parent.find('.trying_again').remove();
|
68
|
+
parent.find('.search-error-rescue').show();
|
69
|
+
}
|
70
|
+
}
|
71
|
+
});
|
72
|
+
})
|
73
|
+
).then(
|
74
|
+
// No matter what the result (success, failure) the spinners ought to be removed.
|
75
|
+
remove_timedout_spinners,
|
76
|
+
remove_timedout_spinners
|
77
|
+
);
|
78
|
+
}
|
79
|
+
|
80
|
+
$(document).ready(function() {
|
81
|
+
xhr_searches();
|
82
|
+
});
|
@@ -0,0 +1,20 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require quick_search/google_analytics
|
16
|
+
//= require quick_search/event_tracking
|
17
|
+
//= require quick_search/xhr_search
|
18
|
+
//= require quick_search/quicksearch
|
19
|
+
//= require quick_search/appstats
|
20
|
+
<%= require_asset(QuickSearch::Engine::APP_CONFIG['theme']) %>
|