Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

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?
0
andris333
Asked:
andris333
2 Solutions
 
rockmansatticCommented:
I think this will help you

http://www.dbazine.com/celko9.html

Rockman
0
 
aprestoCommented:
change this:

"%searchword%"

to this:

'"%&searchword&%"'

This is assuming you are storing your

request.form("...") in the variable called searchword
0
 
ivanrgCommented:
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.
Ivan
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
rockmansatticCommented:
@ 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.

Rockman
0
 
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.
0
 
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?
0
 
HecatonchiresCommented:
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.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now