473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

boolean search expressions?

Hi,

I'm trying to add a search facility to a page that looks for matches in one,
other or both memo fields of a database. The code below works fine if the
visitor types in one word, or the term just happens to exist in one of the
queried fields.

What I'd really like is for a visitor to type in an expression, or query in
the same format as you would use in a search engine and it would find
appropriate matches. Any ideas how I can modify the code below to do this?

Thanks

set rsData = con.execute("select topic, title, ID, description from journals
where articletext LIKE '%" & searchstring & "%' OR description Like '%" &
searchstring & "%' ORDER BY dateno DESC")
Jul 19 '05 #1
5 2592
David wrote:
Hi,

I'm trying to add a search facility to a page that looks for matches
in one, other or both memo fields of a database. The code below
works fine if the visitor types in one word, or the term just happens
to exist in one of the queried fields.

What I'd really like is for a visitor to type in an expression, or
query in the same format as you would use in a search engine and it
would find appropriate matches. Any ideas how I can modify the code
below to do this?

Thanks

set rsData = con.execute("select topic, title, ID, description from
journals where articletext LIKE '%" & searchstring & "%' OR
description Like '%" & searchstring & "%' ORDER BY dateno DESC")


"Memo" implies Access, right? Please don't make us guess. Always tell us the
type and version of database you are using. It is almost always relevant.

Anyways, I think we need to see specs for the expression syntax you want the
visitor to use. Depending on the search engine you are talking about, the
syntax can be very simple, or very complex. So tell us what you mean by "the
same format as you would use in a search engine".

Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #2
"Memo" implies Access, right? Please don't make us guess. Always tell us the type and version of database you are using. It is almost always relevant.
I'm sorry - I forgot that bit. Yes, the database is Access (office2000
version)
Anyways, I think we need to see specs for the expression syntax you want the visitor to use. Depending on the search engine you are talking about, the
syntax can be very simple, or very complex. So tell us what you mean by "the same format as you would use in a search engine".


Ideally I'd like the visitor to be able to type in an expression such as:-
model railway in england
into the search box. If they want to type in all the " ' + type characters
you can use in a search engine I'd strip them from the querystring.

So, if the visitor types in model railway in england, then the search would
look in both memo fields to see if any of the words in that expression
appeared in either field of the database.

I'd go down the route of the code stripping common words like "of at and in"
etc from the querystring.

Hope this provides more information. I don't want a fully featured search
engine - just the ability to see if any of the words in a search string are
in the database.

Thanks
Jul 19 '05 #3
David wrote:
"Memo" implies Access, right? Please don't make us guess. Always
tell us the type and version of database you are using. It is almost
always relevant.


I'm sorry - I forgot that bit. Yes, the database is Access (office2000
version)

Anyways, I think we need to see specs for the expression syntax you
want the visitor to use. Depending on the search engine you are
talking about, the syntax can be very simple, or very complex. So
tell us what you mean by "the same format as you would use in a
search engine".


Ideally I'd like the visitor to be able to type in an expression such
as:- model railway in england
into the search box. If they want to type in all the " ' + type
characters you can use in a search engine I'd strip them from the
querystring.

So, if the visitor types in model railway in england, then the search
would look in both memo fields to see if any of the words in that
expression appeared in either field of the database.

I'd go down the route of the code stripping common words like "of at
and in" etc from the querystring.

Hope this provides more information. I don't want a fully featured
search engine - just the ability to see if any of the words in a
search string are in the database.

Thanks


That's a relief: you're not going to allow the use of "exclusion words".

You're options are very limited, since you are not limiting the number of
words being typed. I see no way to avoid concatenating a potentially long
dynamic sql statement, which will probably perform horribly. If you were
using SQL Server, you could use the Full Text Search functionality, but ....

Anyways, you'll need to carry out your plan to break up the search string
into discrete words (you can use Split for this):
wordarray = split(searchstring, " ")

and then loop through the array, adding an OR clause to the query for each
word in the array:
where articletext LIKE '%" & wordarray(0) & "%' OR description Like '%" & _
wordarray(0) & "%' OR articletext LIKE '%" & wordarray(1) & _
"%' OR description Like '%" & wordarray(1) & "%' etc.

