close ad
WARNING PC USERS: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Complex search with DB Search component of DA

Thread began 5/26/2009 1:09 pm by msummers194171 | Last modified 5/28/2009 9:44 am by msummers194171 | 1128 views | 5 replies |

msummers194171

Complex search with DB Search component of DA

I want to be able to do a keyword search across multiple fields. For example, I want the client to be able to search for -

red widgets

in fields A, B, and C.

I have a form with a single text field called 'keywords'. If I add more than one item to that field ('red widgets'), I get a query like this -

SELECT * FROM items WHERE (((item_primary LIKE '%red%') OR (item_secondary LIKE '%red%') OR (item_content LIKE '%red%')) OR ((item_primary LIKE '%widgets%') OR (item_secondary LIKE '%widgets%') OR (item_content LIKE '%widgets%'))) ORDER BY item_id ASC

And what I really want is a query like this -

SELECT * FROM items WHERE (((LOWER(item_primary) LIKE LOWER('%red%')) OR (LOWER(item_secondary) LIKE LOWER('%red%')) OR (item_content LIKE '%red%')) AND ((item_primary LIKE '%widgets%') OR (item_secondary LIKE '%widgets%') OR (item_content LIKE '%widgets%'))) ORDER BY item_id ASC

(I didn't propagate the LOWER() usages for simplicity)

How can I get that?

Thanks,

Murray

Sign in to reply to this post

Ray BorduinWebAssist

Your first one is easy. Just use the wizards "keyword" search option which allows you to choose multiple columns and automatically creates the where clause as you have specified.

The second one is more difficult and would require hand code. You can't just pass in LOWER() around columns because there is SQL Injection protection built into the code that won't allow you to call functions from within it.

You could remove that and pass it in... another option is to create a VIEW in your database with Lower() versions of the fields. Then you wouldn't need to specify it in the query, you could also convert the value of the field to lower automatically in the server code so that it wouldn't need to be in the SQL itself.

The final option is to bring in the field AS a column in the query itself and using HAVING instead of WHERE. This can slow things down and requires hand code, so I would suggest the creating a view technique if at all possible.

Sign in to reply to this post

msummers194171

Thank you, Ray! I'll give those things a shot.... 8)

Sign in to reply to this post

msummers194171

Ray - I think that's what I have already used to create this page in the first place. The code I pasted into my initial post shows the select statement that resulted from that.

But - I started a new page, added a recordset to it. Then I inserted DataAssist > Database Search Wizard. Next, I chose a search page and a form name. Then I Add a search element that is Advanced Text Search. I select the fields I want to search, and specify a New Form Field (text) that I have called "Keywords". I make no further changes by clicking through the next step. The summary shows me -

Creating Search Page: test3-search.php

Creating Form: form1
Creating form element: Keywords

Applying to Recordset: rsData2

Search Arguments:
Advanced Text Search in item_primary, item_secondary, item_content from Keywords

This new search results page looks identical to my original post - it has:

//comparison list additions
$WADbSearch1->keywordComparison($KeyArr0,"".((isset($_POST["Keywords"]))?$_POST["Keywords"]:"") ."","AND","Includes",",%20","%20","%22","%22",0);

So I added

setQueryBuilderSource($query_rsData2,$WADbSearch1,false);
exit($query_rsData2);

the exit command, and uploaded.

When I fill in and submit the form, I'm getting exactly what I posted before -

SELECT * FROM items WHERE ((((item_primary LIKE '%Remington%') OR (item_secondary LIKE '%Remington%') OR (item_content LIKE '%Remington%')) OR ((item_primary LIKE '%military%') OR (item_secondary LIKE '%military%') OR (item_content LIKE '%military%'))) OR ((item_primary LIKE '%weapon%') OR (item_secondary LIKE '%weapon%') OR (item_content LIKE '%weapon%')))

I'm not getting the "AND" conjunction in there as you say I should be.

Sign in to reply to this post

Ray BorduinWebAssist

Make sure when you applied you specify your implied AND as a space. I think it may be a comma by default. That should get it to add the AND.

Sign in to reply to this post

msummers194171

OK - that's got it. Thanks, Ray!

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...