Skip to content

Commit

Permalink
Merge pull request #8 from robintaylor/master
Browse files Browse the repository at this point in the history
LIB001-519 Add autocomplete to the Search box for the Exam Papers
  • Loading branch information
Robin Taylor committed Feb 21, 2014
2 parents 6a19892 + 2b187e3 commit 8bee7d6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions application/controllers/autocomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@ function Autocomplete() {

public function index() {

log_message('debug', "search autocomplete initialized");

$term = $this->input->get('term');
$field = $this->input->get('field');
$term_lower = strtolower($term);

$solr_xml = file_get_contents($this->config->item('skylight_solrbase') . 'terms?terms=true&terms.fl='.$field.'&terms.prefix='.$term.'&terms.lower.incl=false&terms.regex.flag=case_insensitive&indent=true&wt=json');
//$solr_xml = file_get_contents($this->config->item('skylight_solrbase') . 'terms?terms=true&terms.fl='.$field.'&terms.prefix='.$term.'&terms.lower.incl=false&terms.regex.flag=case_insensitive&indent=true&wt=json');
$solr_xml = file_get_contents($this->config->item('skylight_solrbase') . 'terms?terms=true&terms.fl=title_ac&terms.prefix='.$term_lower.'&terms.lower.incl=false&terms.regex.flag=case_insensitive&indent=true&wt=json');

$ac_json = json_decode($solr_xml);

echo '[';
for($i = 0; $i < sizeof($ac_json->terms[1]); $i += 2) {
echo '"'.$ac_json->terms[1][$i].'"';
if($i+2 < sizeof($ac_json->terms[1])) {
for($i = 0; $i < sizeof($ac_json->terms->{'title_ac'}); $i += 2) {
echo '"'.$ac_json->terms->{'title_ac'}[$i].'"';
if($i+2 < sizeof($ac_json->terms->{'title_ac'})) {
echo ', ';
}
}
Expand Down

0 comments on commit 8bee7d6

Please sign in to comment.