Solved

ASP with Index Server question

Posted on 2004-04-12
10
1,079 Views
Last Modified: 2007-12-19
Hello,

I'm trying to write a query to access Index server on our server.

My code (which I basically copied from a place on the web) is:

<%

Dim objConn, objRS, sqlString, strDocTitle

sqlString = "SELECT DocTitle FROM SCOPE('''/dev_goebase_com''') WHERE CONTAINS('mentoring')"

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "provider=MSIDXS"

Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open sqlString, objConn

Do While Not objRS.EOF
     strDocTitle = objRS("DocTitle")
     Response.Write(strDocTitle)
Loop

objRS.Close
Set objRS = Nothing
Set objConn = Nothing
%>

Now, this generates an error:

Microsoft OLE DB Provider for Indexing Service error '80040e14'

Incorrect syntax near '(null)'. SQLSTATE=42000

/library/newsearch.asp, line 12

Also, what I really want to do is substitute the name of a catalog to search, not a directory.

Can anybody provide guidance on how to do what I want?

Thanks,

Steve
0
Comment
Question by:skbohler
  • 4
  • 3
10 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 10807053
0
 

Author Comment

by:skbohler
ID: 10807405
Thanks.

I now get the error:

Microsoft OLE DB Provider for Indexing Service error '8004181d'

There is no catalog.
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 10807486
You need to create a Catalog in the Index Service first.

Try this:

1. Go to the Start > Programs > Administrative Tools > Computer Management
2. Click on Services and Applications, then select Indexing Service. If there is no Indexing Service, you may need to install this Component.
3. Right click the Indexing Service, then select New > Catalog.
4. Type in the Catalog Name (that will using later in your script), and the location you need to indexing.
0
 

Author Comment