Did I mention that this will probably perform horribly?

HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #4
Bob Barrows wrote:

Anyways, you'll need to carry out your plan to break up the search
string into discrete words (you can use Split for this):
wordarray = split(searchstring, " ")

and then loop through the array, adding an OR clause to the query for
each word in the array:
where articletext LIKE '%" & wordarray(0) & "%' OR description Like
'%" & _ wordarray(0) & "%' OR articletext LIKE '%" & wordarray(1) & _
"%' OR description Like '%" & wordarray(1) & "%' etc.

Did I mention that this will probably perform horribly?

Hmm, I wonder if a UNION query would perform better ... It can't hurt to
test it:

sSQL = "select dateno, topic, title, ID, description from journals " & _
"where articletext LIKE '%" & searchstring1 & "%' " & _
"UNION select dateno, topic, title, ID, description from journals " & _
"where description Like '%" & searchstring1 & "%' " & _
"UNION select dateno, topic, title, ID, description from journals " & _
"where articletext LIKE '%" & searchstring2 & "%' " & _
"UNION select dateno, topic, title, ID, description from journals " & _
"where description Like '%" & searchstring2 & "%' " & _
"ORDER BY dateno DESC")

HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #5

"Bob Barrows" <re******@NOyahoo.SPAMcom> wrote in message
news:uN**************@TK2MSFTNGP11.phx.gbl...
Bob Barrows wrote:

Anyways, you'll need to carry out your plan to break up the search
string into discrete words (you can use Split for this):
wordarray = split(searchstring, " ")

and then loop through the array, adding an OR clause to the query for
each word in the array:
where articletext LIKE '%" & wordarray(0) & "%' OR description Like
'%" & _ wordarray(0) & "%' OR articletext LIKE '%" & wordarray(1) & _
"%' OR description Like '%" & wordarray(1) & "%' etc.

Did I mention that this will probably perform horribly?

Hmm, I wonder if a UNION query would perform better ... It can't hurt to
test it:

sSQL = "select dateno, topic, title, ID, description from journals " & _
"where articletext LIKE '%" & searchstring1 & "%' " & _
"UNION select dateno, topic, title, ID, description from journals " & _
"where description Like '%" & searchstring1 & "%' " & _
"UNION select dateno, topic, title, ID, description from journals " & _
"where articletext LIKE '%" & searchstring2 & "%' " & _
"UNION select dateno, topic, title, ID, description from journals " & _
"where description Like '%" & searchstring2 & "%' " & _
"ORDER BY dateno DESC")


Thanks Bob - I'll try this.

David
Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mad Scientist Jr | last post by:
Has anyone worked on code that that can parse evaluation expressions (could be numbers or strings) like ( ( "dog" = "dog" ) or "foo" = "bar" ) and ("cow" = "bat" and "bye" = "hi") or ("math" =...
2
by: webposter | last post by:
Hi, I am looking for information on a data structure (and associated algorithm) to do short-circuit evaluation of boolean expressions and haven't found a single one even after googing for two...
6
by: DC | last post by:
Hi, I am programming a search catalogue with 200000 items (and growing). I am currently using the SQL Server 2000 fulltext engine for this task but it does not fit the requirements anymore. ...
2
by: ajitgoel | last post by:
Hi; I need some simple help with my regular expressions. I want to search my input text for all the boolean variables which do not start with bln. i.e I want to match "bool followed by 1 or...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
4
by: lucky | last post by:
hi there!! i'm looking for a code snipett wich help me to search some words into a particular string and replace with a perticular word. i got a huge data string in which searching traditional...
7
by: pyluke | last post by:
I'm parsing LaTeX document and want to find lines with equations blocked by "\", but not other instances of "\" so, in short, I was to match "\" to add to this, I also don't want lines that...
16
by: Shawnk | last post by:
I would like to perform various boolean operations on bitmapped (FlagsAttribute) enum types for a state machine design as in; ------------------- enum portState { Unknown, Open,
47
by: Henning_Thornblad | last post by:
What can be the cause of the large difference between re.search and grep? This script takes about 5 min to run on my computer: #!/usr/bin/env python import re row="" for a in range(156000):...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.