|
|
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<!--------------------------------------------------------------------------
// // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. // // Copyright 1998-2000 Microsoft Corporation. All Rights Reserved. // // PROGRAM: Ciquery.htm // // PURPOSE: Illustrates use of Dynamic HTML to build a client-side // query page used to access Indexing Service. // // PLATFORM: Windows 2000 // //-------------------------------------------------------------------------->
<HTML> <HEAD>
<TITLE>Indexing Services Dynamic HTML Sample</TITLE> <META NAME="DESCRIPTION" CONTENT="Indexing Services client-side query form"> <META NAME="AUTHOR" CONTENT="Indexing Service Team"> <META NAME="KEYWORDS" CONTENT="Indexing Services, query, content, hit"> <META NAME="SUBJECT" CONTENT="Sample form"> <META NAME="MS.CATEGORY" CONTENT="Internet"> <META NAME="MS.LOCALE" CONTENT="EN-US"> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"> <base target="_blank"> </HEAD>
<BODY OnLoad="Init()" LANGUAGE="VBScript"> <center> <DIV ID="idTransDiv" ALIGN=CENTER STYLE="position:0; top:0; height:0; width:500; filter:revealTrans(duration=3.0, transition=5);"> <H2 id="idHead" STYLE="position:0; visibility:visible; margin-bottom:0;"> <font color=Blue> Indexing Service Query Form </font></H2> </DIV>
</center> <br>
<!-- This table contains the user-entry form. -->
<div align=center> <TABLE bgcolor=ffffcc cellpadding=2 cellspacing=3 Border=3 WIDTH=400> <TR><td> <div id="QueryHeader"><b><LABEL FOR=SrchStrCtrl NAME="UserSearchString"> </LABEL></b></div> <INPUT ID="SrchStrCtrl" TYPE="TEXT" NAME="UserSearchString" SIZE="50" MAXLENGTH="100" TABINDEX=1> <BUTTON TYPE=SUBMIT ID="CmdGo"> <FONT SIZE=-1>Search</FONT> </BUTTON> <br> <INPUT TYPE="RADIO" ID = StdQryButton NAME="radioQueryType" VALUE="0" checked onclick="StandardSelected()"> <LABEL FOR=StdQryButton ID=StdqryButtonId> </LABEL> <br> <INPUT TYPE="RADIO" ID = AdvQryButton NAME="radioQueryType" VALUE="1" onclick="AdvancedSelected()"> <LABEL FOR=AdvQryButton ID=AdvQryButtonId> </LABEL> <br>
<div align=right> <A HREF="ixqlang.htm" target=_self ID=TipId> </A></div> <LABEL FOR=SortCtrl ID=SortCtrlId> <b> </b> </LABEL> <SELECT ID = SortCtrl NAME="selectSort" onchange="SortOrderSelected()"> <OPTION SELECTED VALUE="Rank" ID=RankId> ????? <OPTION VALUE="DocTitle" ID=Title2Id> ????? <OPTION VALUE="Path" ID=Path2Id> ????? <OPTION VALUE="Size" ID=Size2Id> ????? <OPTION VALUE="Write" ID=Write2Id> ????? </SELECT> <LABEL FOR=OrderCtrl ID=OrderCtrlId> <b> </b> </LABEL> <SELECT ID = OrderCtrl NAME="selectOrder" onchange="SortOrderSelected()"> <OPTION SELECTED VALUE="[d]" ID=DescendingId> ????????????? <OPTION VALUE="[a]" ID=AscendingId> ????????????? </SELECT> <P><table ID=idUnfiltered cellspacing=0 cellpadding=0><tr><td> <LABEL ID=UnfilteredListId> </LABEL> </td><td><INPUT TYPE="button" VALUE="Unfiltered Docs" ID="UnfilteredDocsId" onclick="UnfilteredSelected()"></td></table> </TD></TR> </TABLE>
<p> <HR WIDTH=80% ALIGN=center SIZE=3> <p>
<!-- A couple of navigation buttons, initially disabled. -->
<a id=JumpPoint name="ResultPart"></a> <table width=775 ID=TopButt> <tr><td> <FORM NAME=Navigation ALIGN=RIGHT> <INPUT TYPE="BUTTON" NAME="CmdPrevious" VALUE=" ???????? "> <INPUT TYPE="BUTTON" NAME="CmdNext" VALUE=" ??????? "> </FORM>
<BR> <P ID=Counter><EM> </EM> <BR>
<!--
-- This is the output table. Result rows will by dynamically added, but the header will -- just be hidden until needed. --> </td></td> </table> <!-- <br><INPUT TYPE="BUTTON" NAME="SortRank" VALUE="Sort by Ascending Rank"> -->
<P> <TABLE bgcolor=ffffcc ID=Results COLS=3 CELLSPACING=1 CELLPADDING=3> <TR bgcolor=99cccc> <TH> <LABEL ID=SerialId> ?? </LABEL> </TH> <TH> <LABEL ID=TitleId> ??????? </LABEL> </TH> <TH> <LABEL ID=SizeId> ??????? </LABEL> </TH> <TH> <LABEL ID=ModifiedId> ????????? </LABEL> </TH> <TH> <LABEL ID=PathId> ????? </LABEL> </TH> </TR> </TABLE>
<table width=775 ID=BottomButt> <tr><td> <br><br> <FORM NAME=Navigation2 ALIGN=RIGHT> <INPUT TYPE="BUTTON" NAME="CmdPrevious" VALUE=" ????????? "> <INPUT TYPE="BUTTON" NAME="CmdNext" VALUE=" ???????? "> </FORM> </td></tr> </table>
</BODY>
<SCRIPT LANGUAGE=VBSCRIPT>
Const L_Title_Text = "Title" Const L_Size_Text = "Size" Const L_Modified_Text = "Modified" Const L_Path_Text = "Path" Const L_Rank_Text = "Rank" Const L_StdQryButton_Text = "Standard query (free text)" Const L_AdvQryButton_Text = "Advanced query" Const L_SortBy_Text = "Sort by: " Const L_OrderBy_Text = "Order by: " Const L_SearchTips_Text = "Tips for searching" Const L_Ascending_Text = "Ascending" Const L_Descending_Text = "Descending" Const L_Previous_Text = "Previous" Const L_Next_Text = "Next" Const L_UnfilteredLabel_Text = "To see a list of unfiltered documents click:" Const L_UnfilteredCmd_Text = "Unfiltered Docs" Const L_SerialNum_Text = "#" Const L_Period_Text = "." DIM RS ' The ADO Recordset. Initially null. DIM SortBy ' Current sort order DIM FirstOnPage, LastOnPage ' Keeps track of records being shown DIM MaxDisplayed ' Max number of results displayed on-screen DIM machine,catalog DIM OrigLocation DIM fUnfiltered ' Unfiltered query was requested. DIM fFreetext ' Free text query was requested
' ' SubRoutine: Init ' ' Synopsis: Initializes the page. Sets defaults for page-global variables ' and DHTML elements. Initially, no query is active. '
Private SUB Init() ' Make the heading roll into view ' idHead.style.visibility = "hidden" ' idTransDiv.filters.item(0).apply() ' idTransDiv.filters.item(0).transition = 3 ' idHead.style.visibility = "visible" ' idTransDiv.filters(0).play(1.000)
UserSearchString.focus Navigation.CmdPrevious.Disabled = TRUE Navigation.CmdNext.Disabled = TRUE Navigation2.CmdPrevious.Disabled = TRUE Navigation2.CmdNext.Disabled = TRUE FirstOnPage = 0 LastOnPage = 0 MaxDisplayed = 25 fUnfiltered = FALSE SortBy = "Rank[d]" 'Parse the catalog name out of the URL 'No need to localize "catalog", "machine" because they are hidden 'from the user. 'URL syntax is: file://<syspath>/help/ciquery.htm#machine=<machine>,catalog=<catalog> catPos = InStr(1, Document.Location.Hash, "catalog=", 1) catPos = catPos + 8 'catalog name is at the end of the string catalog = Right(Document.Location.Hash, len(Document.Location.Hash) - catPos + 1) catalog = DecodeToken(catalog) 'Parse the machine name out of the URL macPos = InStr(1, Document.Location.Hash, "machine=", 1) macPos = macPos + 8 'machine name is between "machine=" and ",catalog=" commaPos = InStr(macPos, Document.Location.Hash, ",catalog", 1) machine = Mid(Document.Location.Hash, macPos, commaPos - macPos) machine = DecodeToken(machine) StdQryButtonId.InnerText = CStr(L_StdQryButton_Text) AdvQryButtonId.InnerText = CStr(L_AdvQryButton_Text) SortCtrlId.InnerText = CStr(L_SortBy_Text) OrderCtrlId.InnerText = CStr(L_OrderBy_Text) TipId.InnerText = CStr(L_SearchTips_Text) DescendingId.InnerText = CStr(L_Descending_Text) AscendingId.InnerText = CStr(L_Ascending_Text) UnfilteredListId.InnerText = CStr(L_UnfilteredLabel_Text) UnfilteredDocsId.InnerText = CStr(L_UnfilteredCmd_Text) SerialId.InnerText = CStr(L_SerialNum_Text) TitleId.InnerText = CStr(L_Title_Text) ModifiedId.InnerText = CStr(L_Modified_Text) PathId.InnerText = CStr(L_Path_Text) SizeId.InnerText = CStr(L_Size_Text) Navigation.CmdPrevious.value = CStr(L_Previous_Text) Navigation.CmdNext.value = CStr(L_Next_Text) Navigation2.CmdPrevious.value = CStr(L_Previous_Text) Navigation2.CmdNext.value = CStr(L_Next_Text) Document.All.Counter.innerHTML = CStr(L_NoResults_Text) RankId.InnerText = CStr(L_Rank_Text) Title2Id.InnerText= CStr(L_Title_Text) Path2Id.InnerText = CStr(L_Path_Text) Size2Id.InnerText = CStr(L_Size_Text) Write2Id.InnerText = CStr(L_Modified_Text) 'Check the state of buttons and init accordingly IF StdQryButton.Checked THEN call StandardSelected ELSE call AdvancedSelected end if
HideTable() HideBottomButt()
END SUB
Const L_Freetext_Text="<LABEL FOR=SrchStrCtrl> <b>Enter your free text query below:</b> </LABEL>" Const L_Advanced_Text="<LABEL FOR=SrchStrCtrl> <b>Enter your advanced query below:</b> </LABEL>"
' ' SubRoutine: StandardSelected() ' ' Synopsis: Queries will be free-text ' Private SUB StandardSelected() Document.All.QueryHeader.innerHTML = CStr(L_Freetext_Text) fFreetext = TRUE END SUB
' ' SubRoutine: AdvancedSelected ' ' Synopsis: Allows for advanced queries to be executed ' Private SUB AdvancedSelected() Document.All.QueryHeader.innerHTML = CStr(L_Advanced_Text) fFreetext = FALSE END SUB ' ' SubRoutine: UnfilteredSelected() ' ' Synopsis: Searches for unfiltered documents ' Private SUB UnfilteredSelected() fUnfiltered = TRUE CmdGo_OnClick() END SUB
' ' SubRoutine: SortOrderSelected() ' ' Synopsis: Sets the sort order as selected by the user ' Private SUB SortOrderSelected() IF StrComp(selectSort.value, "DocTitle") = 0 THEN SortBy = selectSort.value & selectOrder.value & ",Filename" & selectOrder.value ELSE SortBy = selectSort.value & selectOrder.value END IF END SUB
' ' SubRoutine: CmdNext_OnClick() ' ' Synposis: Displays next page of query results. '
Private SUB CmdNext_OnClick() NextPage() END SUB
' ' SubRoutine: CmdPrevious_OnClick() ' ' Synposis: Displays previous page of query results. ' Private SUB CmdPrevious_OnClick() RS.Move( -MaxDisplayed - LastOnPage + FirstOnPage ) NextPage() END SUB
Const L_CreationStatus_Text="Creating query object..." Const L_IssuingStatus_Text="Issuing query..." ' ' SubRoutine: CmdGo_OnClick ' ' Synopsis: Executes query ' Private SUB CmdGo_OnClick() ON ERROR RESUME NEXT ' ' Setup Query '
Window.Status = L_CreationStatus_Text SET Q = CreateObject("ixsso.Query")
SET U = CreateObject("ixsso.Util") Q.LocaleID = U.ISOToLocaleID(navigator.userLanguage)
Q.DefineColumn "Unfiltered(DBTYPE_BOOL, 1) = 49691c90-7e17-101a-a91c-08002b2ecda9 7" Q.Catalog = "query://"+ machine + "/" + catalog Q.SortBy = SortBy Q.Columns = "DocTitle, FileName, Path, Write, Size" Q.Dialect = 2
' ' The default use of the query form should be completely freetext. ' Advanced users can then use all of the features of the query language ' by having the check boxed checked. ' IF fUnfiltered THEN CompSearch = "@Unfiltered=TRUE" fUnfiltered = FALSE ELSEIF fFreetext = TRUE THEN CompSearch = "{freetext}" & UserSearchString.value & "{/freetext}" ELSE CompSearch = UserSearchString.value END IF
' ' The query is now set up. Time to execute. '
IF CompSearch <> "" THEN Q.Query = CompSearch
' Issue query Window.Status = L_IssuingStatus_Text set RS = Q.CreateRecordSet("nonsequential")
Navigation.CmdPrevious.Disabled = TRUE Navigation.CmdNext.Disabled = TRUE Navigation2.CmdPrevious.Disabled = TRUE Navigation2.CmdNext.Disabled = TRUE HideBottomButt()
IF Err.Number = 0 THEN NextPage() ELSE ReportError Err.Number, Err.Description Err.Clear() END IF END IF END SUB
' ' SubRoutine: NextPage ' ' Synopsis: Workhorse routine to populate table with results ' Const L_QueryMatched_Text="Query matched " Const L_Records_Text=" record(s)" Const L_NoResults_Text="<EM>No results</EM>" Const L_NoResultsNoEm_Text="No results" Const L_PopulatingList_Text="Populating result list (row " Const L_Of_Text=" of " Const L_NowShowing_Text=" Now showing " Const L_To_Text=" to " Const L_Period1_Text="." Const L_Period2_Text="." ' working with date format: Change DateSeparator if necessary ' reposition mm (month), dd (day), yyyy (year) without changing the ' the individual tokens. Const L_DateSeparator_Text="/" Const L_DateFormat_Text = "mm-dd-yyyy" Private SUB NextPage ' ' Populate result list. Once this message is displayed, virtually all the time is being ' spent in DHTML and not in query processing. '
fFirstPage = TRUE
' ' Did we actually get anything back? ' IF RS.RecordCount = 0 THEN IF Err.Number = 0 THEN Document.All.Counter.innerHTML = CStr(L_NoResults_Text) Window.Status = CStr(L_NoResultsNoEm_Text) MsgBox CStr(L_NoResultsNoEm_Text) ELSE ReportError Err.Number, Err.Description END IF JumpPoint.scrollintoview ( FALSE ) FirstOnPage = 0 Navigation.CmdNext.Disabled = TRUE Navigation.CmdPrevious.Disabled = TRUE Navigation2.CmdPrevious.Disabled = TRUE Navigation2.CmdNext.Disabled = TRUE HideBottomButt() HideTable() ELSE JumpPoint.scrollintoview ( TRUE ) FirstOnPage = RS.AbsolutePosition LastOnPage = FirstOnPage Document.All.Counter.innerText = CStr(L_QueryMatched_Text) + CStr(RS.RecordCount) + CStr(L_Records_Text) ShowTable() END IF
' ' Loop through the table. For each row, either store values from Recordset or delete ' the row. ' FOR i = 1 TO MaxDisplayed
Window.Status = CStr(L_PopulatingList_Text) + CStr(i) + CStr(L_Of_Text) + Cstr(MaxDisplayed) + ")"
IF RS.EOF THEN ' ' We hit the end. Just clear any remaining rows and fall out of loop. '
FOR j = Results.Rows.length - 1 TO i STEP -1 Results.DeleteRow(j) NEXT
EXIT FOR ELSE ' ' We may have to add a row... '
IF i >= Results.Rows.length THEN Results.InsertRow()
FOR j = 0 TO 4 Results.Rows(i).InsertCell() NEXT
Results.Rows(i).Cells(0).align = "right" Results.Rows(i).Cells(2).align = "right" Results.Rows(i).Cells(3).align = "right" END IF
' Write record number Results.Rows(i).Cells(0).innerText = CStr( RS.AbsolutePosition ) + CStr(L_Period_Text)
' Write either title or filename IF VarType(RS("DocTItle")) = 1 Or RS("DocTItle") = "" THEN Results.Rows(i).Cells(1).innerHTML = "<A HREF=""file://" & RS("path") & """>" & RS("fIlename") & "</A>" ELSE Results.Rows(i).Cells(1).innerHTML = "<A HREF=""file://" & RS("path") & """>" & RS("DocTItle") & "</A>" END IF
' Size Results.Rows(i).Cells(2).innerText = RS("SIze")
' Last Modify time WriteTime = CDate( RS("WrIte") ) Results.Rows(i).Cells(3).innerText = PrintDate( CStr( L_DateFormat_Text), CStr(L_DateSeparator_Text), CStr(Month(WriteTime)), CStr(Day(WriteTime)), CStr(Year(WriteTime) ) )
' Path Results.Rows(i).Cells(4).innerHTML = "<A HREF=""file://" & RS("path") & """>" & RS("Path") & "</A>"
LastOnPage = LastOnPage + 1
RS.MoveNext END IF NEXT
' ' Report result. '
IF FirstOnPage <> LastOnPage And RS.RecordCount <> 0 THEN ' "Query matched 392 record(s). Now showing 1 to 25." Document.All.Counter.innerHTML = CStr(L_QueryMatched_Text) + CStr(RS.RecordCount) + CStr(L_Records_Text) + CStr(L_Period1_Text) + CStr(L_NowShowing_Text) + CStr(FirstOnPage) + CStr(L_To_Text) + CStr(LastOnPage-1) + CStr(L_Period2_Text) END IF
' ' Enable Previous/Next as appropriate '
IF FirstOnPage <= 1 THEN Navigation.CmdPrevious.Disabled = TRUE Navigation2.CmdPrevious.Disabled = TRUE ELSE Navigation.CmdPrevious.Disabled = FALSE Navigation2.CmdPrevious.Disabled = FALSE END IF
IF RS.EOF THEN Navigation.CmdNext.Disabled = TRUE Navigation2.CmdNext.Disabled = TRUE UserSearchString.focus ELSE Navigation.CmdNext.Disabled = FALSE Navigation.CmdNext.focus Navigation2.CmdNext.Disabled = FALSE END IF IF Navigation2.CmdPrevious.Disabled = FALSE OR Navigation2.CmdNext.Disabled = FALSE THEN ShowBottomButt() END IF
' ' Done! '
Window.Status = Window.DefaultStatus
END SUB
' ' SubRoutine: HideBottomButt ' ' Synopsis: Hides the bottom button table from the user's view. '
SUB HideBottomButt() BottomButt.Rows(0).Cells(0).style.visibility = "hidden"
BottomButt.Border = 0 BottomButt.Rules = ""
FOR i = BottomButt.Rows.length - 1 TO 1 STEP -1 BottomButt.DeleteRow(i) NEXT END SUB
' ' SubRoutine: ShowBottomButt ' ' Synopsis: Shows the bottom button table from the user's view. '
SUB ShowBottomButt() BottomButt.Rows(0).Cells(0).style.visibility = "visible"
BottomButt.Border = 0 BottomButt.Rules = ""
END SUB ' ' SubRoutine: HideTable ' ' Synopsis: Hides the table from the user's view. '
SUB HideTable() Results.Rows(0).Cells(0).style.visibility = "hidden" Results.Rows(0).Cells(1).style.visibility = "hidden" Results.Rows(0).Cells(2).style.visibility = "hidden" Results.Rows(0).Cells(3).style.visibility = "hidden" Results.Rows(0).Cells(4).style.visibility = "hidden"
Results.Border = 0 Results.Rules = ""
FOR i = Results.Rows.length - 1 TO 1 STEP -1 Results.DeleteRow(i) NEXT END SUB
' ' SubRoutine: ShowTable ' ' Synopsis: Makes the result table visible. '
SUB ShowTable() Results.Rows(0).Cells(0).style.visibility = "visible" Results.Rows(0).Cells(1).style.visibility = "visible" Results.Rows(0).Cells(2).style.visibility = "visible" Results.Rows(0).Cells(3).style.visibility = "visible" Results.Rows(0).Cells(4).style.visibility = "visible"
Results.Border = 1 Results.Rules = "cols"
END SUB FUNCTION DecodeToken( Token ) 'Replace all escaped characters with their original characters '%20 --> ' ' 'Characters that must be encoded include any characters that have no 'corresponding graphic character in the US-ASCII coded character set '(hexadecimal 80-FF, which are not used in the US-ASCII coded character 'set, and hexadecimal 00-1F and 7F, which are control characters), blank 'spaces, "%" (which is used to encode other characters), and unsafe 'characters (<, >, ", #, {, }, |, \, ^, ~, [, ], and '). ' This doesn't cover all possible cases, just the SPACE, which is ' the most common case. Token = Replace(Token, "%20", " ") DecodeToken = Token END FUNCTION
' ' SubRoutine: ReportError ' ' Synopsis: Clears table and reports error. ' ' Arguments: [ErrNo] -- Error to report ' Const L_RedError_Text="<FONT color=red><EM><B>Error "
SUB ReportError( ErrNo, ErrDesc ) HideTable() Window.Status = Err.Description MsgBox Err.Description UserSearchString.focus Document.All.Counter.innerHTML = CStr(L_RedError_Text) + Hex(Err.Number) + " - " + Err.Description + "</B></EM></FONT>" END SUB
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript"> function PrintDate(DateFormat, DateSeparatorText, Month, Day, Year) { var FormattedDate
FormattedDate = DateFormat.replace("mm", Month) FormattedDate = FormattedDate.replace("dd", Day) FormattedDate = FormattedDate.replace("yyyy", Year) FormattedDate = FormattedDate.replace("-", DateSeparatorText) FormattedDate = FormattedDate.replace("-", DateSeparatorText) return FormattedDate }
</SCRIPT>
</HTML>
|