Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Advanced String Searching 2

Status
Not open for further replies.

Guern

Programmer
Jun 22, 2001
91
0
0
GB
Hi,

Does anyone know of a class, control, etc. that will provide me with the following?

I want to be able to search strings with search engine style queries such as
("paul smith" and "visual basic") or "free wine"
etc.
Someone must have done this already!? Seems silly to re-invent the wheel if someones already got some tried and tested code.

Thanks.

Paul
 
'Haven't tried this, but you can

***************************************************************
' Name: Highlite a string within another string
' Description:when the sub is called a string is searched in anot
' her string and then highlited. when the sub is called again the n
' ext instance of that string is highlited.
' By: Ian Watt
'
'
' Inputs:None
'
' Returns:None
'
'Assumes:a command button called cmdFindNext
a text box name txtSearchFor which will contain the text you want to look for
and a text box named txtSearchIn which is the text box that will be searched.
'
'Side Effects:None
'
'Code provided by Planet Source Code(tm) (' e-Code.com) 'as is', without warranties as to performance, fitnes
' s, merchantability,and any other warranty (whether expressed or i
' mplied).
'This code is for personal private or personal business use only
' and may not be redistributed or duplicated in any format without
' express written consent from Planet Source Code or Exhedra Soluti
' ons, Inc.
'***************************************************************

Option Explicit
Dim StartPosition


Private Sub cmdFindNext_Click()


StartPosition = InStr(StartPosition + 1, txtSearchIn, txtSearchFor)
If StartPosition <= 0 Then Exit Sub
txtSearchIn.SelStart = StartPosition - 1
txtSearchIn.SelLength = Len(txtSearchFor)
txtSearchIn.SetFocus
End Sub



Private Sub Form_Load()

StartPosition = 0
End Sub
 
Thx, but not what I was looking for. What I want is kind of InStr on steriods!

I want to be able to issue a search string (search engine style) and get a true or false back as to whether the string met my criteria or not.

Something like does this string contain the works like and toffee, but not chocolate...
 
I have not seen such a procedure in VB/A. It could be interesting. In what manner / situation would you use this? You would need to pass a text object reference and the Search string (parameters) to the function. From your second post, you would just return a boolean to denote wheather the search conditions were met. So I assume that you are only passing a single text object to the routine, not saying 'Search all .Doc fles within the directory structure ...' and return the fully qualified path of each which meet the criteria?

Anonther concer would be the 'construction' of the search string. Would you have this JUST be the response to an input box, or would you 'force' the string of parameters to be logically correct by having the user 'fill in' the blanks and select punctuation (e.g. force matching parens and quotes ... )?

Would you attempt to have the search open ended (put in as many terms and relationships as the user is able to think of) or limit the number and or type of items and relationships between the tokens?

If you are familiar with UNIX, how different would htis process be from the standard 'grep'?

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Hi,

Yes, I think you've understood what I want pretty well. One of the uses I have for this routine would be to search the input from many small files and then categorise them via the use of queries specific to each criteria. I have other uses for it as well though. So a string comparison would be more flexible for me. I can easily read the file into a string for processing.

I imagined it as you did, a call to a routine passing both the string and the criteria you want it to match. I just need to know whether the criteria is met or not, so a True of False would be fine.

I'd like to be able to issue querys of the same type of flexibility as a normal search engine. Nothing to complex. I'd like to keep it open ended to get the maximum benifit if possible.

I'm afraid I'm not really familliar with Grep, alhtough from what I've seen it looks more like pattern matching than the sort of search engine type query language I was looking for?


Regards,

Paul
 
O.K.

This is 'interesting' but I think it is far from trivial. I do not think the actual searching is all that hard. The difficult part would be the parseing and validation of the search string into its components and logical attributes into specific Tokens. I will 'thunk' about it some. I think that - within some limits it is not beyond the limits of what I can contribute. If you have specific wants /needs please post them. It could clarify my thinking.

Grep is a pattern matching program - but it is much more sophisticated than a simple string search. The UNIX acronym stands for Get Regular EsPression, and it can be set to find (and replace) almost any concieveable pattern. I do not rember all of the details, but I think a full version could be 'convinced' to do most all of what you want. I will try to look for the source code of the version I have and review it to see what needs to be added.

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Meant to answer this before. VBScript comes with a COM object for handling regular expressions which, naturally, can be used in VB.

Look for and add the following reference to your project:

Microsoft VBScript Regular Expressions

MSDN carries a bunch of documentation on the subject.
 
Ooh! Thanks very much...

Off to do some research now :)
 
I might be able to use this... Thanks. The pattern matching looks very comprehensive for finding certain phrases etc.

I'm still not sure how to do a simple expression such as contains '(food AND drink) OR bervarages' yet though, but I'll keep reading!
 
That's the problem with Regular Expressions. They're very powerful, but it can be a bit of struggle getting your mind around how to get them to do what you want...
 
I've tried to refererence Microsoft VBScript Regular Expressions and it doen't show up in my Project references menu. So how do I make it accessible?

I use:
* VB5
* Win 98

I've downloaded version 5.6 of the scripting engine and included that as a Component but all that gives me is Microsoft VBScript Globals, which as far as I can see does not expose the regular expressions object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top