HTML search engine

I have a table with html formatted text data in one of the columns. Now I need to make a search using this field. The problem is that in this field is html mixed with text. So, if a user would search for a words like form or title, simple sql searches (SELECT * FROM TABLE_DATA WHERE BODY LIKE "%searchword%" ) will always return all records from database.

Maybe it sound supid, but does anyone know the way how to make search excluding specific database column html tags or this is not possible at all?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I think this will help you

change this:


to this:


This is assuming you are storing your

request.form("...") in the variable called searchword
First of all, you shouldnt be Selecting all the fields on the search engine page, unless you really plan on showing all of them. Lets say its a book DBase. I would just display the title and author of the book and use the ISDN to know which record the user will eventually select.

SQL =  "SELECT ISDN, Title, Author FROM Books WHERE Title LIKE '%" + txtSearch + "%'"       for javascript
SQL =  "SELECT ISDN, Title, Author FROM Books WHERE Title LIKE '%" & txtSearch & "%'"      for VBscript

This select statement should only search in the Title field and not in any other field. If the recordset is returning the whole database then there's something wrong with your SQL statement. Try printing it on the screen with Response.Write(SQL). Also, look are your fields and your information and see if there's a way to narrow the search with dates or any other information the user is able to give you. Also if you're using Access to manage your database, you can test your SQL statement by making a query, however, you will have to change the % with *.

Hope this helps, good luck on your project.
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

@ apresto
I think that is not quite the problem he is having.

Within his database field, the data could contain an entire html table.  i.e.
<table><tr><td>this is the test he wants to search through</td></tr></table>

So if someone searches for the word table, this particular record would show up in the results.

Hope this helps carifiy. (of course, if i am correct.)
My first post should help with this problem.

andris333Author Commented:

Rockman is correct.

My problem is with HTML inserted in fiields. For instance, a database field has following data:

<table><tr><td>this is the test</td></tr></table>

So if user searches for the word table, this particular record would show up in the results.
andris333Author Commented:

Btw, Rockman, I analyzed your solution and I don't understand: does it mean that I should make searchword list for every document in database? How could something like this could be done if I don't know what kind on keyword users might use?
A few options:

1) Not store html in the database - seperating content from its presentation, and building the display in the page - this is preferred

2) Get a function that strips html - function strip_html(sStringWithHtml) returns sWithoutHtml - that can be included in your database.

select somefield from table where strip_html(somefield) like '%string%'

Very expensive computationally.  Functions that can do this are common, look for snippets.

3)Do it in code.  Pull down every record, then search them, using a  strip_html() in your coding language.  More work again.  Don't do this.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.