dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Index Server Search Query

  1. #1
    Dion Guest

    Index Server Search Query


    Hey guys,

    I'm having trouble getting my head around the query language for an Index
    Server Search w/ASP.

    I have some dummy content pages that have text like "this file contains things"
    and "this file contains stuff".

    I've tried these two queries:

    =============
    SELECT DocTitle, VPath, Path, Filename, Rank FROM SCOPE('DEEP TRAVERSAL OF
    "c:\inetpub\wwwroot\"')
    WHERE ((CONTAINS(' "file contains" ') >0)
    AND ((Path NOT LIKE '%\_vti%') AND (Path NOT LIKE '%\_private%') AND (Filename
    NOT LIKE 'search.asp')))
    ORDER BY Rank DESC
    =============

    And:

    =============
    SELECT DocTitle, VPath, Path, Filename, Rank FROM SCOPE('DEEP TRAVERSAL OF
    "c:\inetpub\wwwroot\"')
    WHERE ((CONTAINS(' "file" AND "contains" ') >0)
    AND ((Path NOT LIKE '%\_vti%') AND (Path NOT LIKE '%\_private%') AND (Filename
    NOT LIKE 'search.asp')))
    ORDER BY Rank DESC
    =============

    With neither returning results.

    If I query just "file" or "fil*" I get matches fine.

    Also, if I query "*ile" I get no matches.

    Any idea where I'm going wrong? Any help would be very much appreciated.

  2. #2
    Jake Guest

    Re: Index Server Search Query


    Make sure you have a catalog set up to query (SomeCatalogName is the catalog
    in my example). My Indexing Service is running on my IIS server. Your connection
    string might need to be modified if yours is not.

    Here is how I do it:

    Set conn = Server.CreateObject("ADODB.Connection")
    Set rs = Server.CreateObject("ADODB.Recordset")

    strConn = "Provider=MSIDXS; Data Source=SomeCatalogName" 'Data Source is
    a catalog name
    conn.open strConn

    strSQL = "SELECT FILENAME, " _
    & "DOCCATEGORY, " _
    & "DOCSUBJECT, " _
    & "DOCTITLE, " _
    & "DOCAUTHOR " _
    & "FROM SCOPE() "
    & "WHERE FILENAME LIKE '%.pdf'"
    Set rs = conn.execute(strSQL)

    'Do some rs stuff here

    rs.close
    conn.close
    Set rs = Nothing
    Set conn = Nothing

    Jake

    ------------------------------------------------------------------
    "Dion" <dion@dimeboxmedia.co.nz> wrote:
    >
    >Hey guys,
    >
    >I'm having trouble getting my head around the query language for an Index
    >Server Search w/ASP.
    >
    >I have some dummy content pages that have text like "this file contains

    things"
    >and "this file contains stuff".
    >
    >I've tried these two queries:
    >
    >=============
    >SELECT DocTitle, VPath, Path, Filename, Rank FROM SCOPE('DEEP TRAVERSAL

    OF
    >"c:\inetpub\wwwroot\"')
    > WHERE ((CONTAINS(' "file contains" ') >0)
    > AND ((Path NOT LIKE '%\_vti%') AND (Path NOT LIKE '%\_private%') AND (Filename
    >NOT LIKE 'search.asp')))
    > ORDER BY Rank DESC
    >=============
    >
    >And:
    >
    >=============
    >SELECT DocTitle, VPath, Path, Filename, Rank FROM SCOPE('DEEP TRAVERSAL

    OF
    >"c:\inetpub\wwwroot\"')
    > WHERE ((CONTAINS(' "file" AND "contains" ') >0)
    > AND ((Path NOT LIKE '%\_vti%') AND (Path NOT LIKE '%\_private%') AND (Filename
    >NOT LIKE 'search.asp')))
    > ORDER BY Rank DESC
    >=============
    >
    >With neither returning results.
    >
    >If I query just "file" or "fil*" I get matches fine.
    >
    >Also, if I query "*ile" I get no matches.
    >
    >Any idea where I'm going wrong? Any help would be very much appreciated.



  3. #3
    Dion Guest

    Re: Index Server Search Query


    Hey Jake, thanks for the reply. I'm using the same connect string etc. as
    you too.

    It works fine for single word searches, but if I try an exact phrase or two
    words, I get no results. Any ideas? I'm almost at the end of the road trying
    to crack this one!

  4. #4
    Jake Duckworth Guest

    Re: Index Server Search Query


    Here is how I choose which WHERE clauses I use, maybe this might help you:


    strWhere = Trim(Replace(Request.Form("txtSearchFor"), "'", "''"))
    Select Case Request("cboSearchType")
    Case "1" 'Contains (And)
    'Only allow "AND" search. First replace all keywords and operators

    'with a space, then replace all spaces with the operator " & "
    'for "AND"
    strWhere = Replace(strWhere, " and ", " ")
    strWhere = Replace(strWhere, " or ", " ")
    strWhere = Replace(strWhere, " near ", " ")
    strWhere = Replace(strWhere, " & ", " ")
    strWhere = Replace(strWhere, " | ", " ")
    strWhere = Replace(strWhere, " ~ ", " ")
    strWhere = Trim(strWhere)
    strWhere = Replace(strWhere, " ", " ")
    strWhere = Replace(strWhere, " ", " ")
    strWhere = Replace(strWhere, " ", " & ") strSearch = strSearch & "WHERE
    CONTAINS ('" & strWhere & "') "
    Case "2" 'Contains (Or)
    'Only allow "OR" search. First replace all keywords and operators

    'with a space, then replace all spaces with the operator " | "
    'for "OR"
    strWhere = Replace(strWhere, " and ", " ")
    strWhere = Replace(strWhere, " or ", " ")
    strWhere = Replace(strWhere, " near ", " ")
    strWhere = Replace(strWhere, " & ", " ")
    strWhere = Replace(strWhere, " | ", " ")
    strWhere = Replace(strWhere, " ~ ", " ")
    strWhere = Trim(strWhere)
    strWhere = Replace(strWhere, " ", " ")
    strWhere = Replace(strWhere, " ", " ")
    strWhere = Replace(strWhere, " ", " | ") strSearch = strSearch & "WHERE
    CONTAINS ('" & strWhere & "') "
    Case "3" 'Contains (Near)
    'Only allow "NEAR" search. First replace all keywords and operators

    'with a space, then replace all spaces with the operator " ~ "
    'for "NEAR"
    strWhere = Replace(strWhere, " and ", " ")
    strWhere = Replace(strWhere, " or ", " ")
    strWhere = Replace(strWhere, " near ", " ")
    strWhere = Replace(strWhere, " & ", " ")
    strWhere = Replace(strWhere, " | ", " ")
    strWhere = Replace(strWhere, " ~ ", " ")
    strWhere = Trim(strWhere)
    strWhere = Replace(strWhere, " ", " ")
    strWhere = Replace(strWhere, " ", " ")
    strWhere = Replace(strWhere, " ", " ~ ") strSearch = strSearch & "WHERE
    CONTAINS ('" & strWhere & "') "
    Case "4" 'Exact Match
    strSearch = strSearch & "WHERE CONTAINS ('""" & strWhere & """') "
    Case "5" 'FreeText
    strSearch = strSearch & "WHERE FREETEXT('" & strWhere & "') "
    End Select

    strSQL = "SELECT FILENAME, " _
    & "DOCCATEGORY, " _
    & "DOCSUBJECT, " _
    & "DOCTITLE, " _
    & "DOCAUTHOR " _
    & "FROM SCOPE() "
    & strWhere



    Hope this helps

    Jake Duckworth


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center