Menu

"AND" of multiple patterns (conjunction)

Anonymous
2018-04-12
2019-11-06
  • Anonymous

    Anonymous - 2018-04-12

    I'd appreciate an option to do a search on multiple words at the same time
    for an AND search.

    Example: I want to search for an author named "JOHN SMITH". The filename
    name could be saved as "J SMITH", "JOHN SMITH", or "SMITH, JOHN". I'd like
    to enter "j smith" and have all 3 occurrences returned. It would be nice to
    enter something like "j+smith" or "j smith" and have a search on multiple
    words.

     
    • -

      - - 2018-04-12

      Neat idea! I'm not sure what kind of syntax for that would be a good idea though. Something simple like + or & won't cut it since those can be valid file name characters too, unless I break the current behavior and require users to use a backslash to escape those characters from now on (which I would rather not do). Or unless I introduce a new mode, like how regexes begin with >. But in that case the syntax needs to be robust enough that I don't have to introduce a new mode again later for new functionality. Any ideas?

       

      Last edit: - 2018-04-12
    • -

      - - 2018-04-12

      As a workaround in the meantime, remember that you can always filter by one of your keywords, then right-click the entries, dump the table, then do the rest of your filtering in another program (like Excel). It's annoying, but it can still be done in batch and should be a viable alternative if you only need to do this occasionally.

       

      Last edit: - 2018-04-12
    • Mike

      Mike - 2019-11-06

      You could send a "brute force" search query via AutoHotkey.

      InputBox, txt, Enter name, Enter the name., , 500, 115
      If (txt > "")
      {
       word := StrSplit(txt, A_Space)
       fi := SubStr(txt,1,1)
       fn := word[1]
       ln := word[2]
       Send, >.*(%fi% %ln%|%fn% %ln%|%ln%, %fn%).*
      }
      

      You'll get some extra files due to the .*, so adjust as needed.

       
  • Anonymous

    Anonymous - 2018-04-12

    How about beginning a line with a colon (non-valid filename character) so you would enter ":j smith"?

     
    • -

      - - 2018-04-12

      Nope that won't work. Colons are valid both for drive letters and for alternate data streams, so right now that would list any file that has a stream named "j smith".

       
  • Anonymous

    Anonymous - 2018-04-13

    How about a double greater than sign? ">>j smith"
    I do a lot of searches like this using "Index Your Files".

     
    • -

      - - 2018-04-13

      Haha, well technically the first > implies regex mode, so the second one means you want a regex beginning with >. But that would probably be useless, so this could be made to work.

      I'm afraid my point may have been lost here, though. I wasn't asking what character to begin with. That's easy enough to solve (e.g. < would work). I was asking, more generally, what the syntax should look like.

      For example, if the only thing I do is solve your AND problem with >>, then tomorrow someone will ask that I solve the OR problem, so suddenly I'll need another syntax for that (so should I use >>> then?!). Then the next day someone else will come along and complain that they can only AND two words, not two regexes, etc... it can become arbitrarily complicated.

      And it's not just this... who knows, maybe sometime in the future someone will get the idea that users should be able to type something else, like commands, into the box, such as notepad foo. Now suddenly I'll need an entirely new syntax for commands, and if I've already used up all the easy mode indicators for basic things (>, <, etc.) then I can't come up with an easy syntax for that.

      What I'm trying to figure out is, what kind of syntax can I introduce that is:
      (a) easy to use,
      (b) not too difficult to implement, and
      (c) extensible in the future.

      It's easy enough for me to solve the specific problem you're asking, but then the solution will be so limited that I can't extend it in the future if I need to. I'm trying to avoid that problem.

      (If you don't have any ideas though, that's fine; I'll try to come up with something myself when I get the chance. I was just asking in case you might already have some thoughts on this.)

       
  • Anonymous

    Anonymous - 2018-04-13

    Well, I just wrote a Search for my webpage. I have 2 fields that I search on; the TITLE and ARTIST of a song. Therefore, I used the AND search for the site.

    You are correct, my Search request may be more of a request for me but I would think anyone searching music files would be interested.

    I also think an average user does not konw how to use regular expressions.

     
  • Anonymous

    Anonymous - 2018-04-20

    Simple PHP code to find a Seacrh String using AND:

    $find = trim(str_replace(' ', ' ', $find)); # trim excess spaces
    $findarray = explode(' ', $find); # turn Search string into an array
    $found = TRUE; # assume string is found
    $findstring = $filename; # Set $findstring to the current filename
    for($b = 0; $b < count($findarray); $b++) { # loop through $findarray
    if(stripos($findstring, $findarray[$b]) === FALSE) $found = FALSE; # if array value is not find the set it to FALSE
    }
    if($found == FALSE) continue; # move on to next filename with displaying
    echo $filename; # display the found filename

     
    • -

      - - 2018-04-20

      Haha aw, thanks! Main thing I need right now is a good design and a good chunk of time to implement it, but thanks for trying to help with the implementation!

       
    • -

      - - 2018-05-06

      Hi! I've uploaded a new version that should make this possible with regexes.
      (In fact, it was already almost possible, but it was broken due to a bug.)

      To search for John AND Smith, you can now use (?=...) as follows:

      >(?=.*John[^\\]*\\?$)(?=.*Smith[^\\]*\\?$).*
      

      You can also add more terms by inserting additional similar (?=...) clauses.

      It will be slower than a normal search, but hopefully it will still be usable.

       

      Last edit: - 2018-05-07
  • Anonymous

    Anonymous - 2019-10-17

    (?=.John[^\]\?$)(?=.Smith[^\]\?$).*

    Yes, that looks like a very simple and intuitive syntax indeed. Just meaning AND.

     
    • Anonymous

      Anonymous - 2019-10-17

      I never claimed it was easy or intuitive. I was just trying to help you find a way to do this, otherwise you wouldn't be able to do this at all.

       

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.