Skip to content

Commit

Permalink
Should fix issue of continually adding items to search index instead …
Browse files Browse the repository at this point in the history
…of updating existing ones [#612 state:resolved milestone:2.0.7]
  • Loading branch information
dleffler committed May 22, 2012
1 parent b318ee1 commit 663d191
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
18 changes: 12 additions & 6 deletions framework/core/controllers/expController.php
Expand Up @@ -694,15 +694,21 @@ function addContentToSearch() {
foreach ($content as $cnt) {
$origid = $cnt['id'];
unset($cnt['id']);

// get the location data for this content
if (isset($cnt['location_data'])) $loc = expUnserialize($cnt['location_data']);
$src = isset($loc->src) ? $loc->src : null;

$sql = "original_id=".$origid." AND ref_module='".$this->classname."'";
$oldindex = $db->selectObject('search',$sql);
if (!empty($oldindex)) {
$search_record = new search($oldindex->id, false, false);
$search_record->update($cnt);
} else {
$search_record = new search($cnt, false, false);
}

//build the search record and save it.
$search_record = new search($cnt, false, false);
$search_record->original_id = $origid;
$search_record->posted = empty($cnt['created_at']) ? null : $cnt['created_at'];
// get the location data for this content
if (isset($cnt['location_data'])) $loc = expUnserialize($cnt['location_data']);
$src = isset($loc->src) ? $loc->src : null;
$link = str_replace(URL_FULL,'', makeLink(array('controller'=>$this->baseclassname, 'action'=>'show', 'id'=>$origid, 'src'=>$src)));
// if (empty($search_record->title)) $search_record->title = 'Untitled';
$search_record->view_link = $link;
Expand Down
7 changes: 3 additions & 4 deletions framework/modules/search/models/search.php
Expand Up @@ -38,8 +38,7 @@ public function getSearchResults($terms, $readonly = 0) {
// get the search terms
//$terms = $this->params['search_string'];

if (SAVE_SEARCH_QUERIES && $readonly == 0)
{
if (SAVE_SEARCH_QUERIES && $readonly == 0) {

if(INCLUDE_ANONYMOUS_SEARCH == 1 || $user->id <> 0) {
$queryObj = new stdClass();
Expand Down Expand Up @@ -70,15 +69,15 @@ public function getSearchResults($terms, $readonly = 0) {
// search results due to permissions...not sure what to do about that.
$recs = $records;
for ($i=0; $i < count($records); $i++) {
if($records[$i]->ref_type == 'product'){
if($records[$i]->ref_type == 'product') {
$score = $records[$i]->score;
if (!product::canView($records[$i]->original_id)) unset($recs[$i]);
/*else
{
$records[$i] = new product($records[$i]->original_id);
$records[$i]->score = $score;
}*/
}else if ($records[$i]->ref_type == 'section') {
} else if ($records[$i]->ref_type == 'section') {
$section = $db->selectObject('section', 'id='.$records[$i]->original_id);
if (empty($section) || !navigationmodule::canView($section)) {
unset($recs[$i]);
Expand Down

0 comments on commit 663d191

Please sign in to comment.