HTML search engine

Posted on 2004-11-15
Last Modified: 2010-04-06

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?
Question by:andris333
    LVL 10

    Expert Comment

    I think this will help you

    LVL 23

    Expert Comment

    change this:


    to this:


    This is assuming you are storing your

    request.form("...") in the variable called searchword

    Expert Comment

    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.
    LVL 10

    Assisted Solution

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


    Author Comment


    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.

    Author Comment


    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?
    LVL 7

    Accepted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Android App Development

    This course will involve creating widgets, customize list view, grid view, spinners, etc. Creating applications using audio, video, and SQLite database. Ending with publication on Google Play.

    Suggested Solutions

    There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
    What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now