I have written a search page that, with the help of the magic of
JavaScript, allows users to select either how many days ago a document was
modified or documents within a set range of dates and then sets the
startday, endday, etc., values appropriately (this overcomes the inability
of a regular web page to contain two options, in this case startday, by
the same name). It also contains some other nice functionality
(automatically sets the correct number of days for the month selected,
prevents restrict and exclude options from clobbering each other, etc.).
The one disadvantage of using this page (aside from requiring JavaScript)
is that it always sets at least startday, so it will add overhead to
htsearch as it will always examine the date for each hit to make sure it
falls within the range. That could easily be overcome in the checkStartday
function by only setting values to startday, endday, etc., if they had
been changed from the default. I'm not noticing huge slowness in searches,
so I didn't bother.
Maintainers, feel free to put this into the contrib directory somewhere. I
couldn't find anything there that did this sort of thing, so my apologies
if this is a duplicate of something already out there.
Bill Knox
Senior Operating Systems Programmer/Analyst
The MITRE Corporation
<!-- Search web page written by William Knox ([EMAIL PROTECTED]), 2/2002 -->
<html>
<head>
<title>ht://Dig Hostname Search</title>
<script language="JavaScript">
// Functions to reset the other select list to the first entry if the
// select list in question is changed to something other than the first entry
function checkRestrict() {
if (document.searchdoc.restrict.selectedIndex != 0) {
document.searchdoc.exclude.selectedIndex = 0;
}
return;
}
function checkExclude() {
if (document.searchdoc.exclude.selectedIndex != 0) {
document.searchdoc.restrict.selectedIndex = 0;
}
return;
}
// Function to reset the days back select list to the first (blank) entry if
// the date select lists are changed
function checkRange() {
if (document.searchdoc.startday_number.selectedIndex != 0) {
document.searchdoc.startday_number.selectedIndex = 0;
}
return;
}
// Function to change the day of month select list to make sure that it has
// the correct number of days for the month (and year - leap years) selected
function changeDateList(date_obj, month_obj, year_obj) {
month_set = month_obj.selectedIndex;
year_set = year_obj[year_obj.selectedIndex].value;
var days_in_month = [31,28,31,30,31,30,31,31,30,31,30,31];
if (year_set%4 == 0 && (year_set%400 == 0 || year_set%100 != 0)) {
days_in_month[1] = 29;
}
date_list = date_obj.options;
chosen_day = date_obj[date_obj.selectedIndex].value;
date_list.length = days_in_month[month_set];
var count = 0;
var something_selected = 0;
while (count < days_in_month[month_set]) {
date_list[count] = new Option();
date_list[count].value = count + 1;
date_list[count].text = count + 1;
if (count + 1 == chosen_day) {
date_list.selectedIndex = count;
something_selected = 1;
}
count++;
}
if (! something_selected) {
date_list.selectedIndex = count - 1;
}
checkRange();
}
// Function called upon submission to rename the startday_* and endday_*
// variables depending on whether an entry was made in the days back range
function checkStartday() {
var chosen = document.searchdoc.startday_number.selectedIndex;
if (chosen != 0) {
document.searchdoc.startday.value =
document.searchdoc.startday_number[chosen].value;
}
else {
document.searchdoc.startday.value =
document.searchdoc.startday_range[document.searchdoc.startday_range.selectedIndex].value
document.searchdoc.startmonth.value =
document.searchdoc.startmonth_range[document.searchdoc.startmonth_range.selectedIndex].value;
document.searchdoc.startyear.value =
document.searchdoc.startyear_range[document.searchdoc.startyear_range.selectedIndex].value;
document.searchdoc.endday.value =
document.searchdoc.endday_range[document.searchdoc.endday_range.selectedIndex].value
document.searchdoc.endmonth.value =
document.searchdoc.endmonth_range[document.searchdoc.endmonth_range.selectedIndex].value;
document.searchdoc.endyear.value =
document.searchdoc.endyear_range[document.searchdoc.endyear_range.selectedIndex].value;
}
}
// Function to properly populate the date select menus
function setDates() {
var today = new Date();
var this_day = today.getDate();
var this_month = today.getMonth();
var this_year = today.getFullYear();
var days_in_month = [31,28,31,30,31,30,31,31,30,31,30,31];
if (this_year%4 == 0 && (this_year%400 == 0 || this_year%100 != 0)) {
days_in_month[1] = 29;
}
document.searchdoc.endmonth_range.selectedIndex = this_month;
document.searchdoc.endday_range.length = days_in_month[this_month];
var day_count = 0;
while (day_count < days_in_month[this_month]) {
document.searchdoc.endday_range[day_count] = new Option();
document.searchdoc.endday_range[day_count].value = day_count + 1;
document.searchdoc.endday_range[day_count].text = day_count + 1;
if (day_count + 1 == this_day) {
document.searchdoc.endday_range.selectedIndex = day_count;
}
day_count++;
}
var year_count = 0;
while (year_count + 1996 <= this_year) {
document.searchdoc.endyear_range[year_count] = new Option();
document.searchdoc.endyear_range[year_count].value = year_count +
1996;
document.searchdoc.endyear_range[year_count].text = year_count + 1996;
year_count++;
}
document.searchdoc.endyear_range.selectedIndex = year_count - 1;
changeDateList(document.searchdoc.endday_range,
document.searchdoc.endmonth_range, document.searchdoc.endyear_range);
}
</script>
</head>
<body bgcolor="#FFFFFF" onLoad=setDates()>
<h1>
<a href="http://www.htdig.org"><img src="/htdig/htdig.gif" align="bottom"
alt="ht://Dig" border="0"></a>
Hostname Site Search</h1>
<hr noshade size="4">
This search will allow you to search the contents of
all the publicly available web documents at this site.
<br>
<p>
<form method="post" action="/cgi-bin/htsearch" onSubmit="checkStartday()"
name="searchdoc">
<font size="-1">
Match: <select name="method">
<option value="and">All
<option value="or">Any
<option value="boolean">Boolean
</select>
Format: <select name="format">
<option value="builtin-long">Long
<option value="builtin-short">Short
</select>
Sort by: <select name="sort">
<option value="score">Score
<option value="time">Time
<option value="title">Title
<option value="revscore">Reverse Score
<option value="revtime">Reverse Time
<option value="revtitle">Reverse Title
</select>
</font>
<input type="hidden" name="config" value="htdig">
<br>
Search:
<input type="text" size="30" name="words" value="">
<BR>
Limit to: <select name="restrict" onChange=checkRestrict();>
<option value="">the whole server
<option value="documentation/">the documentation
<option value="mail/">the mail archives
</select>
Exclude from search: <select name="exclude" onChange=checkExclude();>
<option value="">nothing
<option value="documentation/">the documentation
<option value="mail/">the mail archives
</select>
<BR>
Number of matches per page: <select name="matchesperpage">
<option>10
<option selected>25
<option>50
<option>100
</select>
<input type="hidden" name="startday" value="">
<input type="hidden" name="startmonth" value="">
<input type="hidden" name="startyear" value="">
<input type="hidden" name="endday" value="">
<input type="hidden" name="endmonth" value="">
<input type="hidden" name="endyear" value="">
<HR ALIGN=LEFT WIDTH=5%>
Modified within the past <select name="startday_number">
<option selected value="">
<option value="-7">7
<option value="-14">14
<option value="-30">30
<option value="-60">60
<option value="-90">90
<option value="-120">120
</select>
days<P>
OR<P>
Modified between <select name="startmonth_range"
onChange="changeDateList(startday_range, startmonth_range, startyear_range)">
<option selected value="1">Jan
<option value="2">Feb
<option value="3">Mar
<option value="4">Apr
<option value="5">May
<option value="6">Jun
<option value="7">Jul
<option value="8">Aug
<option value="9">Sep
<option value="10">Oct
<option value="11">Nov
<option value="12">Dec
</select>
<select name="startday_range" onChange="checkRange()">
<option selected value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8">8
<option value="9">9
<option value="10">10
<option value="11">11
<option value="12">12
<option value="13">13
<option value="14">14
<option value="15">15
<option value="16">16
<option value="17">17
<option value="18">18
<option value="19">19
<option value="20">20
<option value="21">21
<option value="22">22
<option value="23">23
<option value="24">24
<option value="25">25
<option value="26">26
<option value="27">27
<option value="28">28
<option value="29">29
<option value="30">30
<option value="31">31
</select>
<select name="startyear_range" onChange="changeDateList(startday_range,
startmonth_range, startyear_range)">
<option selected value="1996">1996
<option value="1997">1997
<option value="1998">1998
<option value="1999">1999
<option value="2000">2000
<option value="2001">2001
<option value="2002">2002
</select>
and
<select name="endmonth_range" onChange="changeDateList(endday_range, endmonth_range,
endyear_range)">
<option value="1">Jan
<option value="2">Feb
<option value="3">Mar
<option value="4">Apr
<option value="5">May
<option value="6">Jun
<option value="7">Jul
<option value="8">Aug
<option value="9">Sep
<option value="10">Oct
<option value="11">Nov
<option value="12">Dec
</select>
<select name="endday_range" onChange="checkRange()">
<option value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8">8
<option value="9">9
<option value="10">10
<option value="11">11
<option value="12">12
<option value="13">13
<option value="14">14
<option value="15">15
<option value="16">16
<option value="17">17
<option value="18">18
<option value="19">19
<option value="20">20
<option value="21">21
<option value="22">22
<option value="23">23
<option value="24">24
<option value="25">25
<option value="26">26
<option value="27">27
<option value="28">28
<option value="29">29
<option value="30">30
<option value="31">31
</select>
<select name="endyear_range" onChange="changeDateList(endday_range, endmonth_range,
endyear_range)">
<option value="1996">1996
<option value="1997">1997
<option value="1998">1998
<option value="1999">1999
<option value="2000">2000
<option value="2001">2001
<option value="2002">2002
</select>
<BR>
<input type="submit" value="Search">
</form>
<hr noshade size="4">
</body>
</html>