1010 * e.g.:
1111 * $search = (new Search)
1212 * ->setSearchTerms('Bookmark this page')
13- * ->setRegexWholeWords(true)
1413 * ->setRegexCaseInsensitive(true)
15- * ->setRegexPerfectMatch(false)
14+ * ->setRegexEntireString(false)
15+ * ->setEachWord(false)
16+ * ->setEntireWords(false)
1617 * ->setRepository('release')
1718 * ->setSearchType('strings')
1819 * ->setLocales(['en-US', 'fr']);
@@ -38,16 +39,22 @@ class Search
3839 protected $ regex_case ;
3940
4041 /**
41- * Consider the space separated string as a single word for search
42- * @var string
42+ * Only return strings that entirely match the search (case excluded)
43+ * @var boolean
44+ */
45+ protected $ regex_entire_string ;
46+
47+ /**
48+ * Only return strings where entire words match the search (case excluded)
49+ * @var boolean
4350 */
44- protected $ regex_whole_words ;
51+ protected $ regex_entire_words ;
4552
4653 /**
47- * Only return strings that match the search perfectly (case excluded)
54+ * Set to search for each word in the query instead of using it as a whole.
4855 * @var boolean
4956 */
50- protected $ regex_perfect_match ;
57+ protected $ each_word ;
5158
5259 /**
5360 * The search terms for the regex, these differ from $search_terms as
@@ -79,7 +86,8 @@ class Search
7986 * @var array
8087 */
8188 protected $ form_search_options = [
82- 'case_sensitive ' , 'perfect_match ' , 'repo ' , 'search_type ' , 't2t ' , 'whole_word ' ,
89+ 'case_sensitive ' , 'entire_string ' , 'repo ' ,
90+ 'search_type ' , 't2t ' , 'each_word ' , 'entire_words ' ,
8391 ];
8492
8593 /**
@@ -102,8 +110,9 @@ public function __construct()
102110 $ this ->search_terms = '' ;
103111 $ this ->regex = '' ;
104112 $ this ->regex_case = 'i ' ;
105- $ this ->regex_whole_words = '' ;
106- $ this ->regex_perfect_match = false ;
113+ $ this ->regex_entire_string = false ;
114+ $ this ->regex_entire_words = false ;
115+ $ this ->each_word = false ;
107116 $ this ->regex_search_terms = '' ;
108117 $ this ->repository = 'aurora ' ; // Most locales work on Aurora
109118 $ this ->search_type = 'strings ' ;
@@ -161,35 +170,51 @@ public function setRegexCaseInsensitive($flag)
161170 }
162171
163172 /**
164- * Set the regex to only return perfect matches for the searched string.
173+ * Set the regex to only return strings that entirely match the
174+ * searched string.
165175 * We cast the value to a boolean because we usually get it from a GET.
166176 *
167- * @param boolean $flag Set to True for a perfect match
177+ * @param boolean $flag Set to True for an entire string match
168178 * @return $this
169179 */
170- public function setRegexPerfectMatch ($ flag )
180+ public function setRegexEntireString ($ flag )
171181 {
172- $ this ->regex_perfect_match = (boolean ) $ flag ;
182+ $ this ->regex_entire_string = (boolean ) $ flag ;
173183 $ this ->updateRegex ();
174184
175185 return $ this ;
176186 }
177187
178188 /**
179- * Set the regex so as that a multi-word search is taken as a single word.
189+ * Set the regex to only return strings where entire words match
190+ * the searched string.
180191 * We cast the value to a boolean because we usually get it from a GET.
181192 *
182- * @param boolean $flag A string evaluated to True will add \b to the regex
193+ * @param boolean $flag Set to True for an entire words match
183194 * @return $this
184195 */
185- public function setRegexWholeWords ($ flag )
196+ public function setRegexEntireWords ($ flag )
186197 {
187- $ this ->regex_whole_words = (boolean ) $ flag ? '\b ' : '' ;
198+ $ this ->regex_entire_words = (boolean ) $ flag ? '\b ' : '' ;
188199 $ this ->updateRegex ();
189200
190201 return $ this ;
191202 }
192203
204+ /**
205+ * Set to search for each word in the query instead of using it as a whole.
206+ * We cast the value to a boolean because we usually get it from a GET.
207+ *
208+ * @param boolean $flag Set to True to search for each word.
209+ * @return $this
210+ */
211+ public function setEachWord ($ flag )
212+ {
213+ $ this ->each_word = (boolean ) $ flag ;
214+
215+ return $ this ;
216+ }
217+
193218 /**
194219 * Update the $regex_search_terms value every time a setter to the regex
195220 * is called.
@@ -199,15 +224,15 @@ public function setRegexWholeWords($flag)
199224 private function updateRegex ()
200225 {
201226 $ search = preg_quote ($ this ->regex_search_terms );
202- if ($ this ->regex_perfect_match ) {
227+ if ($ this ->regex_entire_string ) {
203228 $ search = "^ {$ search }$ " ;
204229 }
205230
206231 $ this ->regex =
207232 '~ '
208- . $ this ->regex_whole_words
233+ . $ this ->regex_entire_words
209234 . $ search
210- . $ this ->regex_whole_words
235+ . $ this ->regex_entire_words
211236 . '~ '
212237 . $ this ->regex_case
213238 . 'u ' ;
@@ -226,53 +251,63 @@ public function getRegex()
226251 }
227252
228253 /**
229- * Get the state of regex_perfect_match
254+ * Get the state of regex_entire_string
230255 *
231- * @return boolean True if the regex searches for a perfect string match
256+ * @return boolean True if the regex searches for an entire string match
232257 */
233- public function isPerfectMatch ()
258+ public function isEntireString ()
234259 {
235- return $ this ->regex_perfect_match ;
260+ return $ this ->regex_entire_string ;
236261 }
237262
238263 /**
239- * Get search terms
264+ * Get the state of each_word
240265 *
241- * @return string Searched terms
266+ * @return boolean True if the search should be for each word.
242267 */
243- public function getSearchTerms ()
268+ public function isEachWord ()
244269 {
245- return $ this ->search_terms ;
270+ return $ this ->each_word ;
246271 }
247272
248273 /**
249- * Get search terms in regex
274+ * Get the state of entire_words
250275 *
251- * @return string Searched terms in regex
276+ * @return boolean True if the search should be only for entire word.
252277 */
253- public function getRegexSearchTerms ()
278+ public function isEntireWords ()
254279 {
255- return $ this ->regex_search_terms ;
280+ return $ this ->regex_entire_words == ' \b ' ? true : false ;
256281 }
257282
258283 /**
259- * Get the regex case
284+ * Get the state of case_sensitive
260285 *
261- * @return string Return 'i' for case insensitive search, '' for sensitive
286+ * @return boolean False if the search should be case sensitive
262287 */
263- public function getRegexCase ()
288+ public function isCaseSensitive ()
264289 {
265- return $ this ->regex_case ;
290+ return $ this ->regex_case == ' i ' ? false : true ;
266291 }
267292
268293 /**
269- * Get the regex whole words
294+ * Get search terms
270295 *
271- * @return boolean True if we have the 'whole words' option for the regex
296+ * @return string Searched terms
272297 */
273- public function isWholeWords ()
298+ public function getSearchTerms ()
274299 {
275- return $ this ->regex_whole_words ;
300+ return $ this ->search_terms ;
301+ }
302+
303+ /**
304+ * Get search terms in regex
305+ *
306+ * @return string Searched terms in regex
307+ */
308+ public function getRegexSearchTerms ()
309+ {
310+ return $ this ->regex_search_terms ;
276311 }
277312
278313 /**
0 commit comments