')
- var matchPosition = result.body.indexOf(query.split(' ')[0])
- var bodyStartPosition = matchPosition - SUMMARY_INCLUDE > 0 ? matchPosition - SUMMARY_INCLUDE : 0
+ var metadata = lunrResult[idx].matchData.metadata
+ var matchPosition = metadata[Object.keys(metadata)[0]].body ? metadata[Object.keys(metadata)[0]].body.position[0][0] : 0
+ var bodyStartPosition = (matchPosition - (BODY_LENGTH / 2) > 0) ? matchPosition - (BODY_LENGTH / 2) : 0
+
$searchResultPage.append('
' + result.title + '')
- $searchResultPage.append('
' + result.body.substr(bodyStartPosition, SUMMARY_INCLUDE * 2) + '
')
+
+ $searchResultPage.append('
' + result.body.substr(bodyStartPosition, BODY_LENGTH) + '
')
$searchResults.append($searchResultPage)
// Highlight keyword
@@ -92,7 +112,7 @@ function renderResults (results) {
})
}
-initSearch()
+initLunr()
$(function () {
initUI()