/** * Main search function * SOLR search * @param bool $no_record * @return json * @internal param string $class class restriction */ function filter($no_log = false) { header('Cache-Control: no-cache, must-revalidate'); header('Content-type: application/json'); set_exception_handler('json_exception_handler'); $data = json_decode(file_get_contents("php://input"), true); $filters = isset($data['filters']) ? $data['filters'] : false; // experiment with delayed response time // sleep(2); $this->load->library('solr'); //restrict to default class $default_class = isset($filters['class']) ? $filters['class'] : 'collection'; if (!is_array($default_class)) { $this->solr->setOpt('fq', '+class:' . $default_class); } $this->solr->setFilters($filters); //test // $this->solr->setOpt('fq', '+spatial_coverage_centres:*'); //not recording a hit for the quick search done for advanced search if (!$no_log) { $event = array('event' => 'portal_search', 'ip' => $this->input->ip_address(), 'user_agent' => $this->input->user_agent()); if ($filters) { $event = array_merge($event, $filters); } ulog_terms($event, 'portal'); } //returns this set of Facets if ($default_class == 'activity') { foreach ($this->components['activity_facet'] as $facet) { if ($facet != 'temporal' && $facet != 'spatial') { $this->solr->setFacetOpt('field', $facet); } } } elseif ($default_class == 'collection') { foreach ($this->components['facet'] as $facet) { if ($facet != 'temporal' && $facet != 'spatial') { $this->solr->setFacetOpt('field', $facet); } } } else { foreach ($this->components['facet'] as $facet) { if ($facet != 'temporal' && $facet != 'spatial') { $this->solr->setFacetOpt('field', $facet); } } } //high level subjects facet // $subjects = $this->config->item('subjects'); // foreach ($subjects as $subject) { // $fq = '('; // foreach($subject['codes'] as $code) { // $fq .= 'subject_vocab_uri:("http://purl.org/au-research/vocabulary/anzsrc-for/2008/'.$code.'") '; // } // $fq.=')'; // $this->solr->setFacetOpt('query', // '{! key='.url_title($subject['display'], '-', true).'}'.$fq // ); // } //temporal facet $this->solr->setFacetOpt('field', 'earliest_year')->setFacetOpt('field', 'latest_year')->setOpt('f.earliest_year.facet.sort', 'count asc')->setOpt('f.latest_year.facet.sort', 'count'); //flags, these are the only fields that will be returned in the search $this->solr->setOpt('fl', 'id,type,title,description,group,slug,spatial_coverage_centres,spatial_coverage_polygons,administering_institution,researchers,matching_identifier_count,list_description'); //highlighting $this->solr->setOpt('hl', 'true'); $this->solr->setOpt('hl.fl', 'identifier_value_search, related_party_one_search, related_party_multi_search, related_activity_search, related_service_search, group_search, related_info_search, subject_value_resolved_search, description_value, date_to, date_from, citation_info_search'); $this->solr->setOpt('hl.simple.pre', '<b>'); $this->solr->setOpt('hl.simple.post', '</b>'); $this->solr->setOpt('hl.snippets', '2'); //extract sentence $this->solr->setOpt('hl.fragmenter', 'regex'); $this->solr->setOpt('hl.fragsize', '140'); $this->solr->setOpt('hl.regex.slop', '1.0'); $this->solr->setOpt('hl.regex.pattern', "\\w[^.!?]{400,600}[.!?]"); $this->solr->setOpt('hl.bs.type', "SENTENCE"); $this->solr->setOpt('hl.bs.maxScan', "30"); // $this->solr->setOpt('hl.useFastVectorHighlighter', "true"); //experiment hl attrs // $this->solr->setOpt('hl.alternateField', 'description'); // $this->solr->setOpt('hl.alternateFieldLength', '100'); // $this->solr->setOpt('hl.fragsize', '300'); // $this->solr->setOpt('hl.snippets', '100'); $this->solr->setFacetOpt('mincount', '1'); $this->solr->setFacetOpt('limit', '100'); $this->solr->setFacetOpt('sort', 'count'); $result = $this->solr->executeSearch(true); //fuzzy search if ($this->solr->getNumFound() == 0 && isset($filters['q'])) { $new_search_term_array = explode(' ', escapeSolrValue($filters['q'])); $new_search_term = ''; foreach ($new_search_term_array as $c) { $new_search_term .= $c . '~0.7 '; } // $new_search_term = $data['search_term'].'~0.7'; $this->solr->setOpt('q', 'fulltext:(' . $new_search_term . ') OR simplified_title:(' . iconv('UTF-8', 'ASCII//TRANSLIT', $new_search_term) . ')'); $result = $this->solr->executeSearch(true); if ($this->solr->getNumFound() > 0) { $result['fuzzy_result'] = true; } } $result['url'] = $this->solr->constructFieldString(); echo json_encode($result); }
function record_hit($page = 'home') { $event = array('event' => 'portal_page', 'page' => $page, 'ip' => $this->input->ip_address(), 'user_agent' => $this->input->user_agent()); ulog_terms($event, 'portal'); }