1 const moment = require('moment');
17 updated_before: false,
19 created_before: false,
31 this.termString += ' ' + term;
32 this.termString = this.termString.replace(/\s{2,}/g, ' ');
33 this.termString = this.termString.replace(/^\s+/, '');
34 this.termString = this.termString.replace(/\s+$/, '');
37 exactParse(searchString) {
38 this.search.exactTerms = [];
39 let exactFilter = /"(.+?)"/g;
41 while ((matches = exactFilter.exec(searchString)) !== null) {
42 this.search.exactTerms.push(matches[1]);
47 let exactFilter = /"(.+?)"/g;
48 this.termString = this.termString.replace(exactFilter, '');
49 let matchesTerm = this.search.exactTerms.filter(term => {
50 return term.trim() !== '';
54 this.appendTerm(matchesTerm);
58 this.search.exactTerms.push('');
60 let exactInputs = document.querySelectorAll('.exact-input');
61 exactInputs[exactInputs.length - 1].focus();
66 this.search.exactTerms.splice(index, 1);
70 tagParse(searchString) {
71 this.search.tagTerms = [];
72 let tagFilter = /\[(.+?)\]/g;
74 while ((matches = tagFilter.exec(searchString)) !== null) {
75 this.search.tagTerms.push(matches[1]);
80 let tagFilter = /\[(.+?)\]/g;
81 this.termString = this.termString.replace(tagFilter, '');
82 let matchesTerm = this.search.tagTerms.filter(term => {
83 return term.trim() !== '';
87 this.appendTerm(matchesTerm);
91 this.search.tagTerms.push('');
93 let tagInputs = document.querySelectorAll('.tag-input');
94 tagInputs[tagInputs.length - 1].focus();
99 this.search.tagTerms.splice(index, 1);
103 typeParse(searchString) {
104 let typeFilter = /{\s?type:\s?(.*?)\s?}/;
105 let match = searchString.match(typeFilter);
106 let type = this.search.type;
108 type.page = type.book = type.chapter = true;
111 let splitTypes = match[1].replace(/ /g, '').split('|');
112 type.page = (splitTypes.indexOf('page') !== -1);
113 type.chapter = (splitTypes.indexOf('chapter') !== -1);
114 type.book = (splitTypes.indexOf('book') !== -1);
118 let typeFilter = /{\s?type:\s?(.*?)\s?}/;
119 let type = this.search.type;
120 if (type.page === type.chapter && type.page === type.book) {
121 this.termString = this.termString.replace(typeFilter, '');
124 let selectedTypes = Object.keys(type).filter(type => {return this.search.type[type];}).join('|');
125 let typeTerm = '{type:'+selectedTypes+'}';
126 if (this.termString.match(typeFilter)) {
127 this.termString = this.termString.replace(typeFilter, typeTerm);
130 this.appendTerm(typeTerm);
133 optionParse(searchString) {
134 let optionFilter = /{([a-z_\-:]+?)}/gi;
136 while ((matches = optionFilter.exec(searchString)) !== null) {
137 this.search.option[matches[1].toLowerCase()] = true;
141 optionChange(optionName) {
142 let isChecked = this.search.option[optionName];
144 this.appendTerm(`{${optionName}}`);
146 this.termString = this.termString.replace(`{${optionName}}`, '');
152 window.location = window.baseUrl('/search?term=' + encodeURIComponent(this.termString));
155 enableDate(optionName) {
156 this.search.dates[optionName.toLowerCase()] = moment().format('YYYY-MM-DD');
157 this.dateChange(optionName);
160 dateParse(searchString) {
161 let dateFilter = /{([a-z_\-]+?):([a-z_\-0-9]+?)}/gi;
162 let dateTags = Object.keys(this.search.dates);
164 while ((matches = dateFilter.exec(searchString)) !== null) {
165 if (dateTags.indexOf(matches[1]) === -1) continue;
166 this.search.dates[matches[1].toLowerCase()] = matches[2];
170 dateChange(optionName) {
171 let dateFilter = new RegExp('{\\s?'+optionName+'\\s?:([a-z_\\-0-9]+?)}', 'gi');
172 this.termString = this.termString.replace(dateFilter, '');
173 if (!this.search.dates[optionName]) return;
174 this.appendTerm(`{${optionName}:${this.search.dates[optionName]}}`);
177 dateRemove(optionName) {
178 this.search.dates[optionName] = false;
179 this.dateChange(optionName);
185 this.termString = document.querySelector('[name=searchTerm]').value;
186 this.typeParse(this.termString);
187 this.exactParse(this.termString);
188 this.tagParse(this.termString);
189 this.optionParse(this.termString);
190 this.dateParse(this.termString);
194 data, computed, methods, created