The "File name" search, only search on the current folder. It does not search files inside sub directories. What I am missing?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jaffaralia’s picture

I also have the same problem. Can anyone point me in the right direction.

jaffaralia’s picture

Please find the patch

das-peter’s picture

Status: Active » Needs work

The "File name" search, only search on the current folder. It does not search files inside sub directories. What I am missing?

Nothing, this is by design.

I'm not sure how to proceed here. Searching over all files / folders would have to be covered in global way.
Just checking if there's a filename set wouldn't do it. E.h. the user still sees the navigation even thought the navigation isn't relevant at all - this is unpredictable behaviour.

@jaffaralia Thanks for the patch! I've checked it but as explained above we would need another approach to provide an unified approach for all "searches". Further it looks the code is more complex than necessary is there a reason you didn't use taxonomy_get_tree e.g. like this:

    $folders = array($this->value);
    $taxonomy_tree = taxonomy_get_tree(taxonomy_vocabulary_machine_name_load('media_folders')->vid, $this->value);
    foreach ($taxonomy_tree as $term) {
      $folders[] = $term->tid;
    }
jaffaralia’s picture

Now I corrected the code. Please check.

jaffaralia’s picture

Status: Needs work » Needs review

The last submitted patch, 2: nested_folder_search-2387943-9413075.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 4: nested_folder_search-2387943-9413075.patch, failed testing.

das-peter’s picture

@jaffaralia Thanks for re-organizing the code. Looks much simpler now :)
However, this won't change anything regarding my feedback that we need to come up with a proper way to achieve this without introducing "unpredictable behaviour".
So this still needs work - besides the test failures we've to look into.

bennybobw’s picture

I also think this is confusing. @das-peter, what do you mean when you say it is "unpredictable behaviour." Our users expect that if they search inside a folder, it will also search inside sub folders. This matches users' expected behavior based on desktop searches on Mac and Windows -- if you search inside a folder it also shows you results within subfolders.

bennybobw’s picture

Ah I think I see the issue here. When you are browsing without a search, the view should not show files within subfolders. However, when you are doing a search it makes sense to show the files within the subfolders.

bennybobw’s picture

I have a proposal for this. Add a checkbox to the filters section that says "Include subfolders in view." Toggling the checkbox will reload the view and show subfolders or not.

Then, in the "Media Files" column, it will show a breadcrumb like "Media Files > Folder 1" or if the subfolders are enabled "Media Files > Folder 1 (+ subfolders)"

bennybobw’s picture

Attaching a patch with the include subfolders checkbox.

bennybobw’s picture

Version: 7.x-3.0-beta3 » 7.x-3.x-dev
Status: Needs work » Needs review

Oops sorry, I forgot to change the issue status. I based my patch on the 3.x-dev version, so I'm changing the version as well.

Knud Frank’s picture

I have fixed the patch to now work correctly with subfolders.
As the where clause was always adding
AND( (field_data_field_folder.field_folder_tid IS NULL ) OR (field_data_field_folder.field_folder_tid = '1') )
the search was always based on the base folder (tid = '1').
I have now corrected this, so that all subfolders (8, 9) will be included in the search and the AND clause is no longer executed.
WHERE (( (file_managed.status IN ('1')) AND (file_managed.filename LIKE '%searchterm%' ESCAPE '\\') AND (field_data_field_folder.field_folder_tid IN ('1', '8', '9')) ))

  • das-peter committed 82f5b1f on 7.x-3.x
    Issue #2387943 by jaffaralia, bennybobw, Knud Frank, das-peter: Nested...
das-peter’s picture

Thanks all for working on this. I like the approach.
I ended up adjusting the patch(es) a bit. I still want to ensure that we find "orphaned" files in any case if accessing the root folder. So the IS NULL condition has to stay.
But if we just adjust the condition to always work with IN, we can easily combine both approaches.
Attached patch shows what I've committed.

The last submitted patch, 12: 2387943-subfolder-search-12.patch, failed testing.

The last submitted patch, 14: media_browser_plus_views_handler_area_navigation.patch, failed testing.

Status: Fixed » Closed (fixed)

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