CurtWRC
03-15-2006, 11:03 PM
I am trying to create a search system on my site using records from an oledb database. So far I have managed to create a textbox for keywords. When the user submits their search they are redirected to a page with a querystring with their keywords in. For example: searchresults.aspx?keywords=example. I then want to be able to display all records through a datagrid where there is a word in the querystring that matches a word in the 'Subject' Field of my 'News' table. Currently I am just using a WHERE clause. For example: WHERE Subject='" & Request.QueryString("Keywords")"'. But this isn't very useful as the words searched for must be the exact words in the 'Subject' Field for the record to be displayed. Is there a way of displaying records where only one of the words in the querystring matches one of the words in the field 'Subject'?
If there is, is there also a way of ordering the displayed records according to how many words match.
If anyone knows how to do this it would be very much appreciated if you shared with me how to do it as I can't think how to do it.
Thanks,
Curt.
handshakeit
03-22-2006, 11:45 AM
How much u have tried for this?
Can you give some code snipset it will help me to answer you.
Regards
Abhi
Handshakeit (http://www.handshakeit.com)
I am trying to create a search system on my site using records from an oledb database. So far I have managed to create a textbox for keywords. When the user submits their search they are redirected to a page with a querystring with their keywords in. For example: searchresults.aspx?keywords=example. I then want to be able to display all records through a datagrid where there is a word in the querystring that matches a word in the 'Subject' Field of my 'News' table. Currently I am just using a WHERE clause. For example: WHERE Subject='" & Request.QueryString("Keywords")"'. But this isn't very useful as the words searched for must be the exact words in the 'Subject' Field for the record to be displayed. Is there a way of displaying records where only one of the words in the querystring matches one of the words in the field 'Subject'?
If there is, is there also a way of ordering the displayed records according to how many words match.
If anyone knows how to do this it would be very much appreciated if you shared with me how to do it as I can't think how to do it.
Thanks,
Curt.
CurtWRC
03-22-2006, 11:43 PM
Here is what I have done so far:
http://www.rallystuff.net/curt/general.aspx?action=search
Currently only the 'news' search has any code attached to it. Try searching for 'links' and you will be re-directed to this page:
http://www.rallystuff.net/curt/general.aspx?action=searchresults&Search=News&Keyword=Links
It should display the news article called 'Links'. However if there was a news article called 'More Links' I would like that to also be displayed as it contains the word 'Links'.
To display the records I am using this clause:
"SELECT [News].* FROM [News] WHERE Subject='" & Request.QueryString("keyword") & "'"
handshakeit
03-23-2006, 04:16 AM
Try out this
It should display the news article called 'Links'. However if there was a news article called 'More Links' I would like that to also be displayed as it contains the word 'Links'.
For this u can modify your query like this
"SELECT [News].* FROM [News] WHERE Subject like %'" & Request.QueryString("keyword") & "%'"
this will check any string that containg the keyword string.
Thanx
Abhi
Handshakeit (http://www.handshakeit.com)
CurtWRC
03-24-2006, 12:26 AM
I just tried this using the search text 'Version' in hope that it would display the news article 'Version 2' as that has the word 'Version' in it:
http://www.rallystuff.net/curt/general.aspx?action=searchresults&Search=News&Keyword=version
However I got this error:
Syntax error in query expression 'Subject like %'version%''.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Syntax error in query expression 'Subject like %'version%''.
CurtWRC
03-24-2006, 12:42 AM
Sorry for double posting, but I have just had a play around with that code and have changed it to this and now it works great! :D
"SELECT [News].* FROM [News] WHERE Subject like '%" & Request.QueryString("keyword") & "%'"
Thanks handshakeit
handshakeit
03-24-2006, 05:38 AM
Thanks handshakeit
Your Welcome
Sorry form mistake in the query text
Handshakeit (http://www.handshakeit.com)