Hi AutoHotkey Experts,
I wrote an AHK program that searches for a string in plain text files. It offers what I call a "Simple" search that searches for an entire phrase (either case sensitive or case insensitive) and also offers a RegEx search. It uses StringReplace to determine the number of occurrences found in a Simple search and RegExReplace to determine the number of occurrences found in a RegEx search.
As I have discovered that many users are not thrilled with trying to figure out RegEx searching, I'd like to offer a Boolean search capability - specifically, AND, OR, NOT. Ideally, I'd like it to support parentheses to determine precedence, but if that's too tough, I could live with evaluating NOT first, AND second, and OR third. I'm fine with saying that the Boolean search cannot search for AND, OR, NOT - that is, they are always interpreted as Boolean operators, not as search strings.
Is anyone aware of AHK code that can already do this or provide a good starting point for it? I'd be very grateful. Thanks much, Joe
Boolean Search - AND, OR, NOT
- JoeWinograd
- Posts: 2203
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Boolean Search - AND, OR, NOT
you can use regex with |, used it as OR and use it as AND. To use it as AND you use subpatterns, is both subpatters are found you can say AND result is 1.
- JoeWinograd
- Posts: 2203
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Boolean Search - AND, OR, NOT
Hi meimyself,
Thanks for the reply. Yes, I understand that it's doable with RegEx, which is an extremely powerful search technique, but based on lots of experience with lots of "typical" users, RegEx just isn't going to fly. My experience is that they feel comfortable with Boolean searches using AND, OR, NOT, but training them on RegEx is a losing battle (I'm not even an expert myself on it). Other software developers may have different experiences with users of their programs, but that's been my experience, so I'd really like to find a way for my users to issue a Boolean search with the AND, OR, NOT operators. Regards, Joe
Thanks for the reply. Yes, I understand that it's doable with RegEx, which is an extremely powerful search technique, but based on lots of experience with lots of "typical" users, RegEx just isn't going to fly. My experience is that they feel comfortable with Boolean searches using AND, OR, NOT, but training them on RegEx is a losing battle (I'm not even an expert myself on it). Other software developers may have different experiences with users of their programs, but that's been my experience, so I'd really like to find a way for my users to issue a Boolean search with the AND, OR, NOT operators. Regards, Joe
Re: Boolean Search - AND, OR, NOT
I think that he was saying that you could allow the users to enter searches using AND / OR, then you would convert the search to regex.
- JoeWinograd
- Posts: 2203
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Boolean Search - AND, OR, NOT
Morpheus,
Ah, I missed that. As I already mentioned, I'm not a RegEx expert myself, so I'll need some help here. I get that "|" is OR (the gray|grey example at the AHK RegEx QuickRef). How would I use subpatterns to implement AND? How about NOT?
An example would be helpful. Let's say the user is searching for a page that has:
autohotkey AND comspec OR runwait NOT unix
Using default precedence of NOT first, AND second, OR third, this would find pages that do not have "unix" but do have either (1) both "autohotkey" and "comspec" or (2) "runwait". What is the RegEx equivalent search? Thanks, Joe
Ah, I missed that. As I already mentioned, I'm not a RegEx expert myself, so I'll need some help here. I get that "|" is OR (the gray|grey example at the AHK RegEx QuickRef). How would I use subpatterns to implement AND? How about NOT?
An example would be helpful. Let's say the user is searching for a page that has:
autohotkey AND comspec OR runwait NOT unix
Using default precedence of NOT first, AND second, OR third, this would find pages that do not have "unix" but do have either (1) both "autohotkey" and "comspec" or (2) "runwait". What is the RegEx equivalent search? Thanks, Joe
Re: Boolean Search - AND, OR, NOT
OR regexmatch every search text
;text = test autohotkey AND comspec
;text = text autohotkey testing
;text = letter comspec testing
;text = autohotkey AND comspec OR runwait NOT unix
text = autohotkey AND comspec OR runwait
RegExMatch(text,"autohotkey",m)
s1:=m
RegExMatch(text,"comspec",m)
s2:=m
RegExMatch(text,"runwait",m)
s3:=m
RegExMatch(text,"unix",m)
s4:=m
if (!s4 AND (s1 and s2 or s3))
MsgBox Boolean Success
OR use ifinstring if they are not using any regex patterns.
;text = test autohotkey AND comspec
;text = text autohotkey testing
;text = letter comspec testing
;text = autohotkey AND comspec OR runwait NOT unix
text = autohotkey AND comspec OR runwait
RegExMatch(text,"autohotkey",m)
s1:=m
RegExMatch(text,"comspec",m)
s2:=m
RegExMatch(text,"runwait",m)
s3:=m
RegExMatch(text,"unix",m)
s4:=m
if (!s4 AND (s1 and s2 or s3))
MsgBox Boolean Success
OR use ifinstring if they are not using any regex patterns.
- JoeWinograd
- Posts: 2203
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Boolean Search - AND, OR, NOT
Thanks, meimyself, and to everyone else who replied earlier, but I think that RegEx isn't going to work out for this requirement. I've decided to try a different approach, so please take a look at my new topic. Thanks, Joe