Results 1 to 6 of 6

Thread: search function question with asp

  1. #1
    Join Date
    May 2004
    Location
    NewYork, USA
    Posts
    175
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Default search function question with asp

    I wonder if this can be done in asp search function.

    I wrote a search tool (I mean, copied and integrated from somewhere ) workx perfect but...

    - let's say I am searching for the word considering , result comes up, fine...

    - when I search for sidering (which is nonsense but this is sample.) results comes up same because considering also includes sidering

    What I really need is, I just want it to find only the word sidering not the words includes sidering. When I type just onsi it also brings me the page includes considering.

    I've googled it and results were not helpfull, is this too difficult? Am i trying to create another google ?


    this is my code:


    form:

    Code:
     
    <form action="search-v2.asp">
    <input type="hidden" name="boo" value="AND" />
    <p align="right">
    <input type="text" name="q" size="22" /> </p>
    </form> 






    result page:
    Code:
    <%
     page = request.querystring("page")
     query = request.querystring("q")
     boo = request.querystring("boolean")
     If page = "" Then
     page = 1
     else
     page = cint(page)
     End If
     query = replace(query, "'" , "''")
     if query = "" then
     strRsp = " " 
     
     else
     if boo = "AND" then
     SQL = SQL & " pages.title LIKE '%" & query & "%' OR "
     SQL = SQL & " pages.keywords LIKE '%" & query & "%' OR "
     SQL = SQL & " pages.pageDesc LIKE '%" & query & "%' OR "
     SQL = SQL & " pages.pageDesc2 LIKE '%" & query & "%' OR "
     else
     q = split(query, " ")
     for e = 0 to ubound(q)
     SQL = SQL & " pages.title LIKE '%" & q(e) & "%' OR "
     SQL = SQL & " pages.keywords LIKE '%" & q(e) & "%' OR "
     SQL = SQL & " pages.pageDesc LIKE '%" & q(e) & "%' OR "
     SQL = SQL & " pages.pageDesc2 LIKE '%" & q(e) & "%' OR "
     next 
     end if
     SQL = Left(SQL, (LEN(SQL)-3))
     DisplayNum = 0
     Set oCon = Server.CreateObject ("ADODB.Connection")
     Set Rec = Server.CreateObject ("ADODB.Recordset")
     oCon.Open strCon
     Rec.PageSize = 10
     Rec.CursorLocation = adUseClient  
     SQL = "SELECT pageID, title, pageDesc, pageDesc2, url FROM pages WHERE active = 0 AND " & SQL
     SQL = SQL & " order by title asc"
     Rec.Open SQL, oCon
     if Rec.EOF OR Rec.BOF Then
     strRsp = strRsp & "<br><br>"
     strRsp = strRsp & "<p align=center><b>Sorry, There is no result ... </b></p>"
     response.write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sorry, There is no result ..."
     else 
     
     ipage = Rec.PageCount 
     if page = 0 or page > ipage Then
     Rec.AbsolutePage = ipage
     else
     Rec.AbsolutePage = page
     end if
     
     response.write "<blockquote>"
     Do While Not Rec.EOF AND DisplayNum < 10
     response.write "<b><a href="""& Rec("url") & """>"& Rec("title") & "</a></b><br>" & rec("pageDesc") & "<br><br>"
     DisplayNum = DisplayNum + 1
     Rec.MoveNext
     Loop
     response.write "</blockquote>"
     end if
     If ipage > 1 Then
     showpages = "&nbsp;More Pages : &nbsp;&nbsp;"
     For z = 1 to ipage
      If z = page then
       showpages = showpages & "&nbsp;[" & page & "]&nbsp;&nbsp;"
      Else 
     showpages = showpages & "&nbsp;<a href=search-v2.asp?page=" & z &"&q="&server.urlencode(query)& "&boolean="& boo &">" & z &  "</a>" & "&nbsp;&nbsp;"
      End If 
     Next 
     response.write  showpages & "&nbsp;&nbsp;"
     
     if ipage > 1 And page > 1 Then
     response.write  "<a  href=search-v2.asp?page="& page - 1 &"&q="& server.urlencode(query) & "&boolean="& boo &">Previous</a>&nbsp;&nbsp;"
     end if
     strLine = strLine &  "&nbsp;&nbsp;"
     If ipage > 1 And page < ipage Then
     response.write  "<a href=search-v2.asp?page="& page + 1 &"&q="& server.urlencode(query) & "&boolean="& boo &">Next Page</a>&nbsp;&nbsp;"
     end if
     
     End If
     Rec.Close
     oCon.Close
     set Rec = nothing
     set oCon = nothing
     end if
     %>

  2. #2
    Join Date
    Jan 2006
    Posts
    419
    Thanks
    2
    Thanked 16 Times in 16 Posts

    Default

    the problem you have is that you are using the like function with wild cards matching. a quick fix is to search for space word space or word space or space word - it is slow but fixes the problem. e.g ' ' + keyword + ' ' or keyword + ' ' or ' ' + keyword. if you are using sql server you can use functionality of full text catalogs and use the function for full word matching

  3. #3
    Join Date
    Apr 2006
    Location
    Amsterdam
    Posts
    352
    Thanks
    20
    Thanked 11 Times in 11 Posts

    Default

    Are you using MySQL?
    In that case its worth looking at MySQLs Full-Text Search Functions.

  4. #4
    Join Date
    May 2004
    Location
    NewYork, USA
    Posts
    175
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jimlewis
    the problem you have is that you are using the like function with wild cards matching. a quick fix is to search for space word space or word space or space word - it is slow but fixes the problem. e.g ' ' + keyword + ' ' or keyword + ' ' or ' ' + keyword. if you are using sql server you can use functionality of full text catalogs and use the function for full word matching
    Thank you, you gave me a good point, and I guess I will get it done, will work on it


    Quote Originally Posted by Rappie View Post
    Are you using MySQL?
    In that case its worth looking at MySQLs Full-Text Search Functions.
    Hi
    I am using MsAccess. I'm not mafiliar with php that's why I used msaccess.

  5. #5
    Join Date
    May 2004
    Location
    NewYork, USA
    Posts
    175
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Default

    I think i found what I was looking for:

    I've added this lines and seems like works fine to me


    Code:
     SQL = SQL & " pages.title LIKE '%" & " " & q(e) & " " & "%' OR "
     SQL = SQL & " pages.searched_short_description LIKE '%" & " " & q(e) & " " & "%' OR "
     SQL = SQL & " pages.searched_keywords LIKE '%" & " " & q(e) & " " & "%' OR "
     SQL = SQL & " pages.searched_description LIKE '%" & " " & q(e) & " " & "%' OR "
     SQL = SQL & " pages.searched_source LIKE '%" & " " & q(e) & " " & "%' OR "

  6. #6
    Join Date
    Jan 2006
    Posts
    419
    Thanks
    2
    Thanked 16 Times in 16 Posts

    Default

    i think u can ditch the use of like as you typically use like in conjuntion with wild cards like % for any character and as you do not want to match any character but just the word you could use
    and column = ' ' + term + ' ' or column = ' ' + term
    etc
    should make it quicker if it is not quick enough

    you should try sql server in future - so easy - far better than mysql

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 11th June 2007, 05:38 PM
  2. ASP.NET Search Engine
    By Furzetech in forum ASP.NET
    Replies: 1
    Last Post: 1st June 2007, 05:31 PM
  3. Replies: 0
    Last Post: 26th March 2007, 04:04 PM
  4. Search engine friendly pages ASP
    By philplatt in forum SEO and Website Promotion
    Replies: 15
    Last Post: 15th February 2006, 09:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •