Skip to content

full-text search using listjs #1720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions _includes/lesson-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<!--
this div ('lesson-list', referenced in lessonfilter.js) needs to contain the sort button/elements AND the actual list for the sort buttons to work
-->
<input id="search" type="text" placeholder="Search lessons...">
<div id="lesson-list">

<!--
Expand All @@ -40,6 +41,7 @@

<input id="date-sort-text" type="hidden" label="{{site.data.snippets.date[page.lang]}}">
<input id="difficulty-sort-text" type="hidden" label="{{site.data.snippets.difficulty[page.lang]}}">


<h2 class="results-title">{{ site.data.snippets.filtering-results[page.lang] }}: <span id="results-value">{{ site.data.snippets.all-lessons[page.lang] }} </span> <span id="current-sort" class="sort-desc">{{site.data.snippets.date[page.lang]}}</span></h2>

Expand Down
1 change: 1 addition & 0 deletions _includes/lesson_describe.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ <h3 class="above-title">{{ include.authors }}</h3>
<span class="topics">{{ lesson.topics | join: ' '}}</span>
<span class="date">{% if lesson.translation_date %}{{ lesson.translation_date }}{% else %}{{ lesson.date }}{% endif %}</span>
<span class="difficulty">{{ lesson.difficulty }}</span>
<span id="{{lesson.title}}-content" class="content" style="display: none;">{{ lesson.content | markdownify | strip_html }}</span>

</div>
19 changes: 19 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,25 @@ Lessons Index
background-color:#ededed;
}

/*****************
SEARCH
*****************/

#search {
width:99.5%;
clear:both;
margin-bottom:1rem;
background-color:#fefefe;
color:#666;
border:1px solid #999;
font: .9rem/1.1rem 'Open Sans',
sans-serif;
padding: .4rem .6rem;
border-radius: 3px;
display:inline-block;
text-transform:uppercase;
text-decoration: none;
}

/*****************
SORT BUTTONS
Expand Down
9 changes: 8 additions & 1 deletion js/lessonfilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,20 @@ function wireButtons() {
console.log(uri.toString());

var options = {
valueNames: [ 'date', 'title', 'difficulty', 'activity', 'topics' ]
valueNames: [ 'date', 'title', 'difficulty', 'activity', 'topics','abstract', 'content' ]
};

var featureList = new List('lesson-list', options);
// We need a stateObj for adjusting the URIs on button clicks, but the value is moot for now; could be useful for future functionality.
var stateObj = { foo: "bar" };

// Filter lessons on search
$('#search').on('keyup', function () {
var searchString = $(this).val();
featureList.search(searchString, ['content']);
// featureList.fuzzySearch(searchString, ['content']); // List.js has a fuzzy search method but I get fewer results with it than the regular search method. We could create are own fuzzy search function here and then use List.js filtering instead of search.
});

// When a filter button is clicked
$('.filter').children().click(function() {
// Set clicked button as current
Expand Down