使用asp.net创建搜索引擎
我想使用 ASP.NET 在我的网站中创建一个搜索引擎。该引擎将从数据库 (SQL Server 2008) 中搜索用户输入的文本。有人知道如何创建这个搜索引擎吗?我真的需要你的帮助。谢谢!
这是我的代码:
Partial Class Search
Inherits System.Web.UI.Page
Dim sqlconn As New SqlConnection("server=.\SQLEXPRESS; AttachDbFilename=C:\Documents and Settings\USER\Desktop\science\App_Data\Library.mdf;Integrated Security=True;User Instance=True")
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim sqlquery As String = "SELECT DISTINCT packagename,packagecategory FROM package Where "
If txtTitle.Text <> "" Then
sqlquery += "packagename LIKE '%" + txtname.Text + "%' AND "
Else
sqlquery += "packagename Like '%%' AND "
End If
If DropDownList1.SelectedValue <> "Any" Then
sqlquery += "packagecategory LIKE '%" + DropDownList1.SelectedValue + "%' AND "
Else
sqlquery += "packagecategory Like '%%' AND "
End If
我发现在列表视图中显示结果时存在问题......
I want to create a search engine in my website using ASP.NET. This engine will search an user's input text from the database (SQL Server 2008). Anyone know how to create this search engine? I really need your help. Thanks!
Here is my code:
Partial Class Search
Inherits System.Web.UI.Page
Dim sqlconn As New SqlConnection("server=.\SQLEXPRESS; AttachDbFilename=C:\Documents and Settings\USER\Desktop\science\App_Data\Library.mdf;Integrated Security=True;User Instance=True")
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim sqlquery As String = "SELECT DISTINCT packagename,packagecategory FROM package Where "
If txtTitle.Text <> "" Then
sqlquery += "packagename LIKE '%" + txtname.Text + "%' AND "
Else
sqlquery += "packagename Like '%%' AND "
End If
If DropDownList1.SelectedValue <> "Any" Then
sqlquery += "packagecategory LIKE '%" + DropDownList1.SelectedValue + "%' AND "
Else
sqlquery += "packagecategory Like '%%' AND "
End If
I find the problem in showing the result in the list view...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
查看 Lucene.net 以获得开箱即用的解决方案。
Have a look at Lucene.net for an out the box solution.
加快查询速度的一种方法是不搜索 COLUMN_NAME LIKE '%%' 因为所有内容都会匹配,基本上,删除示例中的其他内容。
A way you can speed up your query is to not search for COLUMN_NAME LIKE '%%' because everything will match, basicallyl, remove the elses in your example.
最简单的方法是使用数据库连接器,然后使用 SELECT * FROM table WHERE text LIKE '$USERINPUT'
The simplest you can get will be to use a db connector, then use
SELECT * FROM table WHERE text LIKE '$USERINPUT'
查看 Lucene.NET:http://incubator.apache.org/lucene.net/
Checkout Lucene.NET: http://incubator.apache.org/lucene.net/
因为您使用 Sql Server,所以请查看全文搜索,它可以帮助你。
正如 Mark 提到的,Lucene.net 也是一个选择。
Because you use Sql Server then have a look at Full-Text Search, it can help you.
Lucene.net is also the option as Mark has mentioned.