by:skbohler
ID: 10807517
I already have a  catalog (it's called "goebasedev").

When I inserted that between the Chr(34)'s, I still got the same error message.

Any thoughts?

Thanks,
Steve
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 49

Expert Comment

by:Ryan Chong
ID: 10807581
Try:

sqlString = "SELECT DocTitle FROM SCOPE('" & Chr(34) & "/dev_goebase_com" & Chr(34) & "') WHERE FreeText(Contents,'mentoring') > 0 "

0
 

Author Comment

by:skbohler
ID: 10807942
I'm afraid the error message is the same.

Our catalog's name is goebasedev. Is there a place I should be specifying that?

Steve
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 10810950
Try other example on the links i posted above, which may use other technology (ixsso.Query - Index Server Object) to doing the File Indexing?

In additional, here is an example i had done few years ago:

Name the file as search.asp:

<%
      Server.ScriptTimeout = 500
      'on error resume next
      startURL = "http://www.mydomain.net/af"
      startURL1 = "http://www.mydomain.net"
      'startURL = "http://127.0.0.1"
      
      para = ""
      chkdoc = ""
      chksize = ""
      chkdate = ""
      fileequal = ""
      filesize = ""
      datemodified = ""
      operator = ""
      sortby = "Rank"
      orderby = "d"
                  
      if isEmpty(request("para")) then
            gotPara = false
      else
            if Request("para") = "" then
                  gotPara = false
            else            
                  para = Replace(Request("para"),"'","''")
                  
                  chkdoc = "" & Request("chkdoc")
                  chksize = "" & Request("chksize")
                  chkdate = "" & Request("chkdate")
                  fileequal = "" & Request("fileequal")
                  filesize = "" & Request("filesize")
                  datemodified = "" & Request("datemodified")
                  operator = "" & Request("operator")
                  sortby = "" & Request("sortby")
                  orderby = "" & Request("orderby")
                  
                  gotPara = True
            end if
      End if
%>
<html>
<head>
<title>Demo Search</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<Script languange = "Javascript">
      function chkformat(obj,format) {
            var ok = true;
            if (obj.value.length == 0) {
                  ok = false;
            } else {
                  for (var i=0; i<obj.value.length; i++) {
                        temp = "" + obj.value.substring(i, i+1);
                        if (format.indexOf(temp) == "-1") ok = false;break;
                  }
            }
            return ok;
      }
      

      function verify(frm) {
            if (frm.para.value == "") {
                  alert('Please enter Keyword to search');
                  frm.para.focus();
                  return false;
            }
            if (frm.chksize.checked) {
                  if (frm.fileequal.options[frm.fileequal.selectedIndex].value == "") {
                        alert('Please select File Size');
                        frm.fileequal.focus();
                        return false;
                  }
                  if (chkformat(frm.filesize,"0123456789") == false) {
                        alert('Please enter numeric File Size');
                        frm.filesize.focus();
                        frm.filesize.select();
                        return false;
                  }
            }
            if (frm.chkdate.checked) {
                  if (frm.datemodified.value == "") {
                        alert('Please enter Date Modified');
                        frm.datemodified.focus();
                        return false;
                  }
                  if (checkdate(frm.datemodified) == false) {
                        alert('Please enter valid Date Modified');
                        frm.datemodified.focus();
                        frm.datemodified.select();
                        return false;
                  }
            }
            if (frm.operator.options[frm.operator.selectedIndex].value == "") {
                  alert('Please select Operator');
                  frm.operator.focus();
                  return false;
            }
            if (frm.sortby.options[frm.sortby.selectedIndex].value == "") {
                  alert('Please select Sort By');
                  frm.sortby.focus();
                  return false;
            }
            if (frm.orderby.options[frm.orderby.selectedIndex].value == "") {
                  alert('Please select Order By');
                  frm.orderby.focus();
                  return false;
            }
            return true;
      }
</script>

<script language="Javascript1.2" src="js/af.js"></script>
<script language="Javascript1.2" src="js/checkdate.js"></script>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="search.asp" onsubmit="Javascript:return verify(this);">
  <table width="600" cellspacing="0" cellpadding="0" border="1" bordercolor="#000000">
    <tr>
      <td>
        <table width="600" cellspacing="0" cellpadding="2">
          <tr bgcolor="#006699">
            <td width="5">&nbsp;</td>
            <td width="88"><b><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">Search</font></b></td>
            <td colspan="2">&nbsp;</td>
          </tr>
          <tr>
            <td width="5">&nbsp;</td>
            <td width="88"><font face="Arial, Helvetica, sans-serif" size="2"><b>Keyword:
              </b></font> </td>
            <td colspan="2">
              <input type="text" name="para" maxlength="255" value="<%=para%>" size="30">
            </td>
          </tr>
          <tr>
            <td width="5"><font face="Arial, Helvetica, sans-serif" size="2"></font></td>
            <td width="88"><font face="Arial, Helvetica, sans-serif" size="2"></font></td>
            <td colspan="2"><font face="Arial, Helvetica, sans-serif" size="2"></font></td>
          </tr>
          <tr>
            <td width="5"><font face="Arial, Helvetica, sans-serif" size="2"></font></td>
            <td width="88"><font face="Arial, Helvetica, sans-serif" size="2"><b>Search
              with:</b></font></td>
            <td colspan="2"><font face="Arial, Helvetica, sans-serif" size="2"></font></td>
          </tr>
          <tr>
            <td width="5"><font face="Arial, Helvetica, sans-serif" size="2"></font></td>
            <td width="88" align="center"><font face="Arial, Helvetica, sans-serif" size="2">
              <input type="checkbox" name="chkdoc" value="Yes" <%=chkopt(chkdoc,"Yes","checked")%>>
              </font></td>
            <td colspan="2"><font face="Arial, Helvetica, sans-serif" size="2">Document
              Title</font></td>
          </tr>
          <tr>
            <td width="5"><font face="Arial, Helvetica, sans-serif" size="2"></font></td>
            <td width="88" align="center"><font face="Arial, Helvetica, sans-serif" size="2">
              <input type="checkbox" name="chksize" value="Yes" <%=chkopt(chksize,"Yes","checked")%>>
              </font></td>
            <td width="87"><font face="Arial, Helvetica, sans-serif" size="2">Size
              </font></td>
            <td width="402">
              <select name="fileequal">
                <option value="=" <%=chkopt(fileequal,"=","selected")%>>=</option>
                <option value="<" <%=chkopt(fileequal,"<","selected")%>>&lt;</option>
                <option value="<=" <%=chkopt(fileequal,"<=","selected")%>>&lt;=</option>
                <option value=">" <%=chkopt(fileequal,">","selected")%>>&gt;</option>
                <option value=">=" <%=chkopt(fileequal,">=","selected")%>>&gt;=</option>
              </select>
              <input type="text" name="filesize" maxlength="3" value="<%=filesize%>" size="2">
              <font face="Arial, Helvetica, sans-serif" size="2">Kbs</font> </td>
          </tr>
          <tr>
            <td width="5"><font face="Arial, Helvetica, sans-serif" size="2"></font></td>
            <td width="88" align="center"><font face="Arial, Helvetica, sans-serif" size="2">
              <input type="checkbox" name="chkdate" value="Yes" <%=chkopt(chkdate,"Yes","checked")%>>
              </font></td>
            <td width="87"><font face="Arial, Helvetica, sans-serif" size="2">Date
              Modified</font></td>
            <td width="402">
              <input type="text" name="datemodified" maxlength="10" value="<%=datemodified%>" size="8">
              <font face="Arial, Helvetica, sans-serif" size="2"> (dd/mm/yyyy)
              </font></td>
          </tr>
          <tr>
            <td width="5">&nbsp;</td>
            <td width="88"><font face="Arial, Helvetica, sans-serif" size="2"><b>Operator:</b></font></td>
            <td colspan="2">
              <select name="operator">
                <option value="AND" <%=chkopt(operator,"AND","selected")%>>And</option>
                <option value="OR" <%=chkopt(operator,"OR","selected")%>>Or</option>
              </select>
            </td>
          </tr>
          <tr>
            <td width="5"><font face="Arial, Helvetica, sans-serif" size="2"></font></td>
            <td width="88"><font face="Arial, Helvetica, sans-serif" size="2">
              </font></td>
            <td colspan="2"><font face="Arial, Helvetica, sans-serif" size="2"></font></td>
          </tr>
          <tr>
            <td width="5" height="22">&nbsp;</td>
            <td width="88" height="22"><b><font face="Arial, Helvetica, sans-serif" size="2">Sort
              By:</font></b></td>
            <td colspan="2" height="22">
              <select name="sortby">
                <option value="Rank" <%=chkopt(sortby,"Rank","selected")%>>Rank</option>
                <option value="DocTitle" <%=chkopt(sortby,"DocTitle","selected")%>>Title</option>
                <option value="Path" <%=chkopt(sortby,"Path","selected")%>>Path</option>
                <option value="Size" <%=chkopt(sortby,"Size","selected")%>>Size</option>
                <option value="write" <%=chkopt(sortby,"write","selected")%>>Modified</option>
              </select>
            </td>
          </tr>
          <tr>
            <td width="5">&nbsp;</td>
            <td width="88"><b><font face="Arial, Helvetica, sans-serif" size="2">Order
              By:</font></b></td>
            <td colspan="2">
              <select name="orderby">
                <option value="a" <%=chkopt(orderby,"a","selected")%>>Ascending</option>
                <option value="d" <%=chkopt(orderby,"d","selected")%>>Descending</option>
              </select>
            </td>
          </tr>
          <tr>
            <td width="5">&nbsp;</td>
            <td width="88">&nbsp;</td>
            <td colspan="2">&nbsp;</td>
          </tr>
          <tr>
            <td width="5">&nbsp;</td>
            <td colspan="3">
              <input type="submit" name="Submit" value="Search Now">
              <input type="reset" name="Reset" value="Reset">
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
  <br>
</form>
<p>
  <%
      map = lcase(Server.mappath("./"))
      map1 = "c:\sites\mydomain.com.sg\www\"
      'response.write("map: " & map)
      if gotPara = True then
            
            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 = para
            
            ' 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    = "goebasedev"  ' Catalog to query
                                                
                        if chkdoc <> ""  then                         
                              strQuery = strQuery & " " & operator & " DocTitle like " & strQuery & " "
                        end if
                        if chksize <> ""  then                         
                              strQuery = strQuery & " " & operator & " @Size " & fileequal & " " & CInt(filesize) * 1024 & " "
                        end if
                        if chkdate <> ""  then                         
                              converteddate = right(datemodified,4) & "/" & mid(datemodified,4,2) & "/" & mid(datemodified,1,2)
                              strQuery = strQuery & " " & operator & " (@write >= " & converteddate & " 00:00:00 And @write <=" & converteddate & " 23:59:59) "                              
                        end if
                        strQuery = strQuery & " And (not #filename search.asp) And #filename *.|(htm|,html|,shtml|,asp|,aspx|) And #path " & map & "*"
                        
                        .Query      = strQuery     ' Query text
                        
                        'response.write(strQuery & "<br>")
                        .MaxRecords = 300           ' Max # of records to return
            
                        ' What to sort records by.  I'm sorting by rank [d]
                        ' which is [d]escending by how pertinent Index Server
                        ' thinks the result is.  This way the most applicable
                        ' result should be first.
                        .SortBy = sortby & " [" & orderby & "]"
                        
                        'response.write(.SortBy & "<br>")
                        'response.end
                        
                        ' Which columns to return.  Column names must
                        ' be the same as the catalog's properties.  Some
                        ' of them are: contents, filename, size, path,
                        ' vpath, hitcount, rank, create, write, DocTitle
                        ' DocSubject, DocAuthor, DocKeywords...
                        .Columns = "filename, contents, path, vpath, size, " _
                              & "characterization, create, write, DocTitle, DocSubject, DocAuthor, " _
                              & "DocKeywords, rank, hitcount"
                  End With
                  
                  ' 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 "<font face='Arial, Helvetica, sans-serif' size='2'>Sorry. No results found.</font>"
                  Else
                        ' Print out # of results
                        Response.Write "<p><font face='Arial, Helvetica, sans-serif' size='2'><strong>"
                        Response.Write rstResults.RecordCount
                        Response.Write "</strong> results found:</font></p>"
                        
                        %>
<table width="600" cellspacing="0" cellpadding="2">
  <%
                        
                        ' Loop through results
                        i=1
                        Do While Not rstResults.EOF
                        
                              if i mod 2 = 0 then
                                    color1 = "#DDFFDD"
                                    color2 = "#ECFFEC"
                              else
                                    color1 = "#DDFFF9"
                                    color2 = "#F4FFFD"
                              end if
                              i=i+1
                  
                              ' Loop through Fields
                              ' Formatting leaves something to be desired,
                              ' but it'll work for now.  We'll pretty things
                              ' up and link to the content in part II.
                              'For Each objField in rstResults.Fields
                              
                              %>
  <tr>
    <td width="130" bgcolor="<%=color1%>" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Filename:
      </font></td>
    <td width="460" bgcolor="<%=color2%>" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">
      <%
          if instr(rstResults("Path"),map)>0 then
                  apath = Replace(rstResults("Path"),map,"")
                  fURL = startURL                  
            else
                  apath = Replace(rstResults("Path"),map1,"/")
                  fURL = startURL1
            end if            
      %>
      <a href="<%=fURL%><%=apath%>" target="_blank"><%=rstResults( "filename" )%></a> </font></td>
  </tr>
  <tr>
    <td width="130" bgcolor="<%=color1%>" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Subject:</font></td>
    <td width="460" bgcolor="<%=color2%>" valign="top"><font face="Arial, Helvetica, sans-serif" size="2"><%=rstResults( "DocTitle" )%></font></td>
  </tr>
  <tr>
    <td width="130" bgcolor="<%=color1%>" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Rank:</font></td>
    <td width="460" bgcolor="<%=color2%>" valign="top"><font face="Arial, Helvetica, sans-serif" size="2"><%=Round(rstResults( "Rank" )/10,2)%> %</font></td>
  </tr>
  <tr>
    <td width="130" bgcolor="<%=color1%>" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Size:</font></td>
    <td width="460" bgcolor="<%=color2%>" valign="top"><font face="Arial, Helvetica, sans-serif" size="2"><%=Int(cInt(rstResults( "size" ))/1024)%> k</font></td>
  </tr>
  <tr>
    <td width="130" bgcolor="<%=color1%>" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Write:</font></td>
    <td width="460" bgcolor="<%=color2%>" valign="top"><font face="Arial, Helvetica, sans-serif" size="2"><%=FormatDateTime(rstResults( "Write" ),1)%></font></td>
  </tr>
  <tr>
    <td width="130" bgcolor="<%=color1%>" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Characterization:</font></td>
    <td width="460" bgcolor="<%=color2%>" valign="top"><font face="Arial, Helvetica, sans-serif" size="2"><%=rstResults( "Characterization" )%></font></td>
  </tr>
  <%
                        
                              rstResults.MoveNext
                        Loop
                        %>
</table>
                        <%
                  End If
            
                  ' Kill our recordset object
                  Set rstResults = Nothing
            End If

      
      End if
%>

</body>
</html>

<%
      function chkopt(newstype, v, selected)
            if newstype = v then
                  chkopt = selected
            else
                  chkopt = ""
            end if
      end function
      
      sub debug(v)
            response.write(v)
            response.end
      end sub
      
      function getMonth(v)
            Select case v
            case "01"
                  getMonth = "Jan"
            case "02"
                  getMonth = "Feb"
            case "03"
                  getMonth = "Mar"
            case "04"
                  getMonth = "Apr"
            case "05"
                  getMonth = "May"
            case "06"
                  getMonth = "Jun"
            case "07"
                  getMonth = "Jul"
            case "08"
                  getMonth = "Aug"
            case "09"
                  getMonth = "Sep"
            case "10"
                  getMonth = "Oct"
            case "11"
                  getMonth = "Nov"
            case "12"
                  getMonth = "Dec"
            end select
      End function
%>

Try customize the code to run..

Hope this works
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12734526
PAQed with no points refunded (of 250)

modulo
Community Support Moderator
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now