Skip to content

Commit

Permalink
issue/14 Reindex when models change (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverfoster authored Jul 15, 2021
1 parent 4eb37d6 commit 14d9ae6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ A list of search keywords/phrases to be associated with the contentObject/articl
No known limitations.

----------------------------
**Version number:** 4.0.0 <a href="https://community.adaptlearning.org/" target="_blank"><img src="https://github.com/adaptlearning/documentation/blob/master/04_wiki_assets/plug-ins/images/adapt-logo-mrgn-lft.jpg" alt="adapt learning logo" align="right"></a>
**Version number:** 4.0.1 <a href="https://community.adaptlearning.org/" target="_blank"><img src="https://github.com/adaptlearning/documentation/blob/master/04_wiki_assets/plug-ins/images/adapt-logo-mrgn-lft.jpg" alt="adapt learning logo" align="right"></a>
**Framework versions:** 5.8+
**Author / maintainer:** Kineo and community with [contributors](https://github.com/cgkineo/adapt-search/graphs/contributors)
**Accessibility support:** WAI AA
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "git",
"url": "git://github.com/cgkineo/adapt-search"
},
"version": "4.0.0",
"version": "4.0.1",
"framework": ">=5.8",
"homepage": "https://github.com/cgkineo/adapt-search",
"issues": "https://github.com/cgkineo/adapt-search/issues/",
Expand Down
10 changes: 9 additions & 1 deletion js/adapt-search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Adapt from 'core/js/adapt';
import data from 'core/js/data';
import SearchDrawerItemView from './searchDrawerItemView';
import SearchResultsView from './searchResultsView';
import SEARCH_DEFAULTS from './SEARCH_DEFAULTS';
Expand All @@ -19,6 +20,9 @@ class Search extends Backbone.Controller {
'drawer:closed': this.onDrawerClosed,
'drawer:noItems': this.onNoItems
});
this.listenTo(data, {
'add remove change:_isAvailable change:_isLocked': this.reIndex
});
}

onDataReady() {
Expand All @@ -32,12 +36,16 @@ class Search extends Backbone.Controller {
const modelWithDefaults = $.extend(true, {}, SEARCH_DEFAULTS, model);
Adapt.course.set('_search', modelWithDefaults);
this.isSetup = true;
window.search = this.searcher = new Searcher();
this.reIndex();
}

clearSearchResults() {
this.query('');
this.addDrawerItem();
this.reIndex();
}

reIndex() {
if (!this.isSetup) return;
window.search = this.searcher = new Searcher();
}
Expand Down

0 comments on commit 14d9ae6

Please sign in to comment.