Hi, just a feature that would be handy is either a way of excluding attachment types (say with a comma delimited list) or only include attachments that helpers are defined for.... maybe even by content type also.

Example; I have a content type 'Article' and currently only 2 articles with 2 attached pdfs, but my index shows 89 files indexed which looks like it's indexing all attachments (including attached jpgs, pngs etc.).

CommentFileSizeAuthor
#9 search_files_attachments.module.txt10.11 KBduncanc

Comments

dean.p’s picture

Title: Exclude attachent types » Exclude attachment types

*Edit: Sorry, misspelling in the title *fixed*

jpcwebb’s picture

I'd definately support this feature - my site has hundreds of image files uploaded, any only a handful of pdfs and other files, so the search indexing is wasting a lot of time churning through all the images before it gets to the pdfs.

duncanc’s picture

For search_files_attachments to limit indexing to only those files that have helpers defined, then this sql needs to be added to queries in two places

             join {search_files_helpers} h
              on SUBSTRING_INDEX(f.filename,'.',-1) = h.extension 

1) add to two queries in the 'status' processing within function search_files_attachments_search so that the correct counts are returned
2) add to the query in the search index processing within function search_files_attachments_update_index so that only files whose file type has a helper are selected.

jpcwebb’s picture

Thanks for the tip - could this be made into a patch?

jpcwebb’s picture

Hmm, even applying these changes does not seem to prevent the search_dataset table from filling up with hundreds of rows with no data for type 'search_files_att' - that's what I'd like to avoid

duncanc’s picture

I forgot to mention that I had to uninstall the module in order to remove the existing rows in search_dataset, and then reinstall.

Or you can run the sql manually, see the file search_files_attachments.install

function search_files_attachments_uninstall() {
  db_query("DELETE FROM {search_dataset} WHERE type = 'search_files_att'");
  db_query("DELETE FROM {search_index} WHERE type = 'search_files_att'");
  db_query("DELETE FROM {variable} WHERE name LIKE 'search_files_attachments_%'");
}

Then re-index again.

Having looked at the code, I'm not sure that my suggestion is quite enough. The module uses the files table to drive the processing, but I think it should use the upload table instead. That would limit it to files attached to nodes instead of all possible files, as it currently does.
But that's a bigger change!

jpcwebb’s picture

I agree that would cut down the base index selection by a significant margin

duncanc’s picture

Here is a modified search_files_attachments.module that includes the SQL changes I explained previously. The change limits indexing to only those attachments which have a helper defined.

It is based on version 6.x-2.0-beta4, the current recommended release.

To remove the unnecessary rows from search_dataset table you will need to first disable the module "Search files in attachments", and then uninstall it on the module administration page.
Then replace the distributed search_files_attachments.module with the modified file, enable the module, and trigger an index update on the administration page.

Feedback welcome!

duncanc’s picture

StatusFileSize
new10.11 KB

Forgot to attach the file - rename to remove the .txt extension.

candelas’s picture

Version: 6.x-2.0-beta4 » 6.x-2.x-dev
Priority: Normal » Major
Status: Active » Needs review

thanks @duncanc, i have applied your patch and works perfect.
i think it should be on the dev version, since it has not sense to index files that you cant translate to the search index... and it is causing that crons hangs with big photo files...

@duncanc made this one year ago and i am working with the dev version at the moment, so i report here the changes for this version. i have looked among 6.x.2.x-dev, 6.x.2.0-beta4 and duncanc txt line by line.
i dont know how to make patches and i have to finish a work. please someone that knows howto, make a patch and submit, since it is important and makes this supermodule not to have problems with crons... and make search index much clean:

line 62
from

    case 'status':
      $total = db_result(db_query("
        SELECT count(*) FROM {files} f
        JOIN {search_files_helpers} h
        ON SUBSTRING_INDEX(f.filename,'.',-1) = h.extension 
        WHERE status = 1
        "));
      $remaining = db_result(db_query("
                     SELECT count(*)
                     FROM {files} AS f
                     LEFT JOIN {search_dataset} AS d
                     ON d.sid = f.fid
                     WHERE (
                       d.type = 'search_files_att'
                       AND f.status = 1
                       AND (d.sid IS NULL OR d.reindex <> 0)
                     )
                   "));
      return array('remaining' => $remaining, 'total' => $total);

to

    case 'status':
      $total = db_result(db_query("
        SELECT count(*) FROM {files} f
        JOIN {search_files_helpers} h
        ON SUBSTRING_INDEX(f.filename,'.',-1) = h.extension 
        WHERE status = 1
        "));
      $remaining = db_result(db_query("
                     SELECT count(*)
                     FROM {files} AS f
                     JOIN {search_files_helpers} h
                     ON SUBSTRING_INDEX(f.filename,'.',-1) = h.extension 
                     LEFT JOIN {search_dataset} AS d
                     ON d.sid = f.fid
                     WHERE (
                       d.type = 'search_files_att'
                       AND f.status = 1
                       AND (d.sid IS NULL OR d.reindex <> 0)
                     )
                   "));
      return array('remaining' => $remaining, 'total' => $total);

line 196 (moved because i pasted the code from before and i have also applied patch in http://drupal.org/node/965474#comment-3782776 for problems with encoding characters sets (works))

from

 $result = db_query_range("
              SELECT f.fid, f.filepath, d.reindex
              FROM {files} AS f
              LEFT JOIN {search_dataset} AS d
              ON d.sid = f.fid
              WHERE (
                d.type = 'search_files_att' AND
                d.reindex <> 0
              )
              UNION DISTINCT
              SELECT f.fid, f.filepath, NULL
              FROM {files} AS f
              WHERE fid NOT IN (
                SELECT sid
                FROM {search_dataset} AS d
                WHERE d.type = 'search_files_att'
              )
              ORDER BY reindex ASC, fid
            ", 0, $limit);

to

   $result = db_query_range("
              SELECT f.fid, f.filepath, d.reindex
              FROM {files} AS f
              LEFT JOIN {search_dataset} AS d
              ON d.sid = f.fid
              WHERE (
                d.type = 'search_files_att' AND
                d.reindex <> 0
              )
              UNION DISTINCT
              SELECT f.fid, f.filepath, NULL
              FROM {files} AS f
              JOIN {search_files_helpers} h
              ON SUBSTRING_INDEX(f.filename,'.',-1) = h.extension 
              WHERE fid NOT IN (
                SELECT sid
                FROM {search_dataset} AS d
                WHERE d.type = 'search_files_att'
              )
              ORDER BY reindex ASC, fid
            ", 0, $limit);

i have tested and my cron goes much better and not empty records on the table.
@duncanc thanks a lot!!!

jrglasgow’s picture

Status: Needs review » Fixed

I have committed this code

In the future it would be better to have a patch instead ofa replacement file or code in the comment.

to learn to make a patch you can click on the "Version Control" tab for the module, select the proper branch for the module and follow the instruction to clone the repo. then make changes to the file, and then follow instructions to create a patch

candelas’s picture

thanks, i will do it

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.