472,337 Members | 1,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Counting matches

Hi,

This is really more of a MySQL question than PHP per se, but the only
MySQL group my newserver carries seems to be pretty quiet, so I
thought I'd ask here.

What I am trying to do is determine the number of terms which match a
field in the database where an initial string of multiple words has
been broken up into single terms and the SQL statement is built by
looping through each term separately, something like this:

$original_string = "this is a test string"

// code to remove stop words/common terms leaves

$trimmed = "this test string"

// this is then exploded at the space into an array of its constituent
words. This array is then looped over to pass each word to an SQL
query thus

$SQL = "select * from main where"

while(there are terms){

$SQL .= "Title like '%" . $term . "%' OR"

}

// this would lead, using the above example, to an SQL query which
looks like this:

$SQL = "SELECT * FROM main WHERE Title like '%this%' OR Title like
'%test%' OR Title like '%string%'

What I need to do is to check how many of the terms actually match
something. Is there any way, either in MySQL or with the result array
in PHP, to determine this?

Am I on completely the wrong course (as it seems to me at the
moment...)

tia

Chris

Jul 17 '05 #1
3 1292
On Wed, 18 May 2005 10:29:15 +0100, Chris wrote:
What I need to do is to check how many of the terms actually match
something.


I think the best way might be to maintain a separate index table with
terms. New search terms will be a bit slower. Alternatively, you could
just, in addition to your original query, have separate queries for each
term (using count() or using the rowcount of each result).
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #2
On Wed, 18 May 2005 11:49:14 +0200, Ewoud Dronkert
<fi*******@lastname.net.invalid> wrote:
have separate queries for each
term (using count() or using the rowcount of each result).

Hmmmm, that might just work, thanks! I think I've been staring at this
problem for so long that I missed the obvious!

Thanks again

C

Jul 17 '05 #3
Chris <Ch************@nez.oc.ku> wrote:
[snip]
What I need to do is to check how many of the terms actually match
something. Is there any way, either in MySQL or with the result array
in PHP, to determine this?

Am I on completely the wrong course (as it seems to me at the
moment...)


Ehhhh, it looks to me like you are trying to reinvent full text
searches (http://dev.mysql.com/doc/mysql/en/fulltext-search.html)

Jul 17 '05 #4

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

Similar topics

5
by: Adam i Agnieszka Gasiorowski FNORD | last post by:
I need help width formulating the most effective (in terms of processing time) SQL query to count all the "new" documents in the repository, where...
5
by: cassandra.flowers | last post by:
Hi, I have another string handling question for the group, since you have all been so helpful in the past. Thank you. Basically, I want...
4
by: dd | last post by:
Given the bolow sample, I need to count the elements <quick> with a child 'yes'. The result for this sample should, of couse, be '1', but I cannot...
5
by: rob.guitar.rob | last post by:
Hi, This may be a stupid question, but if you count a self axe will it always return 1? For example: count(self::*) and
13
by: Regnab | last post by:
The problem I'm having is the rsa.RecordCount always returns a '1' when I know there should be about 1600 records returned. I read somewhere that...
7
by: Chris Lasher | last post by:
Hi all, How can one count all the permutations of a substring in a string? For a more concrete example, let's say targetstr = 'AAA' and probestr...
3
by: Advo | last post by:
I've made a small search function as of here: if (stristr($bleh,$search_for)) { if(preg_match('/<title>(*)<\/title>/i', $bleh, $matches)) {...
3
by: trashman.horlicks | last post by:
Hi, I'm getting into a tangle with Regex in C#. If I had an expression like abc.def.ghi etc. How do I count how many instances there are of ""...
9
by: drasko | last post by:
Hi, I have RegularExpressionValidator control and I wish to set it up for limiting input text in textarea to 50 words. Users can enter text they...
1
by: jjjones3860 | last post by:
I have XML like the following: <book> <title> <author> <book> : : : and so on for my example.
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

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.