Files not properly deleted from swish_fulltext

SomebodySysop - June 12, 2008 - 22:36
Project:Swish-E Indexer
Version:5.x-1.1
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

I found that there were files in swish_fulltext table that either whose paths had been changed or whose nodes had been deleted. My thought was to always delete all swish_fulltext records associated with a node anytime the node is submitted or deleted. Deleting by the filepath doesn't catch files whose filepaths have changed.

<?php
/**
* Implementation of hook_nodeapi(). Updates Full Text Information on Node Update.
*/
function swish_nodeapi(&$node, $op) {
  switch(
$op) {
    case
"insert":
    case
"update":
    case
"submit":
   
// Check if this node has any references in the files table
    // Note: we do this because other attachments might not be found in $node->file
   
$result = db_query("SELECT filepath FROM {files} WHERE nid = %d", $node->nid);
    if (
db_num_rows($result) && $node->nid) {
     
// If there's a result in files, then delete everything in swish_fulltext for this node and re-populate.
     
db_query("DELETE FROM {swish_fulltext} WHERE nid = %d", $node->nid);
      while (
$row = db_fetch_object($result)) {
       
$text = _swish_do_text_extract($row->filepath);
       
// Do a delete and reinsert, in case anything has gone wrong before and the row isn't there already
       
db_query("DELETE FROM {swish_fulltext} WHERE filepath = '%s'", $row->filepath);
       
db_query("INSERT INTO {swish_fulltext} (filepath, nid, `fulltext`) VALUES ('%s',%d,'%s')", $row->filepath, $node->nid, $text);
      }
    }
    break;
    case
"update index":
     
// return text to be placed in the search index
   
break;
    case
"search result":
     
// return items to be added to search results
   
break;
    case
"delete":
   
// Check if this node has any references in the files table
    // Note: we do this because other attachments might not be found in $node->file
   
$result = db_query("SELECT filepath FROM {files} WHERE nid = %d", $node->nid);
    if (
db_num_rows($result) && $node->nid) {
     
// If there's a result, then delete everything in swish_fulltext for this node.
     
db_query("DELETE FROM {swish_fulltext} WHERE nid = %d", $node->nid);
    }
    break;
   }
}
?>

Perhaps I'm way off base on this, but this seems to more accurately help make sure we don't have files in swish_fulltext that shouldn't be there.

#1

SomebodySysop - June 12, 2008 - 23:01
Status:postponed (maintainer needs more info)» needs review
 
 

Drupal is a registered trademark of Dries Buytaert.