使用asp.net创建搜索引擎

发布于 2024-10-28 05:41:05 字数 1016 浏览 4 评论 0原文

我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

殤城〤 2024-11-04 05:41:05

查看 Lucene.net 以获得开箱即用的解决方案。

Have a look at Lucene.net for an out the box solution.

酷到爆炸 2024-11-04 05:41:05

加快查询速度的一种方法是不搜索 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.

鹤仙姿 2024-11-04 05:41:05

最简单的方法是使用数据库连接器,然后使用 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'

夜巴黎 2024-11-04 05:41:05

因为您使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文