Search part of a website

M

Mel

I have a private website (portal) that our sales representatives have
access to. I have approx. 1GB of documents such as training manuals,
marketing documents, technical information sheets, etc. located in a
"Library" folder which contains lots of sub-folders and files and is
located beneath the root folder. I want to allow the user to easily
search this information; file name and file content key word
searching. How would I implement this on my website?

Please note, I want the users to search this area of the website only,
searching the rest of the website is not necessary. I am using
Asp.net 2.0, VB.net, VS 2008.
 
M

Mel

You could use Index Server (know perhaps as Windows Search) to index those
documents. You may need third party "filters" to be able to index third
party documents. Then you can use ADO.NET to run a query against those
indexed documents.

Try :http://www.c-sharpcorner.com/UploadFile/sushil saini/UsingIndexServ...
--
Patrice

"Mel" <[email protected]> a écrit dans le message de groupe de discussion
: (e-mail address removed)...





- Show quoted text -

Okay, I think I am on the right track. I was able to create a new
indexing service, called "Library" on my web server. I turned on
"Generate Abstracts" and I also installed iFilter (from Adobe Acrobat)
so the indexing service will also return results from PDF files.

Now I am trying to make a new ASP.net web page that uses that indexing
service to perform the searching. I am referring to the website link
you provided and trying to make it work in Visual Basic language and
Asp.net 2.0 (.NET framework 3.5). If anyone else can offer some other
examples that would be excellent.
 
P

Patrice

Now I am trying to make a new ASP.net web page that uses that indexing
service to perform the searching. I am referring to the website link
you provided and trying to make it work in Visual Basic language and
Asp.net 2.0 (.NET framework 3.5). If anyone else can offer some other
examples that would be excellent.

I found a KB article that exists in both C# and VB :
http://support.microsoft.com/kb/820105/en-us (How to use an ASP.NET
application to query an Indexing Service catalog by using Visual Basic
..NET).

Though a bit old it should bit be very similar and even perhaps identical
for .NET 2.0.
 
M

Mel

I found a KB article that exists in both C# and VB :http://support.microsoft.com/kb/820105/en-us(How to use an ASP.NET
application to query an Indexing Service catalog by using Visual Basic
.NET).

Though a bit old it should bit be very similar and even perhaps identical
for .NET 2.0.

My vPath is returning a NULL. The directory does in fact exist but
the URL path is not there. The doctitle and filename are there but
not the vPath. Any ideas why?

'My Example Code
'create a connection object and command object, to connect the
Index Server
Dim odbSearch As New
System.Data.OleDb.OleDbConnection("Provider=""MSIDXS"";Data
Source=""Library"";")
Dim cmdSearch As New System.Data.OleDb.OleDbCommand()
'assign connection to command object cmdSearch
cmdSearch.Connection = odbSearch

'Query to search a free text string in the catalog in the
contents of the indexed documents in the catalog
Dim searchText As String = btntxtSearch.Text.Replace("'",
"''")
cmdSearch.CommandText = "select doctitle, filename, vpath,
rank, characterization from scope() where FREETEXT(Contents, '" &
searchText & "') order by rank desc"

odbSearch.Open()

Try
'execute search query
Dim rdrSearch As System.Data.OleDb.OleDbDataReader =
cmdSearch.ExecuteReader()
'loop through each result and bind it to the repeater
control
While rdrSearch.Read()
'Assemble the search result text and abstract
getpagelink(rdrSearch(0).ToString(),
rdrSearch(2).ToString(), rdrSearch(4).ToString()) 'rdrSearch(2)
IS NULL, WHY?
End While
Catch ex As Exception
lbl.Text = "Search Error: " & ex.Message & "<br>"
End Try

odbSearch.Close()
 
M

Mel

My vPath is returning a NULL.  The directory does in fact exist but
the URL path is not there.  The doctitle and filename are there but
not the vPath.  Any ideas why?

'My Example Code
        'create a connection object and command object, to connect the
Index Server
        Dim odbSearch As New
System.Data.OleDb.OleDbConnection("Provider=""MSIDXS"";Data
Source=""Library"";")
        Dim cmdSearch As New System.Data.OleDb.OleDbCommand()
        'assign connection to command object cmdSearch
        cmdSearch.Connection = odbSearch

        'Query to search a free text string in the catalog in the
contents of the indexed documents in the catalog
        Dim searchText As String = btntxtSearch.Text.Replace("'",
"''")
        cmdSearch.CommandText = "select doctitle, filename, vpath,
rank, characterization from scope() where FREETEXT(Contents, '" &
searchText & "') order by rank desc"

        odbSearch.Open()

        Try
            'execute search query
            Dim rdrSearch As System.Data.OleDb.OleDbDataReader =
cmdSearch.ExecuteReader()
            'loop through each result and bind it to the repeater
control
            While rdrSearch.Read()
                'Assemble the search result text and abstract
                getpagelink(rdrSearch(0).ToString(),
rdrSearch(2).ToString(), rdrSearch(4).ToString())       'rdrSearch(2)
IS NULL, WHY?
            End While
        Catch ex As Exception
            lbl.Text = "Search Error: " & ex.Message & "<br>"
        End Try

        odbSearch.Close()

I tried just "path" instead of "vpath" (which is virtual path) and I
believe that will work.
 
P

Patrice

I tried just "path" instead of "vpath" (which is virtual path) and I
believe that will work.

Based on the name vpath would be likely some kind of virtual directory
(perhaps when you index content on another server using a share ?). So path
should do it if you are on the same server...
 
M

Mel

Based on the name vpath would be likely some kind of virtual directory
(perhaps when you index content on another server using a share ?). So path
should do it if you are on the same server...

Got it. Almost done, however, when I release my new awesome search
page to the web server the Next Page linkbutton doesn't work; it
returns an error listed below. The code does work on my local
computer while debugging but does not work on the web server. Ever
had this problem? I don't use the ViewState much so I may need to
read up on that.... Just thought I would post in case you have ever
had this same issue.

Server Error in '/' Application: Index was out of range. Must be non-
negative and less than the size of the collection.
Parameter name: index

Example Code:
Public Class Library
Inherits System.Web.UI.Page
Protected values As New ArrayList()
Public cnt As Integer

Public Property CurrentPage() As Integer
Get
Dim o As Object = Me.ViewState("_CurrentPage")
' look for current page in ViewState
If o Is Nothing Then
Return 0
Else
' default to showing the first page
Return CInt(o)
End If
End Get

Set(ByVal value As Integer)
Me.ViewState("_CurrentPage") = value
End Set
End Property

Protected Sub cmdNext_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdNext.Click
' Set viewstate variable to the next page
CurrentPage += 1
' Reload control
btnSearch_Click(sender, e)
End Sub

'Execute the search
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click
''Reset to page 1 as a new search is performed
If sender.text.ToString = "search" Then
CurrentPage = 0
End If

' Show Prev or Next buttons upon searching
cmdPrev.Visible = True
cmdNext.Visible = True

cnt = 1
If btntxtSearch.Text.Trim() = "" Then
btnClear_Click(sender, e)
Else
lbl.Text = ""
Search()
End If
End Sub

Public Sub Search()
Dim iPos As Integer
'create a connection object and command object, to connect the
Index Server
Dim odbSearch As New
System.Data.OleDb.OleDbConnection("Provider=""MSIDXS"";Data
Source=""Library"";")
Dim cmdSearch As New System.Data.OleDb.OleDbCommand()
'assign connection to command object cmdSearch
cmdSearch.Connection = odbSearch

'Query to search a free text string in the catalog in the
contents of the indexed documents in the catalog
Dim searchText As String = btntxtSearch.Text.Replace("'",
"''")
cmdSearch.CommandText = "select doctitle, filename, vpath,
rank, characterization from scope() where FREETEXT(Contents, '" &
searchText & "') order by rank desc"
odbSearch.Open()

Try
'execute search query
Dim rdrSearch As System.Data.OleDb.OleDbDataReader =
cmdSearch.ExecuteReader()
'loop through each result and bind it to the repeater
control
While rdrSearch.Read()
'Assemble the search result text and abstract
getpagelink(rdrSearch(0).ToString(),
rdrSearch(2).ToString(), rdrSearch(4).ToString())
End While
Catch ex As Exception
lbl.Text = "Search Error: " & ex.Message & "<br>"
End Try

odbSearch.Close()

' Populate the repeater control with the Items DataSet
Dim objPds As New PagedDataSource()
objPds.DataSource = values

' Indicate that the data should be paged
objPds.AllowPaging = True

' Set the number of items you wish to display per page
objPds.PageSize = 50

' Set the PagedDataSource's current page
objPds.CurrentPageIndex = CurrentPage

'Display a summary for the current search
resultSummary.Text = ((("Your search for <b>" &
btntxtSearch.Text & "</b> Returned ") & (cnt - 1) & " Results. " &
"<br>Page: ") & (CurrentPage + 1).ToString() & " of ") &
objPds.PageCount.ToString()

' Disable Prev or Next buttons if necessary
cmdPrev.Enabled = Not objPds.IsFirstPage
cmdNext.Enabled = Not objPds.IsLastPage

repSearchResults.DataSource = objPds
repSearchResults.DataBind()
End Sub
End Class
 
M

Mel

Got it.  Almost done, however, when I release my new awesome search
page to the web server the Next Page linkbutton doesn't work; it
returns an error listed below.  The code does work on my local
computer while debugging but does not work on the web server.  Ever
had this problem?  I don't use the ViewState much so I may need to
read up on that....  Just thought I would post in case you have ever
had this same issue.

Server Error in '/' Application:  Index was out of range. Must be non-
negative and less than the size of the collection.
Parameter name: index

Example Code:
Public Class Library
    Inherits System.Web.UI.Page
    Protected values As New ArrayList()
    Public cnt As Integer

    Public Property CurrentPage() As Integer
        Get
            Dim o As Object = Me.ViewState("_CurrentPage")
            ' look for current page in ViewState
            If o Is Nothing Then
                Return 0
            Else
                ' default to showing the first page
                Return CInt(o)
            End If
        End Get

        Set(ByVal value As Integer)
            Me.ViewState("_CurrentPage") = value
        End Set
    End Property

    Protected Sub cmdNext_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdNext.Click
        ' Set viewstate variable to the next page
        CurrentPage += 1
        ' Reload control
        btnSearch_Click(sender, e)
    End Sub

    'Execute the search
    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click
        ''Reset to page 1 as a new search is performed
        If sender.text.ToString = "search" Then
            CurrentPage = 0
        End If

        ' Show Prev or Next buttons upon searching
        cmdPrev.Visible = True
        cmdNext.Visible = True

        cnt = 1
        If btntxtSearch.Text.Trim() = "" Then
            btnClear_Click(sender, e)
        Else
            lbl.Text = ""
            Search()
        End If
    End Sub

    Public Sub Search()
        Dim iPos As Integer
        'create a connection object and command object, to connect the
Index Server
        Dim odbSearch As New
System.Data.OleDb.OleDbConnection("Provider=""MSIDXS"";Data
Source=""Library"";")
        Dim cmdSearch As New System.Data.OleDb.OleDbCommand()
        'assign connection to command object cmdSearch
        cmdSearch.Connection = odbSearch

        'Query to search a free text string in the catalog in the
contents of the indexed documents in the catalog
        Dim searchText As String = btntxtSearch.Text.Replace("'",
"''")
        cmdSearch.CommandText = "select doctitle, filename, vpath,
rank, characterization from scope() where FREETEXT(Contents, '" &
searchText & "') order by rank desc"
        odbSearch.Open()

        Try
            'execute search query
            Dim rdrSearch As System.Data.OleDb.OleDbDataReader =
cmdSearch.ExecuteReader()
            'loop through each result and bind it to the repeater
control
            While rdrSearch.Read()
                'Assemble the search result text and abstract
                getpagelink(rdrSearch(0).ToString(),
rdrSearch(2).ToString(), rdrSearch(4).ToString())
            End While
        Catch ex As Exception
            lbl.Text = "Search Error: " & ex.Message & "<br>"
        End Try

        odbSearch.Close()

        ' Populate the repeater control with the Items DataSet
        Dim objPds As New PagedDataSource()
        objPds.DataSource = values

        ' Indicate that the data should be paged
        objPds.AllowPaging = True

        ' Set the number of items you wish to display per page
        objPds.PageSize = 50

        ' Set the PagedDataSource's current page
        objPds.CurrentPageIndex = CurrentPage

        'Display a summary for the current search
        resultSummary.Text = ((("Your search for <b>" &
btntxtSearch.Text & "</b> Returned ") & (cnt - 1) & " Results. " &
"<br>Page: ") & (CurrentPage + 1).ToString() & " of ") &
objPds.PageCount.ToString()

        ' Disable Prev or Next buttons if necessary
        cmdPrev.Enabled = Not objPds.IsFirstPage
        cmdNext.Enabled = Not objPds.IsLastPage

        repSearchResults.DataSource = objPds
        repSearchResults.DataBind()
    End Sub
End Class

Nevermind I fixed it. Had a problem in my aspx page. Thanks for all
of your help! You rock!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top