This repository was archived by the owner on Nov 1, 2017. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork1.1k
Sync changes from upstream repository#920
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
6 changes: 5 additions & 1 deletion.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionGemfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
11 changes: 8 additions & 3 deletionsRules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
37 changes: 20 additions & 17 deletionsassets/javascripts/search.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletionsassets/javascripts/search_worker.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
importScripts('lunr.min.js'); | ||
// create lunr.js search index specifying that we want to index the title and body fields of documents. | ||
var lunr_index = lunr(function() { | ||
this.field('title', { boost: 10 }); | ||
this.field('body'); | ||
this.ref('id'); | ||
}), | ||
entries; | ||
onmessage = function (oEvent) { | ||
populateIndex = function(data) { | ||
// format the raw json into a form that is simpler to work with | ||
this.entries = data.map(this.createEntry).filter(function(n){ return n !== undefined }); | ||
this.entries.forEach(function(entry) { | ||
if (entry !== null) | ||
this.lunr_index.add(entry); | ||
}); | ||
postMessage({type: {indexed: true}}); | ||
}; | ||
decodeHtmlEntity = function(str) { | ||
return str.replace(/&#(\d+);/g, function(match, dec) { | ||
return String.fromCharCode(dec); | ||
}); | ||
}; | ||
createEntry = function(entry, entry_id) { | ||
if (entry.title === undefined) | ||
return undefined; | ||
entry.id = entry_id + 1; | ||
entry.title = decodeHtmlEntity(entry.title); | ||
return entry; | ||
}; | ||
search = function(data) { | ||
var entries = this.entries; | ||
var results = lunr_index | ||
.search(data.query) | ||
.map(function(result) { | ||
return entries.filter(function(entry) { return entry.id === parseInt(result.ref, 10); })[0]; | ||
}) | ||
.filter(function (result) { | ||
return typeof result !== 'undefined'; | ||
}); | ||
postMessage({ query: data.query, results: results, type: { search: true } }); | ||
} | ||
// if we're asked to index, index! else, search | ||
if (oEvent.data.type == "index") | ||
populateIndex(oEvent.data); | ||
else | ||
search(oEvent.data); | ||
}; |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.