kmehan / gt-course-critique

Georgia Institute of Technology Course Critique
18 stars 13 forks source link

Handle search query without a space between dept and course # #30

Closed jonathanhunsucker closed 10 years ago

jonathanhunsucker commented 10 years ago

Searching for "cs1331" should return the same results as "cs 1331". This preg_replace adds the space if it matches the former format.

Test of the regex:

 $queries = array(
     'c',
     'cs',
     'cs1',
     'cs123',
     'cs 123',
     'csasfsafas',
     'math',
     'loss',
     'loss michael',
 );

 $regex = '/^([A-Za-z]*)(\d*)$/';
 $replacement = '$1 $2';

 foreach ($queries as $query) {
     echo $query . ' -> ' . preg_replace($regex, $replacement, $query) . "\n";
 }

Output:

$ php test-fuzzy-search.php 
c -> c 
cs -> cs 
cs1 -> cs 1
cs123 -> cs 123
cs 123 -> cs 123
csasfsafas -> csasfsafas 
math -> math 
loss -> loss 
loss michael -> loss michael
chrisforrence commented 10 years ago

This looks reasonable; @cobookman?

cobookman commented 10 years ago

I'll merge it. But the critique.gatech.edu webpage will not be updated, as I'm no longer in charge of that. I've setup issue #31.