Skip to content

Commit

Permalink
update view_facet
Browse files Browse the repository at this point in the history
Niqui O'Neill committed May 15, 2019
1 parent 59fcbc6 commit 7cc8f4c
Showing 11 changed files with 24 additions and 7,234 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -5,13 +5,6 @@ Originally forked from [jekyll-lunr-js-search](https://github.com/slashdotdash/j
### Using gem
Quickstart instructions are located here: [https://dnoneill.github.io/jekyll-lunr-js-custom-search/quickstart](https://dnoneill.github.io/jekyll-lunr-js-custom-search/quickstart)

### 6. Alternate data directory

You can choose to store `index.js`, `custom-search.js` and `lunr.js` in a different directory like this:

lunr_search:
js_dir: "javascript"

### Development Requirements

Install [Bundler](http://bundler.io/) and then run the following.
2 changes: 1 addition & 1 deletion build/custom-search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

180 changes: 0 additions & 180 deletions build/jekyll_lunr_advanced_js_search.rb

This file was deleted.

7 changes: 4 additions & 3 deletions build/jekyll_lunr_js_custom_search.rb
Original file line number Diff line number Diff line change
@@ -14,10 +14,11 @@ def initialize(config = {})
@jekyllconfig = config
@config = config['lunr_settings']
fields = Hash[@config['fields'].collect { |field| [field['searchfield'], field['boost']] }]
jsdir = @config['js_dir'] ? @config['js_dir'] : 'js'
@lunr_config = {
'js_dir' => 'js',
'js_dir' => jsdir,
'css_dir' => 'css'
}.merge!(config['lunr_search'] || {})
}
@lunr_config['fields'] = fields
@js_dir = @lunr_config['js_dir']
@css_dir = @lunr_config['css_dir']
@@ -108,7 +109,7 @@ def generate(site)
ctx = ExecJS.compile(index_js)

index = ctx.eval('JSON.stringify(idx)')
total = "var docs = #{@docs.to_json}\nvar index = #{index.to_json}\nvar view_facets = #{@jekyllconfig['view_facets'].to_json}\nvar baseurl = #{@jekyllconfig['baseurl'].to_json}\nvar lunr_settings = #{@config.to_json}"
total = "var docs = #{@docs.to_json}\nvar index = #{index.to_json}\nvar baseurl = #{@jekyllconfig['baseurl'].to_json}\nvar lunr_settings = #{@config.to_json}"
filepath = File.join(site.dest, filename)
File.open(filepath, "w") { |f| f.write(total) }
Jekyll.logger.info "Lunr:", "Index ready (lunr.js v#{@lunr_version})"
4 changes: 1 addition & 3 deletions demo/_config.yml
Original file line number Diff line number Diff line change
@@ -30,9 +30,6 @@ plugins:
- jekyll-feed
- jekyll-lunr-js-custom-search

view_facets: 5


lunr_settings:
atozsortfield: preferredName
collections: [people]
@@ -83,6 +80,7 @@ lunr_settings:
secondaryfield: contributorId
widget: relational
fuzzysearchfields: [name, birthplace, residences, worklocations]
view_facets: 5

collections:
people:
159 changes: 0 additions & 159 deletions demo/dist/advanced-search.css

This file was deleted.

6,876 changes: 0 additions & 6,876 deletions demo/dist/advanced-search.js

This file was deleted.

2 changes: 1 addition & 1 deletion demo/dist/custom-search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions demo/docs/quickstart/setup.md
Original file line number Diff line number Diff line change
@@ -181,6 +181,17 @@ lunr_settings:
fuzzysearchfields: [name]
```

## view_facets
**view_facets** should be a number field. This is an **optional** field, if it is not set it will revert to the **default** setting of 4. This determines how many facets are shown, if there are more facets then view_facets the remaining facets will be hidden but can be displayed with the "Show All" button that is automatically generated.

## js_dir
You can choose to store `index.js`, `custom-search.js` and `lunr.js` in a different directory like this:

```
lunr_settings:
js_dir: "javascript"
```

## Full settings example
An example of all these settings can be seen below. An example of it running is here: [https://dnoneill.github.io/jekyll-customsearch/search?q=&name=&ethnicity=](https://dnoneill.github.io/jekyll-customsearch/search?q=&name=&ethnicity=)

@@ -235,4 +246,5 @@ lunr_settings:
secondaryfield: contributorId
widget: relational
fuzzysearchfields: [name, birthplace, residences, worklocations]
view_facets: 5
```
2 changes: 1 addition & 1 deletion js/lunr.custom.search.js
Original file line number Diff line number Diff line change
@@ -183,7 +183,7 @@ function loadsearchtemplate(settings){
return tmp;
}();
}
view_facets = view_facets ? view_facets : 4;
view_facets = lunr_settings['view_facets'] ? lunr_settings['view_facets'] : 4;
var site_url = window.location.origin + window.location.pathname;
var query = window.location.search.substring(1);
if (query != ''){
7 changes: 4 additions & 3 deletions lib/jekyll_lunr_js_custom_search/indexer.rb
Original file line number Diff line number Diff line change
@@ -14,10 +14,11 @@ def initialize(config = {})
@jekyllconfig = config
@config = config['lunr_settings']
fields = Hash[@config['fields'].collect { |field| [field['searchfield'], field['boost']] }]
jsdir = @config['js_dir'] ? @config['js_dir'] : 'js'
@lunr_config = {
'js_dir' => 'js',
'js_dir' => jsdir,
'css_dir' => 'css'
}.merge!(config['lunr_search'] || {})
}
@lunr_config['fields'] = fields
@js_dir = @lunr_config['js_dir']
@css_dir = @lunr_config['css_dir']
@@ -108,7 +109,7 @@ def generate(site)
ctx = ExecJS.compile(index_js)

index = ctx.eval('JSON.stringify(idx)')
total = "var docs = #{@docs.to_json}\nvar index = #{index.to_json}\nvar view_facets = #{@jekyllconfig['view_facets'].to_json}\nvar baseurl = #{@jekyllconfig['baseurl'].to_json}\nvar lunr_settings = #{@config.to_json}"
total = "var docs = #{@docs.to_json}\nvar index = #{index.to_json}\nvar baseurl = #{@jekyllconfig['baseurl'].to_json}\nvar lunr_settings = #{@config.to_json}"
filepath = File.join(site.dest, filename)
File.open(filepath, "w") { |f| f.write(total) }
Jekyll.logger.info "Lunr:", "Index ready (lunr.js v#{@lunr_version})"

0 comments on commit 7cc8f4c

Please sign in to comment.