search-idea

skamster
2007-09-24
2013-05-17
  • skamster
    skamster
    2007-09-24

    heyho

    i use quixplorer and i like it very mutch.. most the clean code and the comments. so, i've an idea for search; as default the package found just exactly things. if i don't know the exactly name, i loose it.

    so i maked a little bit of my own code; it's not the best, but maybe a input ;)

    file: /.include/fun_search.php

    Code:

    function find_item($dir,$pat,&$list,$recur) {    // find items
        $handle=@opendir(get_abs_dir($dir));
        if($handle===false) return;        // unable to open dir
       
        while(($new_item=readdir($handle))!==false) {
            if(!@file_exists(get_abs_item($dir, $new_item))) continue;
            if(!get_show_item($dir, $new_item)) continue;
           
            // match?
    $pat1 = "^".$_POST['searchitem']."$";
    $pat2 = "^.*".$_POST['searchitem']."$";
    $pat3 = "^".$_POST['searchitem'].".*$";
    $pat4 = "^.*".$_POST['searchitem'].".*$";

    if((@eregi ($pat1,$new_item))||(@eregi( $pat2,$new_item))||(@eregi( $pat3,$new_item)) ||(@eregi( $pat4,$new_item))) {
    $list[]=array($dir,$new_item);
    }
           
            // search sub-directories
            if(get_is_dir($dir, $new_item) && $recur) {
                find_item(get_rel_item($dir,$new_item),$pat,$list,$recur);
            }
        }
       
        closedir($handle);
    }

    so, maybe it's help you a little bit, if not, delete the post.. :)

     
    • skamster
      skamster
      2007-09-24

      sorry, a little bit better..

      function find_item($dir,$pat,&$list,$recur) {    // find items
          $handle=@opendir(get_abs_dir($dir));
          if($handle===false) return;        // unable to open dir
         
      $pat1 = "^".$_POST['searchitem']."$";
      $pat2 = "^.*".$_POST['searchitem']."$";
      $pat3 = "^".$_POST['searchitem'].".*$";
      $pat4 = "^.*".$_POST['searchitem'].".*$";

          while(($new_item=readdir($handle))!==false) {
              if(!@file_exists(get_abs_item($dir, $new_item))) continue;
              if(!get_show_item($dir, $new_item)) continue;
             
              // match?

              if((@eregi ($pat1,$new_item))||(@eregi( $pat2,$new_item))||(@eregi( $pat3,$new_item)) ||(@eregi( $pat4,$new_item))) {
      $list[]=array($dir,$new_item);
      }
             
              // search sub-directories
              if(get_is_dir($dir, $new_item) && $recur) {
                  find_item(get_rel_item($dir,$new_item),$pat,$list,$recur);
              }
          }
         
          closedir($handle);
      }

       
    • The search inputfield already allows the usage of shell wildcards, i.e. that you can get what you want bye just typing *pat* in the inputfield. In my eyes, this change is not necessary.

      Bye the way, you just need one pattern to do what you want. $pat4 covers also all 3 other patterns, since a ".*" regexp also catches an empty string. So you can delete $pat1 to $pat3 and the eregi calls for it.

       
    • skamster
      skamster
      2007-11-14

      yeah, it was just my idea an i don't write a lot of code in php, also my example is bad, i think.

      the pattern, right, why not? i think, this method is good for peobles with programmers-knowledge, but what's with peobles who didn't know more than "press buttons"?

      so, i think, it's could be good with a field "exact-search".. like subfolders.. if this one is off, it's search like *file* .. what do you think?