Avatar billede shadowmage Nybegynder
26. marts 2009 - 11:06 Der er 1 løsning

ASP: Indexing Service - search funktion i ASP

Hej, jeg har arvet en hjemmeside hvor der er del tilrettelser. Men jeg er løbet hovedet mod muren omkring dette.

Når jeg søger på hjemmesiden, så vil den ikke finde resultater medmindre de er "exact".
F.eks. hvis der står: "Global Citrix Error code 5" i en hjemmeside, så vil jeg ikke kunne finde den medmindre jeg skriver "Global Citrix", "Citrix Error code" eller "code 5".
Hvis jeg skriver "Citrix code 5" eller "Global code", så finder den ikke siden.

I Indexing Service, så kan jeg godt finde siden. Så jeg går ud fra at det er i scriptet på ASP search siden.

Jeg poster den her og håber nogen kan se hoved og hale i det.

*******************************************************
<%@LANGUAGE=VBSCRIPT%>
<% OPTION EXPLICIT %>
<% on error resume next %>
<%
'***************************** CONFIGURATION AREA ******************************
'DEFINE YOUR CATALOG...

'If the catalog is on the same server as this script simply type the catalog name
'as the strCatalog variable below. If the catalog is on a different server you
'should use "query://192.168.0.1/intranet" replacing the IP address and catalog name
'as appropriate. You MUST have permission on the remote server for this to work.

Dim strCatalog
strCatalog = "Web"

'SET THE NUMBER OF RESULTS TO SHOW ON THE PAGE...

Dim intResultsPerPage
intResultsPerPage = 10

'MASKING OUT FILE TYPES, FILES AND DIRECTORIES...

Dim strQuery
strQuery = Request.Querystring("QU")

' mask out unwanted document types. You can add to this list if necessary (note: I find that word document templates .DOT screw up the index so try and avoid indexing those directories).
'strQuery = strQuery & " and not #filename *.|(txt|,inc|,dot|,mdb|,cgi|,class|,toc|,csv|,css|,dwg|,dwf|,vbs|,cdx|,png|,asp|)"
strQuery = strQuery & " and not #filename *.|(ppt|,txt|,inc|,dot|,mdb|,cgi|,class|,toc|,csv|,css|,dwg|,dwf|,vbs|,cdx|,png|,asp|,xml|)"

' mask out specific files (repeat the line below for other files).
'strQuery = strQuery & " and not #filename password.txt"
strQuery = strQuery & " and not #filename *_|(y.htm*|,h.htm*|,m.htm*|,d.htm*|)"

' mask out unwanted directories here, such as the FrontPage vti_ (repeat the line below for other directories)
strQuery = strQuery & " and not #path *\_vti*"
strQuery = strQuery & " and not #path *\Excelark*"
strQuery = strQuery & " and not #path *\Extranet*"
strQuery = strQuery & " and not #path *\Wordark*"
' strQuery = strQuery & " and not #path *\_Under construction files*"
strQuery = strQuery & " and not #path *\_vti_bin*"
strQuery = strQuery & " and not #path *\_vti_cnf*"
strQuery = strQuery & " and not #path *\_vti_pvt*"
strQuery = strQuery & " and not #path *\_vti_script*"
strQuery = strQuery & " and not #path *\_vti_txt*"
strQuery = strQuery & " and not #path *\_X-net*"
' strQuery = strQuery & " and not #path *\AcrobatReaderDocuments*"
strQuery = strQuery & " and not #path *\cgi-bin*"
strQuery = strQuery & " and not #path *\Forms*"
strQuery = strQuery & " and not #path *\images*"
strQuery = strQuery & " and not #path *\IT*"
strQuery = strQuery & " and not #path *\Menu*"
' strQuery = strQuery & " and not #path *\MiniPoint Server Version*"
strQuery = strQuery & " and not #path *\mPower*"
strQuery = strQuery & " and not #path *\Ny_Web*"
strQuery = strQuery & " and not #path *\PPT*"
strQuery = strQuery & " and not #path *\SSDP*"
strQuery = strQuery & " and not #path *\Stanli5*"
strQuery = strQuery & " and not #path *\VraisFiles*"
' strQuery = strQuery & " and not #path *\ZIP files*"
strQuery = strQuery & " and not #path *_SysApps_Index*"

'OTHER OPTIONS...

Dim bShowAbstract
bShowAbstract = True 'set False if you want to hide abstracts.

Dim bShowHelp
bShowHelp = True 'set False if you want to hide the SEARCH help.

'*******************************************************************************
'                      DO NOT MODIFY BENEATH THIS LINE!
'*******************************************************************************

