-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSearch.ascx.vb
53 lines (47 loc) · 2.37 KB
/
Search.ascx.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web.UI.WebControls
Imports System.Xml
Imports DevExpress.Web
Namespace AdaptiveSlideNavigation.UserControls
Partial Public Class Search
Inherits System.Web.UI.UserControl
Protected Sub SearchResults_Callback(ByVal sender As Object, ByVal e As CallbackEventArgsBase)
Dim text = e.Parameter
Dim results = DoSearch(text)
If results.Count > 0 Then
BindSearchResultsNavBar(results)
SearchResultsNavBar.Visible = True
noResultsContainer.Visible = False
Else
SearchResultsNavBar.Visible = False
requestText.InnerHtml = text
noResultsContainer.Visible = True
End If
End Sub
Private Sub BindSearchResultsNavBar(ByVal data As IList(Of SearchResultItem))
Dim group = New NavBarGroup()
SearchResultsNavBar.Groups.Add(group)
For Each item In data
Dim navBarItem = New NavBarItem(text:= String.Format("<span class='title'>{0}</span> <span class='tags'>Tags: {1}</span>", item.Title, GetFromattedTags(item.Tags)), name:= "", imageUrl:= "", navigateUrl:= item.Url)
group.Items.Add(navBarItem)
Next item
End Sub
Private Function GetFromattedTags(ByVal tags As String) As String
Return String.Concat(tags.Split(","c).Select(Function(i) String.Format("<span class='tag'>{0}</span>", i.Trim())))
End Function
Private Function DoSearch(ByVal text As String) As IList(Of SearchResultItem)
Dim pagesNodes = XmlDataSource1.GetXmlDocument().GetElementsByTagName("page").OfType(Of XmlNode)()
Return pagesNodes.Where(Function(n) n.Attributes("Title").Value.ToUpper().Contains(text.ToUpper()) OrElse n.Attributes("Tags").Value.ToUpper().Contains(text.ToUpper())).Select(Function(n) New SearchResultItem() With { _
.Title = n.Attributes("Title").Value, _
.Tags = n.Attributes("Tags").Value, _
.Url = n.Attributes("Url").Value _
}).ToList()
End Function
Private Class SearchResultItem
Public Property Title() As String
Public Property Tags() As String
Public Property Url() As String
End Class
End Class
End Namespace