Discussion:
building an search page in asp.net
(too old to reply)
savvas stampolloglou
2007-03-18 15:45:27 UTC
Permalink
Hello to all after having read a lot if stuff about indexing server i
decided to build an app using it.
I wanted to start from something simle and then add more stuff to it
so I made the application below.

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<Script Runat="Server">

Sub Button_Click( s As Object, e As EventArgs )
Dim databaseCon As OleDbConnection
Dim queryString As String
Dim cmdSearch As OleDbCommand
Dim dtrSearch As OleDbDataReader

DatabaseCon = New OleDbConnection( "Provider=MSIDXS;Data
Source=Web" )
query = "SELECT RANK, FileName, VPath, Characterization " & _
"FROM SCOPE() " & _
"WHERE CONTAINS( '" & txtSearchPhrase.Text & "') " & _
"ORDER BY RANK DESC"
cmdSearch = New OleDbCommand( strSearch, DatabaseCon )
DatabaseCon.Open()
Try
dtrSearch = cmdSearch.ExecuteReader()
lblResults.Text = "<ul>"
While dtrSearch.Read
lblResults.Text &= "<li> (" & dtrSearch( "RANK" ) / 10 & "%) "
lblResults.Text &= "<a href=""" &
dtrSearch( "VPath" ).ToString()
lblResults.Text &= """>"
lblResults.Text &= dtrSearch( "FileName" ) & "</a><br>"
lblResults.Text &= dtrSearch( "Characterization" )
lblResults.Text &= "<p>"
End While
Catch exc As Exception
lblResults.Text = "Den vrethikan apotelesmata"
End Try
DatabaseCon.Close()
End Sub

</Script>

<html>
<head><title>FileContains.aspx</title></head>
<body>
<form Runat="Server">

<h2>Indexing service boolean search:</h2>
<asp:TextBox
ID="txtSearchPhrase"
Columns="50"
Runat="Server" />
<asp:Button
Text="Search!"
OnClick="Button_Click"
Runat="Server" />
<hr>
<asp:Label
ID="lblResults"
EnableViewState="False"
Width="400px"
Runat="Server" />

</form>
</body>
</html>

when i run it everything is except that lblResults.Text &= "<a
href=""" & dtrSearch( "VPath" ).ToString()
lblResults.Text &= """>" doens't work. when I put the mouse over
the created link for each file i get only a link to my search page
instead of the path.
For example if the returned document is located on c:\word.doc when i
click on the lick I go back to the default.aspx. Can anyone help??


Thanks in advance!!
Gang_Warily
2007-03-19 15:23:44 UTC
Permalink
Hi Savvas

If dtrSearch( "VPath" ) is empty that might mean you are indexing the folder
on the hard disk ('Physical Root'), rather than the website ('Virtual Root')
?

See "Q. What is a virtual root? " in
www.indexserverfaq.com/ISMMC.htm
then see Fig 4.

Eric
Post by savvas stampolloglou
Hello to all after having read a lot if stuff about indexing server i
decided to build an app using it.
I wanted to start from something simle and then add more stuff to it
so I made the application below.
<Script Runat="Server">
Sub Button_Click( s As Object, e As EventArgs )
Dim databaseCon As OleDbConnection
Dim queryString As String
Dim cmdSearch As OleDbCommand
Dim dtrSearch As OleDbDataReader
DatabaseCon = New OleDbConnection( "Provider=MSIDXS;Data
Source=Web" )
query = "SELECT RANK, FileName, VPath, Characterization " & _
"FROM SCOPE() " & _
"WHERE CONTAINS( '" & txtSearchPhrase.Text & "') " & _
"ORDER BY RANK DESC"
cmdSearch = New OleDbCommand( strSearch, DatabaseCon )
DatabaseCon.Open()
Try
dtrSearch = cmdSearch.ExecuteReader()
lblResults.Text = "<ul>"
While dtrSearch.Read
lblResults.Text &= "<li> (" & dtrSearch( "RANK" ) / 10 & "%) "
lblResults.Text &= "<a href=""" &
dtrSearch( "VPath" ).ToString()
lblResults.Text &= """>"
lblResults.Text &= dtrSearch( "FileName" ) & "</a><br>"
lblResults.Text &= dtrSearch( "Characterization" )
lblResults.Text &= "<p>"
End While
Catch exc As Exception
lblResults.Text = "Den vrethikan apotelesmata"
End Try
DatabaseCon.Close()
End Sub
</Script>
<html>
<head><title>FileContains.aspx</title></head>
<body>
<form Runat="Server">
<h2>Indexing service boolean search:</h2>
<asp:TextBox
ID="txtSearchPhrase"
Columns="50"
Runat="Server" />
<asp:Button
Text="Search!"
OnClick="Button_Click"
Runat="Server" />
<hr>
<asp:Label
ID="lblResults"
EnableViewState="False"
Width="400px"
Runat="Server" />
</form>
</body>
</html>
when i run it everything is except that lblResults.Text &= "<a
href=""" & dtrSearch( "VPath" ).ToString()
lblResults.Text &= """>" doens't work. when I put the mouse over
the created link for each file i get only a link to my search page
instead of the path.
For example if the returned document is located on c:\word.doc when i
click on the lick I go back to the default.aspx. Can anyone help??
Thanks in advance!!
.._..
2007-03-21 14:19:03 UTC
Permalink
I found this on the web someplace (and unfortunately lost the link)

I think the part you may want to look at is the path to vpath code at the
very bottom.

<%@ Language="VBScript" %>
<% Option Explicit %>
<html>
<head>
<title>ASP 101's Index Server Article - Advanced Search Page</title>
<meta name="description" content="ASP 101's Index Server Article - Advanced
Search Page">
<meta name="keywords" content="ASP 101's Index Server Article - Advanced
Search Page">
<meta name="author" content="John Peterson">
</head>
<body>

<p>
This is the advanced search page of the sample web content
for ASP 101's Index Server article.
</p>

<form action="advanced.asp" method="get">
<input type="text" name="query" />
<input type="submit" value="Search" />
</form>

<p>
<a href="default.asp">Basic Search</a>
</p>

<p>
Queries that should return results include:
<a href="?query=admin">admin</a> (only in basic),
<a href="?query=asp">asp</a> (> 10),
<a href="?query=component">component</a>,
<a href="?query=cookie">cookie</a>,
<a href="?query=database">database</a>,
<a href="?query=date">date</a>,
<a href="?query=time">time</a>,
<a href="?query=email">email</a>,
<a href="?query=form">form</a>,
<a href="?query=search">search</a>,
etc.
</p>


<%
Dim strQuery ' The text of our query
Dim objQuery ' The index server query object
Dim rstResults ' A recordset of results returned from I.S.
Dim objField ' Field object for loop

' Retreive the query from the querystring
strQuery = Request.QueryString("query")

' If the query isn't blank them proceed
If strQuery <> "" Then
' Create our index server object
Set objQuery = Server.CreateObject("IXSSO.Query")

' Set it's properties
With objQuery
.Catalog = "IS-Sample" ' Catalog to query
.MaxRecords = 10 ' Max # of records to return
.SortBy = "rank [d]"
.Columns = "filename, path, vpath, size, write, " _
& "characterization, DocTitle, DocAuthor, " _
& "DocKeywords, rank, hitcount"

' Build our Query: Hide admin page and FPSE pages
strQuery = "(" & strQuery & ")" _
& " AND NOT #filename = *admin*" _
& " AND NOT #path *\_vti_*"

' Uncomment to only look for files modified last 5 days
'strQuery = strQuery & " AND @write > -5d"

.Query = strQuery ' Query text
End With

' To set more complex scopes we use the utility object.
' You can call AddScopeToQuery as many times as you need to.
' Shallow includes just files in that folder. Deep includes
' subfolders as well.
'
'Dim objUtility
'Set objUtility = Server.CreateObject("IXSSO.Util")
'objUtility.AddScopeToQuery objQuery, "c:\inetpub\wwwroot\indexserver",
"shallow"
'objUtility.AddScopeToQuery objQuery,
"c:\inetpub\wwwroot\indexserver\content", "shallow"
'Set objUtility = Nothing

' Get a recordset of our results back from Index Server
Set rstResults = objQuery.CreateRecordset("nonsequential")

' Get rid of our Query object
Set objQuery = Nothing

' Check for no records
If rstResults.EOF Then
Response.Write "Sorry. No results found."
Else
' Print out # of results
Response.Write "<p><strong>"
Response.Write rstResults.RecordCount
Response.Write "</strong> results found:</p>"

' Loop through results
Do While Not rstResults.EOF
' Loop through Fields
' Pretty is as pretty does... good enough:
%>
<p>
<% If rstResults.Fields("doctitle") = "" Then %>
<strong><a href="<%= PathToVpath(rstResults.Fields("path")) %>"><%=
PathToVpath(rstResults.Fields("path")) %></a></strong><br />
<% Else %>
<strong><a href="<%= PathToVpath(rstResults.Fields("path")) %>"><%=
rstResults.Fields("doctitle") %></a></strong><br />
<% End If %>
&nbsp;&nbsp;&nbsp;<em>Author:</em> <%= rstResults.Fields("docauthor")
%><br />
&nbsp;&nbsp;&nbsp;<em>Last Modified:</em> <%= rstResults.Fields("write")
%><br />
&nbsp;&nbsp;&nbsp;<em>Size:</em> <%= rstResults.Fields("size") %>
bytes<br />
&nbsp;&nbsp;&nbsp;<em>Keywords:</em> <%= rstResults.Fields("dockeywords")
%><br />
&nbsp;&nbsp;&nbsp;<em>Description:</em> <%=
rstResults.Fields("characterization") %><br />
</p>
<hr />
<%

' Move to next result
rstResults.MoveNext
Loop

rstResults.MoveFirst
Response.Write "<pre>"
'Response.Write rstResults.GetString()
Response.Write "</pre>"
End If

' Kill our recordset object
Set rstResults = Nothing
End If
%>

</body>
</html>

<%
Function PathToVpath(strPath)
Const strWebRoot = "c:\inetpub\wwwroot\"

Dim strTemp

strTemp = strPath

strTemp = Replace(strTemp, strWebRoot, "\")
strTemp = Replace(strTemp, "\", "/")

PathToVpath = strTemp
End Function
%>
Post by Gang_Warily
Hi Savvas
If dtrSearch( "VPath" ) is empty that might mean you are indexing the folder
on the hard disk ('Physical Root'), rather than the website ('Virtual Root')
?
See "Q. What is a virtual root? " in
www.indexserverfaq.com/ISMMC.htm
then see Fig 4.
Eric
Post by savvas stampolloglou
Hello to all after having read a lot if stuff about indexing server i
decided to build an app using it.
I wanted to start from something simle and then add more stuff to it
so I made the application below.
<Script Runat="Server">
Sub Button_Click( s As Object, e As EventArgs )
Dim databaseCon As OleDbConnection
Dim queryString As String
Dim cmdSearch As OleDbCommand
Dim dtrSearch As OleDbDataReader
DatabaseCon = New OleDbConnection( "Provider=MSIDXS;Data
Source=Web" )
query = "SELECT RANK, FileName, VPath, Characterization " & _
"FROM SCOPE() " & _
"WHERE CONTAINS( '" & txtSearchPhrase.Text & "') " & _
"ORDER BY RANK DESC"
cmdSearch = New OleDbCommand( strSearch, DatabaseCon )
DatabaseCon.Open()
Try
dtrSearch = cmdSearch.ExecuteReader()
lblResults.Text = "<ul>"
While dtrSearch.Read
lblResults.Text &= "<li> (" & dtrSearch( "RANK" ) / 10 & "%) "
lblResults.Text &= "<a href=""" &
dtrSearch( "VPath" ).ToString()
lblResults.Text &= """>"
lblResults.Text &= dtrSearch( "FileName" ) & "</a><br>"
lblResults.Text &= dtrSearch( "Characterization" )
lblResults.Text &= "<p>"
End While
Catch exc As Exception
lblResults.Text = "Den vrethikan apotelesmata"
End Try
DatabaseCon.Close()
End Sub
</Script>
<html>
<head><title>FileContains.aspx</title></head>
<body>
<form Runat="Server">
<h2>Indexing service boolean search:</h2>
<asp:TextBox
ID="txtSearchPhrase"
Columns="50"
Runat="Server" />
<asp:Button
Text="Search!"
OnClick="Button_Click"
Runat="Server" />
<hr>
<asp:Label
ID="lblResults"
EnableViewState="False"
Width="400px"
Runat="Server" />
</form>
</body>
</html>
when i run it everything is except that lblResults.Text &= "<a
href=""" & dtrSearch( "VPath" ).ToString()
lblResults.Text &= """>" doens't work. when I put the mouse over
the created link for each file i get only a link to my search page
instead of the path.
For example if the returned document is located on c:\word.doc when i
click on the lick I go back to the default.aspx. Can anyone help??
Thanks in advance!!
Loading...