Function processURL(vpath,path)
  Dim strProtocol
  IF Trim(LCase(Request.ServerVariables("HTTPS"))) = "on" THEN
      strProtocol = "https://"
  ELSE
      strProtocol = "http://"
  END IF

  Dim strPhysicalPath
  strPhysicalPath = Left(Request.ServerVariables("PATH_TRANSLATED"),(Len(Request.ServerVariables("PATH_TRANSLATED"))-Len(Request.ServerVariables("PATH_INFO"))))

  IF vpath = "" OR isNULL(vpath) THEN
      IF inStr(LCase(path),LCase(strPhysicalPath)) THEN
        processURL = strProtocol & Request.ServerVariables("SERVER_NAME") & Replace(Replace(LCase(path),LCase(strPhysicalPath),""),"\","/")
      ELSE
        processURL = path
      END IF
  ELSE
      ProcessURL = strProtocol & Request.ServerVariables("SERVER_NAME") & vpath
  END IF
End Function

Function processTitle(doctitle,filename)
  IF Trim(doctitle) = "" OR isNULL(doctitle) THEN
      processTitle = filename
  ELSE
      processTitle = doctitle
  END IF
End Function

Function processAbstract(abstract)
  IF bShowAbstract = False THEN
      processAbstract = ""
  ELSE
      IF abstract = "" OR isNULL(abstract) THEN
        processAbstract = "<b>Abstract:</b> [No Abstract available for this document]<br>"
      ELSE
        processAbstract = "<b>Abstract:</b> " & Server.HTMLEncode(abstract) & "...<br>"
      END IF
  END IF
End Function

Function processRank(rank)
  Dim intRank
  intRank = rank/10
  IF intRank < 1 THEN
      intRank = 1
  ELSE
      intRank = FormatNumber(intRank,0)
  END IF
  processRank = intRank & "%"
End Function

Function processSize(filesize)
  Dim intFileSize
  intFileSize = Trim(filesize)
  IF intFilesize > 1048575 THEN
  processSize = FormatNumber(intFilesize/1048576,0) & " MB"
  ELSEIF intFilesize > 1023 AND intFilesize < 1048576 THEN
  processSize = FormatNumber(intFilesize/1024,1) & " KB"
  ELSE
  processSize = intFilesize & " Bytes"
  END IF
End Function

Function processWrite(write)
  processWrite = FormatDateTime(write,1) & " at " & FormatDateTime(write,3)
End Function

Function getLinks(TotalPages,CurrentPage)

  Dim strQueryString
  Dim item
  for each item in Request.QueryString()
      IF item <> "PAGE" THEN
      strQueryString = strQueryString & item & "=" & Request.QueryString(item) & "&"
      END IF
  next
  IF Right(strQueryString,1) = "&" THEN
  strQueryString = Left(strQueryString,Len(strQueryString)-1)
  END IF

  Dim strLinks
  IF CInt(Request.QueryString("PAGE")) > 1 THEN
      strLinks = ("<a href=""" & Request.ServerVariables("SCRIPT_NAME") & "?" & strQueryString & "&PAGE=" & CurrentPage - 1 & """>Prev</a>")
  END IF

  Dim i
  i = 1
  Do
      IF i = CInt(CurrentPage) THEN
      strLinks = strLinks & " <font color=""#FF9900"">" & i & " </font>"
      ELSE
      strLinks = strLinks & " <a href=""" & Request.ServerVariables("SCRIPT_NAME") & "?" & strQueryString & "&PAGE=" & i & """>" & i & "</a> " & VbCrLf
      END IF
      i = i + 1
  Loop While i <= TotalPages

  ' Display the Next button unless we are on the last page...
  if CInt(CurrentPage) < CInt(TotalPages) then
        strLinks = strLinks & "<a href=""" & Request.ServerVariables("SCRIPT_NAME") & "?" & strQueryString & "&PAGE=" & CurrentPage + 1 & """>Next</a>" & VbCrLf
  End If

  getLinks = strLinks

End Function

'*******************************************************************************
' has a SEARCH been requested? is there anything to SEARCH for?
IF Request.QueryString("Action") = "SEARCH" AND Request.QueryString("QU") <> "" THEN

Dim Page
If Request.QueryString("PAGE") = "" then
Page = 1 'We're on the first page
Else
Page = Request.QueryString("PAGE")
End If

' create the Index Server query...
Dim Index
Set Index = Server.CreateObject("IXSSO.Query")
Index.catalog=strCatalog
Index.Query = strQuery
Index.CiScope = "\"
Index.Columns = "HitCount, filename, Vpath, DocTitle, characterization, rank, size, path, write"
Index.SortBy = "rank[d], doctitle"
Index.MaxRecords = 300
Index.Dialect = 1
Dim Results
Set Results = Index.CreateRecordset("nonsequential")

Dim bError
Dim strError
If Err.number <> 0 then
  strError = Err.Description
  bError = True
End If

IF NOT Results.EOF THEN
Results.MoveFirst
Results.PageSize = intResultsPerPage

' Get the max number of pages
Dim intTotalPages
intTotalPages = Results.PageCount

' Set the absolute page
Results.AbsolutePage = Page
END IF

' Counting variable for our recordset
Dim count
END IF
'*******************************************************************************
%>
<!-- Now Generate the HTML Results Page -->
<HTML>
<HEAD>
<TITLE>Intranet SEARCH Results</title>
<style>
a:link {  color: #0066CC; text-decoration: none}
a:visited {  color: #0066CC; text-decoration: none}
a:hover {  color: orange; text-decoration: underline}
.button { background = #CCCCCC; font-size=8pt;}
INPUT { background = #EFF7FF; font-size=8pt;}
</style>
</HEAD>
<BODY bgcolor="white" leftmargin="0" link="#0066CC" rightmargin="0" text="black" topmargin="0" marginheight="0" marginwidth="0" vlink="#0066CC" alink="#0066CC">
<table width="700" cellpadding=5 cellspacing=5>
<tr>
<td width="100" valign="top">&nbsp;</td>
<td width="600" valign="top"><br><br><b><i>
<font face="arial" size="4" color="#CCCCCC">MD-IS</font></i></b><font face= "arial" size="4" color="#CCCCCC"><b><i>
Knowledge Base SEARCH Result</i></b></font><br>


<%
IF bError = True THEN
nomatches("ERROR: " & strError & "<br>Please try again...")
End If

IF Request.QueryString("Action") <> "SEARCH" THEN ' this is a new SEARCH
nomatches("<i>Please enter your SEARCH query in the box above...</i>")

ELSEIF Request.QueryString("Action") = "SEARCH" AND Request.QueryString("QU") = "" THEN ' they didn't enter anything in the box!
nomatches("NOTHING TO SEARCH FOR!<br><br><i>Please enter your SEARCH query in the box above...</i>")

ELSEIF Request.QueryString("Action") = "SEARCH" AND Request.QueryString("QU") <> "" AND Results.EOF = False THEN ' matches
matches

ELSEIF Request.QueryString("Action") = "SEARCH" AND Request.QueryString("QU") <> "" AND Results.EOF = True THEN ' no matches
nomatches("Your SEARCH for <font color=""#0066CC"">" & Request.Querystring("QU") & "</font> matched no Documents or contained only 'Noise' words. <BR>Please check your spelling or SEARCH using more general keywords.")

ELSE

END IF
%>

</body>
</html>

<%
'*******************************************************************************
SUB matches

  Dim strRefine
  If Results.Recordcount > 250 THEN
  strRefine = "You may want to refine your SEARCH."
  ELSE
  strRefine = ""
  END IF

  Response.Write "<b><font face=""arial"" size=""2"">Your SEARCH for <font color=""#0066CC"">" & Request.Querystring("QU") & "</font> matched " & Results.recordcount & " Documents (Page " & Page & " of " & intTotalPages & ").<BR>" & strRefine & " Results Indexed by relevance.</font></b><br></td></tr>" & VbCrLf ' how many docs were matched?
  Dim strNumber
  strNumber = 1 + page * intResultsPerPage - intResultsPerPage ' set the doc counter to the correct number depending on the page and number of records on it

  ' Set Count equal to zero
  Count = 0

  Do While Not Results.EOF AND Count < Results.PageSize' start looping, carry on till you reach the end of the function (ie the EndOfFunction)

      %>
      <tr>
      <td width="100" valign="top" align="right"><font face="arial" size="2"><b><%= strNumber %>.</b></font></td>
      <% strNumber = strNumber + 1 %>
      <td width="600" valign="top"><font face="arial" size="2">
      <a href="<%= ProcessURL(Results("Vpath"),Results("path")) %>"><%= ProcessTitle(Results("DocTitle"),Results("FileName")) %></a> (<%= processRank(Results("Rank")) %>)<br>
      <%= ProcessAbstract(Results("characterization")) %>
      <font size=1><%= ProcessURL(Results("Vpath"),Results("path")) %></font><BR>
      <font size=1>File Name: <%= Results("filename") %>, Size: <%= processSize(Results("size")) %>, Last Modified: <%= processWrite(Results("write")) %></font><br>
      </font></td>
      </tr>
      <%
      Count = Count + 1
      Results.MoveNext ' okay, job done, back to the start of the loop and on to the next record
      Loop
      %>
      <tr>
          <td width="100" valign="top">&nbsp;</td>
          <td width="600" valign="top"><font face="arial" size="2"><center><%= getLinks(intTotalPages,Page) %></center></td>
      </tr>
<%
footer

END SUB
'*******************************************************************************
%>

<% Function nomatches(message) %>

  <b><font face="arial" size="2"><%= message %></font></b>
  <% IF NOT(bShowHelp = False) THEN %>
  <!--#include file="help.inc" -->
  <% END IF %>

<% footer %>
<% END Function %>

<%
'*******************************************************************************
SUB footer
  Response.Write("<tr><td>&nbsp;</td><td><font face=""arial"" size=""1""><center><a href=""http://scop.net.sas.dk/"" target=""_blank"">© Copyright 2005 Computer Sciences Corporation</a></center></font></td></tr></table>")
  Response.End

END SUB
'*******************************************************************************
%>

<% IF Request.QueryString("Action") = "SEARCH" AND Request.QueryString("QU") <> "" THEN %>
<% Results.Close %>
<% Set Results = Nothing %>
<% END IF %>=
*******************************************************
Avatar billede shadowmage Nybegynder
18. marts 2011 - 12:07 #1
Nevermind. ^^
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester