我有以下代码用于在文档标题中搜索多个关键字,效果很好。我现在想要一列显示在每个标题行中找到的关键字数量并以后代方式排序。例如,如果我正在搜索“产假”,我应该得到如下信息:
名称 - 找到的关键字
产假政策 -- 2
年假政策——1
给准妈妈的孕产建议——1
希望它是有道理的,非常感谢!
Dim s As String = TextBox1.Text
Dim SqlQuery As String = "SELECT Doc_LibraryTable.DocID, Doc_LibraryTable.DocName, Doc_LibraryTable.DocType WHERE Doc_LibraryTable.DocType = DocType"
Dim ints As String() = s.Split(" ")
Dim i As Integer
If UBound(ints) >= 1 Then
SqlQuery += " AND (Doc_LibraryTable.DocName LIKE '%" + ints(0) + "%'"
For i = 1 To UBound(ints)
If Not ints(i) = "of" And Not ints(i) = "the" And Not ints(i) = "in" And Not ints(i) = "or" Then
SqlQuery += " OR Doc_LibraryTable.DocName LIKE '%"
SqlQuery += ints(i) + "%'"
End If
Next
ElseIf UBound(ints) < 1 Then
For i = 0 To UBound(ints)
SqlQuery += " AND (Doc_LibraryTable.DocName LIKE '%"
SqlQuery += ints(i) + "%"
Next
End If
If UBound(ints) >= 1 Then
SqlQuery += ")"
ElseIf UBound(ints) < 1 Then
SqlQuery += "')"
End If
SqlDataSource2.SelectCommand = SqlQuery
GridView1.DataSource = SqlDataSource2