묻고답하기
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
영어, 숫자만 되는 검색엔진 - 한글도 검색되게 할 순 없나요
2007.02.26 23:44
http://www.livestock.co.kr/~livestock/livestock/infovet-kr/start.htm영어, 숫자만 되는 검색엔진 - 한글도 검색되게 할 순 없나요
외국사이트의 검색엔진 소스를 적용했는데 영어와 숫자는 검색이 잘 되는데
한글은 검색이 안됩니다.
한글로 "자료"라고 입력하고 검색하면 '"Ú·á"는 찿을 수 없다고 나오는 군요
제생각으로는
sfunc.js 와 extend.js에서
checkchr 로 시작되는 구문을 수정하면 될 것 같은데 잘 안되는군요
고수님들 한글도 검색되게 수정 좀 부탁드립니다.
홈페이지는
http://www.livestock.co.kr/~livestock/livestock/infovet-kr/start.htm 입니다.
꼭 좀 부탁드립니다.
아래에 검색엔진 소스를 첨부 파일로 올리니 한번 봐주시기 바랍니다.
start.htm 입니다. 일반적인 index.htm과 같습니다.
<html>
<head>
<title>Dairy Manual</title>
<meta http-equiv="Content-Language" content="euc-kr">
<base target="_parent">
</head>
<frameset cols="216,*">
<frameset rows="156,*">
<frame name="searchform" target="bottom" src="sform.htm" scrolling="auto">
<frame name="toc" src="toc.htm" target="main">
</frameset>
<frameset rows="32,*,15%">
<frame name="tools" target="bottom" src="tools.htm" scrolling="no">
<frame name="main" scrolling="auto" src="title.htm" >
<frame name="bottom" src="blank.htm" target="main" scrolling="auto">
</frameset>
<noframes>
<body>
<p>This page uses frames, but your browser doesn't support them.</p>
</body>
</noframes>
</frameset>
</html>
sform.htm 입니다. 검색할 단어를 기입하고 검색버튼을 누르면 됩니다.
<html>
<head>
<title>Untitled Document</title>
<base target="bottom">
<style>
<!--
form { margin-top: 8; margin-bottom: 12 }
-->
</style>
</head>
<body style="font-family: Arial" bgcolor="#FFFFFF" topmargin="8" leftmargin="8">
<SCRIPT LANGUAGE="JavaScript">
<!--
function valid(form)
{
var field = form.searchField.value;
var checkchr = 0;
for(var i = 0; i < field.length; i++)
{
checkchr = field.charCodeAt(i);
if(checkchr != 32)
{
}
}
}
// -->
</SCRIPT>
<a href="http://www.livestock.co.kr" target="_parent"><img border="0" src="Images/IVC.gif" width="180" height="59"></a>
<form name="searchForm" action="sresult.htm" onSubmit="return valid(this)">
<b>
검색하기</b><br>
<input type="text" name="searchField" size="20"><br>
<select size="1" name="srcriteria">
<option selected value="phrase">Exact phrase</option>
<option value="all">All words</option>
<option value="any">Any words</option>
</select> <input type="Submit" name="Submit" value="Go">
</form>
</body>
</html>
sresult.htm 입니다. 검색 결과를 보여주는 frame입니다.
여기서 sfunc.js 와 extend.js 를 이용하여 sindex.js에서 검색어를 찿아내는 기능을 수행합니다.
<html>
<head>
<meta http-equiv="Content-Language" content="euc-kr">
<script language="JavaScript" SRC="sfunc.js"></SCRIPT>
<script language="JavaScript" SRC="extend.js"></SCRIPT>
<script language="JavaScript" SRC="sindex.js"></SCRIPT>
<title>Search Results</title>
<base target="main">
<style>
<!--
body { font-family: Arial; font-size: 9pt }
-->
</style>
</head>
<body style="font-family: ??" bgcolor="#FFFFFF">
<font face="Arial, Helvetica, 굴림, sans-serif" size="2">
<SCRIPT language="Javascript">
doSearch()
</SCRIPT>
</font>
</body>
</html>
sfunc.js 입니다.
/*
This search routine is based on the free Recon Search Engine
by Jerry Bradenbaugh (http://www.serve.com/hotsyte/)
alterations have been made by Marc Reed (http://www.marcreed.com)
This script may be used for free
Further modifications by Infovets
*/
// Define global variables
// the maxPages variable determines how
// many results are displayed per page:
var maxPages = 10;
var allMatch = new Array();
var phraseMatch = new Array();
var anyMatch = new Array();
var urlMatch = new Array();
var indexer = 0;
var srcCrit = "any"
var count = 0;
var start = 0;
var urlTest = false;
var findwords = new Array();
var strtarget=" ";
//Search Results page should call this function
function doSearch() {
fullEntry = getQueryString('searchField');
filteredEntry = ""
//clean up spaces at beginning of string
while (fullEntry.charAt(0) == '+') {
fullEntry = fullEntry.substring(1,fullEntry.length);
}
//clean up spaces at end of string
while (fullEntry.charAt(fullEntry.length - 1) == '+') {
fullEntry = fullEntry.substring(0,fullEntry.length - 1);
}
//Look for ++(clean up multiple spaces)
var PlusSigns = "++"
while (fullEntry.indexOf(PlusSigns) >= 0) {
fullEntry=fullEntry.replace(/++/, "+")
}
//Isolate search term(s) and convert "+" to spaces
for (i=0; i<fullEntry.length; i++) {
if ((fullEntry.charAt(i) == "&")||(fullEntry.charAt(i) == "#")) {
break
}
if (fullEntry.charAt(i) == "+") {
filteredEntry = (filteredEntry+" ")
}else {
filteredEntry = (filteredEntry+(fullEntry.charAt(i)))
}
}
if (filteredEntry.indexOf("#") > -1) filteredEntry = filteredEntry.substring(0, filteredEntry.indexOf("#"));
validate(filteredEntry);
}
//This generic function will return the value of a QueryString
function getQueryString(Val) {
thisURLparamStr = document.location.search;
//chop "?" off thisURLparamStr
if (thisURLparamStr.charAt(0) == "?") thisURLparamStr = thisURLparamStr.substring(1, thisURLparamStr.length);
returnStr = "";
if (thisURLparamStr != "") {
//Build array out of thisURLparamStr using "&" as delimiter
divide1=(thisURLparamStr.split("&"))
for (i=0; i < divide1.length; i++) {
divide2 = divide1[i].split("=")
if (unescape(divide2[0]) == Val) {
returnStr = unescape(divide2[1]);
}
}
}
return returnStr;
}
//Determine any word/all words/phrase search
function validate(text) {
var entry = text;
//clean up spaces at beginning of string
while (entry.charAt(0) == ' ') {
entry = entry.substring(1,entry.length);
}
//clean up spaces at end of string
while (entry.charAt(entry.length - 1) == ' '+ '+ ') {
entry = entry.substring(0,entry.length - 1);
}
if ((entry.charAt(0) == "+")||(getQueryString('srcriteria') == "all")) {
entry = (entry.charAt(0) == "+")? entry.substring(1,entry.length):entry;
srcCrit = "all"
}
if (entry.substring(0,4) == "url:") {
entry = entry.substring(5,entry.length);
srcCrit = "url"
}
//If user wants exact phrase
if (((entry.charAt(0) == """)&&(entry.charAt((entry.length)-1) == """))||(getQueryString('srcriteria') == "phrase")){
while (entry.indexOf(""") > -1) {
entry=entry.replace(/"/, "")
}
srcCrit = "phrase"
}
if (entry.length < 3) {
alert("All the words or exact phrase must be longer than three characters.");
return;
}
convertString(entry, text);
}
// If not exact phrase, split the entry string into an array
function convertString(reentry, text) {
//If user wants exact phrase
if (srcCrit == "phrase") {
findwords = searchTerm = reentry;
requirePhrase(searchTerm, text);
return;
}
findwords = searchArray = reentry.split(" ");
//check if each word is longer than 3 letters because the previous check doesn't catch these
for(i=0; i<searchArray.length; i++)
{
if (searchArray[i].length < 3)
{
alert("All the words or exact phrase must be longer than three characters.");
return;
}
}
if (srcCrit == "any") { allowAny(searchArray, text); return; }
if (srcCrit == "all") { requireAll(searchArray, text); return; }
if (srcCrit == "url") { parseURL(searchArray, text); return; }
}
//*************************************************************
// This function merges title, brief description, page content,
// keywords and returns all-caps string
//*************************************************************
function mergeCaps(str1, str2, str3) {
mergeStr = "";
// join str2 (brief description) and str3 (rest of page text)
// if page content is longer than brief description length,
// then str2 ends "..."
// if str2 ends "..." remove dots
if ((str2.length > 0) && (str2.charAt(0) != " ")) str2 = " " + str2;
if (str2.substring(str2.length - 3, str2.length) == "...") {
mergeString = str2.substring(0, str2.length - 3).concat(str3);
} else {
mergeString = str2.concat(str3);
}
mergeString = str1 + mergeString
//to make search case-insensitive, convert to all caps
return mergeString.toUpperCase();
}
//*************************************************************************
// This function will parse the URL search string and change a name/value pair
//*************************************************************************
function changeParam(whichParam, newVal) {
newParamStr = "";
thisURLstr = document.location.href.substring(0, document.location.href.indexOf("?"));
thisURLparamStr = document.location.href.substring(document.location.href.indexOf("?") + 1, document.location.href.length);
//Build array out of thisURLparamStr using "&" as delimiter
divide1=(thisURLparamStr.split("&"))
for (cnt=0; cnt < divide1.length; cnt++) {
divide2 = divide1[cnt].split("=")
if (divide2[0] == whichParam) {
// if we find whichParam in thisURLparamStr replace whichParam's value with newVal
newParamStr = newParamStr + divide2[0] + "=" + escape(newVal) + "&";
} else {
//leave other parameters intact
newParamStr = newParamStr + divide2[0] + "=" + divide2[1] + "&";
}
}
//strip off trailing ampersand
if (newParamStr.charAt(newParamStr.length - 1) == "&") newParamStr = newParamStr.substring(0, newParamStr.length - 1);
//apply new URL
return(thisURLstr + "?" + newParamStr);
}
//*************************************************************
// Sorts search results based on 1.Number of hits 2.aplhabetically
//*************************************************************
function compare(a, b) {
if (parseInt(a) - parseInt(b) != 0) {
return parseInt(a) - parseInt(b)
}else {
var aComp = a.substring(a.indexOf("|") + 1, a.length)
var bComp = b.substring(b.indexOf("|") + 1, b.length)
if (aComp < bComp) {return -1}
if (aComp > bComp) {return 1}
return 0
}
}
//Evoked if user searches ANY WORDS
function allowAny(t, text) {
var OccurNum = 0;
for (i = 0; i < profiles.length; i++) {
//strip url out of search string
var refineElement = "";
var splitline = profiles[i].split("|");
refineElement = mergeCaps(splitline[0], splitline[1], splitline[2])
OccurNum = 0;
for (j = 0; j < t.length; j++) {
eval("myRE = /" + "[^a-zA-Z0-9_]" + t[j] + "/gi");
OccurArray = refineElement.match(myRE);
if (OccurArray != null) OccurNum = OccurNum + OccurArray.length;
}
if (OccurNum > 0) {
anyMatch[indexer] = (0-OccurNum) + "|" + profiles[i];
indexer++;
}
}
if (anyMatch.length == 0) { // If no matches are found, print a no match
noMatch(text); // HTML document
return;
}
else { formatResults(anyMatch, text); } // Otherwise, generate a results document
}
//Evoked if user searches ALL WORDS
function requireAll(t, text) {
var OccurNum = 0;
for (i = 0; i < profiles.length; i++) {
var allConfirmation = true;
var refineAllString = "";
var splitline = profiles[i].split("|");
refineAllString = mergeCaps(splitline[0], splitline[1], splitline[2])
OccurNum = 0;
for (j = 0; j < t.length; j++) {
eval("myRE = /" + "[^a-zA-Z0-9_]" + t[j] + "/gi");
OccurArray = refineAllString.match(myRE);
if (OccurArray != null) {
OccurNum = OccurNum + OccurArray.length;
} else {
allConfirmation = false;
}
}
if (allConfirmation) {
allMatch[indexer] = (0-OccurNum) + "|" + profiles[i];
indexer++;
}
}
if (allMatch.length == 0) {
noMatch(text);
return;
} else {
formatResults(allMatch, text);
}
}
//If user wants exact phrase
function requirePhrase(t, text) {
for (i = 0; i < profiles.length; i++) {
var allConfirmation = true;
//strip url out of search string
var refineAllString = "";
var splitline = profiles[i].split("|");
refineAllString = mergeCaps(splitline[0], splitline[1], splitline[2])
var allElement = t.toUpperCase();
var OccurNum = 0;
eval("myRE = /" + "[^a-zA-Z0-9_]" +t + "/gi");
OccurArray = refineAllString.match(myRE);
if (OccurArray != null) {
OccurNum = OccurNum + OccurArray.length;
phraseMatch[indexer] = (0-OccurNum) + "|" + profiles[i];
indexer++;
}
}
if (phraseMatch.length == 0) {
noMatch(text);
return;
}
else { formatResults(phraseMatch, text); }
}
function parseURL(u, text) { // Incite the search, looking only in the URL portion of the string
for (i = 0; i < profiles.length; i++) {
var urlConfirmation = true;
var anyURL = profiles[i].toUpperCase();
//strip url out of search string
var splitline = anyURL.split("|");
var refineAnyURL = splitline[splitline.length - 1];
var OccurNum = 0;
for (j = 0; j < u.length; j++) {
var urlPart = u[j].toUpperCase();
if (refineAnyURL.indexOf(urlPart) != -1 && (urlConfirmation)) {
urlConfirmation = false;
urlMatch[indexer] = (0-OccurNum) + "|" + profiles[i];
indexer++;
}
}
}
if (urlMatch.length == 0) {
noMatch(text);
return;
}
else {
urlTest = true;
formatResults(urlMatch, text, urlTest);
}
}
//*************************************************************
// Format no-results page
//*************************************************************
function noMatch(text) { // Dyanmic HTML page with no results
document.writeln("<a name="top_of_page"></a><h3>Search Results</h3>");
document.writeln("<h4><hr size="1"><b>'" + text + "' returned no results.<hr size="1"><h4>");
return true;
}
//*************************************************************
// Format successfull search results page
//*************************************************************
function formatResults(passedArray, text, urlTest) {
results = passedArray;
pgRange = (getQueryString("range") != "")? parseInt(getQueryString("range")):1;
//document.writeln("<hr size="1">Search Query: " + text + " ");
document.writeln("<font size="2">Search Results: "+ passedArray.length + " ");
document.writeln("Search Query: " + text);
document.writeln("<hr size="1">");
thisPg = 1;
endPg = passedArray.length;
if (passedArray.length > maxPages) {
thisPg = (maxPages * pgRange) - (maxPages - 1);
endPg = (parseInt(thisPg + (maxPages - 1)) < passedArray.length)? parseInt(thisPg + (maxPages - 1)):passedArray.length;
document.writeln(thisPg + " - " + endPg + " of " + passedArray.length);
}
document.writeln("<dl>");
passedArray.sort(compare);
wrdArray = (srcCrit != "phrase")? text.split(" "):new Array(text);
if (urlTest) {
for (i = 0; i < passedArray.length ; i++) {
divide = passedArray[i].split("|"); // Print each URL result as a unit of a definition list
document.writeln("<dt>" + "<a href=""+divide[4]+ "" target="_self">" + divide[4] + "</a></dt>");
document.writeln("<dd>" + divide[2] + "</dd><br><br>");
}
}
else {
for (i = (thisPg - 1); i < endPg; i++) {
divide = passedArray[i].split("|"); // Print each profile result as a unit of a definition list
for (j=0; j<wrdArray.length; j++) {
eval("myRE1 = /" + wrdArray[j] + "/gi");
regArr = null;
regArr = divide[2].match(myRE1);
if (regArr != null) {
//look for uniqueness in regArr
beenThere = new Array();
for (k=0; k<regArr.length; k++) {
beenhere = 0;
for (l=0; l<beenThere.length; l++) {
if (beenThere[l] == regArr[k]) {
beenhere = 1;
//break;
}
}
if (beenhere == 0) {
beenThere[beenThere.length] = regArr[k];
eval("myRE2 = /"+regArr[k]+"/g");
divide[2] = divide[2].replace(myRE2, "<|>" + regArr[k] + "</|>");
}
}
}
}
myRE3 = /<|>/g;
myRE4 = /</|>/g;
//divide[2] = divide[2].replace(myRE3, "<font color=red>");
//divide[2] = divide[2].replace(myRE4, "</font>");
divide[2] = divide[2].replace(myRE3, "");
divide[2] = divide[2].replace(myRE4, "");
//document.writeln("<dt><a href=javascript:overlink('"+divide[4]+"') target="main"><b>" + divide[1] + "</b></a><dt>");
//document.writeln("<dt><a href=""+divide[4]+"" onClick="setTimeout('findInPage();', 500)" target="main"><b>" + divide[1] + "</b></a><dt>");
//document.writeln("<dd>" + divide[2] + "</dd><br><br>");
document.writeln("<dt><a href=""+divide[4]+"" onClick="parent.frames[3].focus(); setTimeout('findInPage();', 250)" target="main"><b>" + divide[1] + "</b></a>");
document.writeln(" - " + divide[2] + "<dt><br>");
}
}
document.writeln("</dl>"); // Finish the HTML document
//write results page numbers
if (passedArray.length > maxPages) {
pgNum = parseInt(passedArray.length/maxPages);
if (passedArray.length/maxPages > pgNum) pgNum++;
pgLinks = "go to page: ";
for (i=0; i < pgNum; i ++) {
locationStr = (location.href.indexOf("&range=") > -1)? changeParam("range", parseInt(i + 1)):location.href + "&range=" + parseInt(i + 1);
pgLinks += (parseInt(i + 1) != pgRange)? "<a href="" + locationStr + "" target="_self">" + (i + 1) + "</a> ":"<b>" + (i + 1) + "</b> ";
}
document.writeln(pgLinks + "<hr size="1">");
}
clearOut();
}
function clearOut() { // Clear the arrays and variables generated from the current search
allMatch.length = 0; anyMatch.length = 0;
urlMatch.length = 0; divide.length = 0;
indexer = 0; all = false; urlTest = false;
}
extend.js 입니다.
/*
This script is by Infovets for added manual browsing functionality
*/
//global variables
var hitcount = 0;
var currenthit = 0;
var targetframe = 3;
var hitwordMG = "";
function showInPage()
{
//parent.frames[targetframe].document.write('Hey');
if (!document.all&&document.getElementById)
{
var bodyvar = parent.frames[targetframe].document.getElementsByTagName('body')[0];
var docvar = bodyvar.innerHTML;
if (srcCrit != "phrase")
{
for (i = 0; i < findwords.length; i++)
{
eval("myRE2 = /"+ "([^a-zA-Z])" +findwords[i]+"/gi");
//docvar = docvar.replace(myRE2, "n<font color='#bb0000'><b>" + findwords[i].toUpperCase() + "</b></font>");
docvar = docvar.replace(myRE2, "$1" + findwords[i].toUpperCase());
}
hitwordMG = findwords[0].toUpperCase();
}
else if (srcCrit == "phrase")
{
eval("myRE2 = /"+ "([^a-zA-Z])" +findwords+"/gi");
//docvar = docvar.replace(myRE2, "n<font color='#bb0000'><b>" + findwords.toUpperCase() + "</b></font>");
docvar = docvar.replace(myRE2, "$1" + findwords.toUpperCase());
hitwordMG = findwords.toUpperCase();
}
bodyvar.innerHTML = docvar;
setTimeout('nexthitMG();', 150);
}
else if(document.all)
{
hitcount = 0;
var temp = "";
var dist = 0;
var scroll = true;
var checkchr = 0;
var checklength = 0;
if (srcCrit != "phrase")
{
for (i = 0; i < findwords.length; i++)
{
var txt = parent.frames[targetframe].document.body.createTextRange();
var str = findwords[i];
var found = txt.findText(str);
while (found)
{
txt.moveStart("character", -1);
checkchr = txt.text.charCodeAt(0);
checklength = txt.text.length;
txt.findText(str);
temp= txt.text;
if(((checkchr < 65 || checkchr > 90) && (checkchr < 97 || checkchr > 122)) || (checklength == temp.length && temp.charCodeAt(0) == checkchr))
{
hitcount++;
txt.pasteHTML('<a name="hit'+hitcount+'"></a><span style="font-weight: bold; color: #bb0000;">'+temp+'</span>');
}
txt.moveStart("character", 1);
found = txt.findText(str);
}
}
}
else if (srcCrit == "phrase")
{
var txt = parent.frames[targetframe].document.body.createTextRange();
var str = findwords;
var found = txt.findText(str);
while (found)
{
txt.moveStart("character", -1);
checkchr = txt.text.charCodeAt(0);
checklength = txt.text.length;
txt.findText(str);
temp= txt.text;
if(((checkchr < 64 || checkchr > 91) && (checkchr < 96 || checkchr > 123)) || (checklength == temp.length && temp.charCodeAt(0) == checkchr))
{
hitcount++;
txt.pasteHTML('<a name="hit'+hitcount+'"></a><span style="font-weight: bold; color: #bb0000;">'+temp+'</span>');
}
txt.moveStart("character", 1);
found = txt.findText(str);
}
}
currenthit = 0;
nexthitIE();
}
}
function findInPage()
{
if (document.getElementById && !document.all)
parent.frames[targetframe].document.body.onload = setTimeout("showInPage()",100);
else if (parent.frames[targetframe].document.readyState == "complete" && document.all)
showInPage();
else if(document.getElementById && document.all)
setTimeout("findInPage()",100);
}
function nexthitIE()
{
if(hitcount!=0)
{
if(currenthit>=hitcount) currenthit=1;
else currenthit++;
parent.frames[targetframe].location.hash = "hit" + currenthit;
}
}
function prevhitIE()
{
if(hitcount!=0)
{
if(currenthit<=1) currenthit=hitcount;
else currenthit--;
parent.frames[targetframe].location.hash = "hit" + currenthit;
}
}
function nexthitMG()
{
if(hitwordMG)
{
parent.frames[targetframe].focus();
strFound=parent.frames[targetframe].find(hitwordMG, true, false, true, false, true, false);
if (!strFound)
{
changehitwordup();
strFound=parent.frames[targetframe].find(hitwordMG, true, false, true, false, true, false)
// while (parent.frames[targetframe].find("mare", false, false, true, false, true, false)) continue
}
}
}
function prevhitMG()
{
if(hitwordMG)
{
parent.frames[targetframe].focus();
strFound=parent.frames[targetframe].find(hitwordMG, true, true, true, false, true, false);
if (!strFound)
{
changehitworddown();
strFound=parent.frames[targetframe].find(hitwordMG, true, true, true, false, true, false)
// while (parent.frames[targetframe].find("foal", true, true, true, false, true, false)) continue
}
}
}
function changehitwordup()
{
if(srcCrit != "phrase")
{
if(currenthit>=findwords.length-1) currenthit=0;
else currenthit++;
hitwordMG = findwords[currenthit].toUpperCase();
}
}
function changehitworddown()
{
if(srcCrit != "phrase")
{
if(currenthit<=0) currenthit=findwords.length;
else currenthit--;
hitwordMG = findwords[currenthit].toUpperCase();
}}
외국사이트의 검색엔진 소스를 적용했는데 영어와 숫자는 검색이 잘 되는데
한글은 검색이 안됩니다.
한글로 "자료"라고 입력하고 검색하면 '"Ú·á"는 찿을 수 없다고 나오는 군요
제생각으로는
sfunc.js 와 extend.js에서
checkchr 로 시작되는 구문을 수정하면 될 것 같은데 잘 안되는군요
고수님들 한글도 검색되게 수정 좀 부탁드립니다.
홈페이지는
http://www.livestock.co.kr/~livestock/livestock/infovet-kr/start.htm 입니다.
꼭 좀 부탁드립니다.
아래에 검색엔진 소스를 첨부 파일로 올리니 한번 봐주시기 바랍니다.
start.htm 입니다. 일반적인 index.htm과 같습니다.
<html>
<head>
<title>Dairy Manual</title>
<meta http-equiv="Content-Language" content="euc-kr">
<base target="_parent">
</head>
<frameset cols="216,*">
<frameset rows="156,*">
<frame name="searchform" target="bottom" src="sform.htm" scrolling="auto">
<frame name="toc" src="toc.htm" target="main">
</frameset>
<frameset rows="32,*,15%">
<frame name="tools" target="bottom" src="tools.htm" scrolling="no">
<frame name="main" scrolling="auto" src="title.htm" >
<frame name="bottom" src="blank.htm" target="main" scrolling="auto">
</frameset>
<noframes>
<body>
<p>This page uses frames, but your browser doesn't support them.</p>
</body>
</noframes>
</frameset>
</html>
sform.htm 입니다. 검색할 단어를 기입하고 검색버튼을 누르면 됩니다.
<html>
<head>
<title>Untitled Document</title>
<base target="bottom">
<style>
<!--
form { margin-top: 8; margin-bottom: 12 }
-->
</style>
</head>
<body style="font-family: Arial" bgcolor="#FFFFFF" topmargin="8" leftmargin="8">
<SCRIPT LANGUAGE="JavaScript">
<!--
function valid(form)
{
var field = form.searchField.value;
var checkchr = 0;
for(var i = 0; i < field.length; i++)
{
checkchr = field.charCodeAt(i);
if(checkchr != 32)
{
}
}
}
// -->
</SCRIPT>
<a href="http://www.livestock.co.kr" target="_parent"><img border="0" src="Images/IVC.gif" width="180" height="59"></a>
<form name="searchForm" action="sresult.htm" onSubmit="return valid(this)">
<b>
검색하기</b><br>
<input type="text" name="searchField" size="20"><br>
<select size="1" name="srcriteria">
<option selected value="phrase">Exact phrase</option>
<option value="all">All words</option>
<option value="any">Any words</option>
</select> <input type="Submit" name="Submit" value="Go">
</form>
</body>
</html>
sresult.htm 입니다. 검색 결과를 보여주는 frame입니다.
여기서 sfunc.js 와 extend.js 를 이용하여 sindex.js에서 검색어를 찿아내는 기능을 수행합니다.
<html>
<head>
<meta http-equiv="Content-Language" content="euc-kr">
<script language="JavaScript" SRC="sfunc.js"></SCRIPT>
<script language="JavaScript" SRC="extend.js"></SCRIPT>
<script language="JavaScript" SRC="sindex.js"></SCRIPT>
<title>Search Results</title>
<base target="main">
<style>
<!--
body { font-family: Arial; font-size: 9pt }
-->
</style>
</head>
<body style="font-family: ??" bgcolor="#FFFFFF">
<font face="Arial, Helvetica, 굴림, sans-serif" size="2">
<SCRIPT language="Javascript">
doSearch()
</SCRIPT>
</font>
</body>
</html>
sfunc.js 입니다.
/*
This search routine is based on the free Recon Search Engine
by Jerry Bradenbaugh (http://www.serve.com/hotsyte/)
alterations have been made by Marc Reed (http://www.marcreed.com)
This script may be used for free
Further modifications by Infovets
*/
// Define global variables
// the maxPages variable determines how
// many results are displayed per page:
var maxPages = 10;
var allMatch = new Array();
var phraseMatch = new Array();
var anyMatch = new Array();
var urlMatch = new Array();
var indexer = 0;
var srcCrit = "any"
var count = 0;
var start = 0;
var urlTest = false;
var findwords = new Array();
var strtarget=" ";
//Search Results page should call this function
function doSearch() {
fullEntry = getQueryString('searchField');
filteredEntry = ""
//clean up spaces at beginning of string
while (fullEntry.charAt(0) == '+') {
fullEntry = fullEntry.substring(1,fullEntry.length);
}
//clean up spaces at end of string
while (fullEntry.charAt(fullEntry.length - 1) == '+') {
fullEntry = fullEntry.substring(0,fullEntry.length - 1);
}
//Look for ++(clean up multiple spaces)
var PlusSigns = "++"
while (fullEntry.indexOf(PlusSigns) >= 0) {
fullEntry=fullEntry.replace(/++/, "+")
}
//Isolate search term(s) and convert "+" to spaces
for (i=0; i<fullEntry.length; i++) {
if ((fullEntry.charAt(i) == "&")||(fullEntry.charAt(i) == "#")) {
break
}
if (fullEntry.charAt(i) == "+") {
filteredEntry = (filteredEntry+" ")
}else {
filteredEntry = (filteredEntry+(fullEntry.charAt(i)))
}
}
if (filteredEntry.indexOf("#") > -1) filteredEntry = filteredEntry.substring(0, filteredEntry.indexOf("#"));
validate(filteredEntry);
}
//This generic function will return the value of a QueryString
function getQueryString(Val) {
thisURLparamStr = document.location.search;
//chop "?" off thisURLparamStr
if (thisURLparamStr.charAt(0) == "?") thisURLparamStr = thisURLparamStr.substring(1, thisURLparamStr.length);
returnStr = "";
if (thisURLparamStr != "") {
//Build array out of thisURLparamStr using "&" as delimiter
divide1=(thisURLparamStr.split("&"))
for (i=0; i < divide1.length; i++) {
divide2 = divide1[i].split("=")
if (unescape(divide2[0]) == Val) {
returnStr = unescape(divide2[1]);
}
}
}
return returnStr;
}
//Determine any word/all words/phrase search
function validate(text) {
var entry = text;
//clean up spaces at beginning of string
while (entry.charAt(0) == ' ') {
entry = entry.substring(1,entry.length);
}
//clean up spaces at end of string
while (entry.charAt(entry.length - 1) == ' '+ '+ ') {
entry = entry.substring(0,entry.length - 1);
}
if ((entry.charAt(0) == "+")||(getQueryString('srcriteria') == "all")) {
entry = (entry.charAt(0) == "+")? entry.substring(1,entry.length):entry;
srcCrit = "all"
}
if (entry.substring(0,4) == "url:") {
entry = entry.substring(5,entry.length);
srcCrit = "url"
}
//If user wants exact phrase
if (((entry.charAt(0) == """)&&(entry.charAt((entry.length)-1) == """))||(getQueryString('srcriteria') == "phrase")){
while (entry.indexOf(""") > -1) {
entry=entry.replace(/"/, "")
}
srcCrit = "phrase"
}
if (entry.length < 3) {
alert("All the words or exact phrase must be longer than three characters.");
return;
}
convertString(entry, text);
}
// If not exact phrase, split the entry string into an array
function convertString(reentry, text) {
//If user wants exact phrase
if (srcCrit == "phrase") {
findwords = searchTerm = reentry;
requirePhrase(searchTerm, text);
return;
}
findwords = searchArray = reentry.split(" ");
//check if each word is longer than 3 letters because the previous check doesn't catch these
for(i=0; i<searchArray.length; i++)
{
if (searchArray[i].length < 3)
{
alert("All the words or exact phrase must be longer than three characters.");
return;
}
}
if (srcCrit == "any") { allowAny(searchArray, text); return; }
if (srcCrit == "all") { requireAll(searchArray, text); return; }
if (srcCrit == "url") { parseURL(searchArray, text); return; }
}
//*************************************************************
// This function merges title, brief description, page content,
// keywords and returns all-caps string
//*************************************************************
function mergeCaps(str1, str2, str3) {
mergeStr = "";
// join str2 (brief description) and str3 (rest of page text)
// if page content is longer than brief description length,
// then str2 ends "..."
// if str2 ends "..." remove dots
if ((str2.length > 0) && (str2.charAt(0) != " ")) str2 = " " + str2;
if (str2.substring(str2.length - 3, str2.length) == "...") {
mergeString = str2.substring(0, str2.length - 3).concat(str3);
} else {
mergeString = str2.concat(str3);
}
mergeString = str1 + mergeString
//to make search case-insensitive, convert to all caps
return mergeString.toUpperCase();
}
//*************************************************************************
// This function will parse the URL search string and change a name/value pair
//*************************************************************************
function changeParam(whichParam, newVal) {
newParamStr = "";
thisURLstr = document.location.href.substring(0, document.location.href.indexOf("?"));
thisURLparamStr = document.location.href.substring(document.location.href.indexOf("?") + 1, document.location.href.length);
//Build array out of thisURLparamStr using "&" as delimiter
divide1=(thisURLparamStr.split("&"))
for (cnt=0; cnt < divide1.length; cnt++) {
divide2 = divide1[cnt].split("=")
if (divide2[0] == whichParam) {
// if we find whichParam in thisURLparamStr replace whichParam's value with newVal
newParamStr = newParamStr + divide2[0] + "=" + escape(newVal) + "&";
} else {
//leave other parameters intact
newParamStr = newParamStr + divide2[0] + "=" + divide2[1] + "&";
}
}
//strip off trailing ampersand
if (newParamStr.charAt(newParamStr.length - 1) == "&") newParamStr = newParamStr.substring(0, newParamStr.length - 1);
//apply new URL
return(thisURLstr + "?" + newParamStr);
}
//*************************************************************
// Sorts search results based on 1.Number of hits 2.aplhabetically
//*************************************************************
function compare(a, b) {
if (parseInt(a) - parseInt(b) != 0) {
return parseInt(a) - parseInt(b)
}else {
var aComp = a.substring(a.indexOf("|") + 1, a.length)
var bComp = b.substring(b.indexOf("|") + 1, b.length)
if (aComp < bComp) {return -1}
if (aComp > bComp) {return 1}
return 0
}
}
//Evoked if user searches ANY WORDS
function allowAny(t, text) {
var OccurNum = 0;
for (i = 0; i < profiles.length; i++) {
//strip url out of search string
var refineElement = "";
var splitline = profiles[i].split("|");
refineElement = mergeCaps(splitline[0], splitline[1], splitline[2])
OccurNum = 0;
for (j = 0; j < t.length; j++) {
eval("myRE = /" + "[^a-zA-Z0-9_]" + t[j] + "/gi");
OccurArray = refineElement.match(myRE);
if (OccurArray != null) OccurNum = OccurNum + OccurArray.length;
}
if (OccurNum > 0) {
anyMatch[indexer] = (0-OccurNum) + "|" + profiles[i];
indexer++;
}
}
if (anyMatch.length == 0) { // If no matches are found, print a no match
noMatch(text); // HTML document
return;
}
else { formatResults(anyMatch, text); } // Otherwise, generate a results document
}
//Evoked if user searches ALL WORDS
function requireAll(t, text) {
var OccurNum = 0;
for (i = 0; i < profiles.length; i++) {
var allConfirmation = true;
var refineAllString = "";
var splitline = profiles[i].split("|");
refineAllString = mergeCaps(splitline[0], splitline[1], splitline[2])
OccurNum = 0;
for (j = 0; j < t.length; j++) {
eval("myRE = /" + "[^a-zA-Z0-9_]" + t[j] + "/gi");
OccurArray = refineAllString.match(myRE);
if (OccurArray != null) {
OccurNum = OccurNum + OccurArray.length;
} else {
allConfirmation = false;
}
}
if (allConfirmation) {
allMatch[indexer] = (0-OccurNum) + "|" + profiles[i];
indexer++;
}
}
if (allMatch.length == 0) {
noMatch(text);
return;
} else {
formatResults(allMatch, text);
}
}
//If user wants exact phrase
function requirePhrase(t, text) {
for (i = 0; i < profiles.length; i++) {
var allConfirmation = true;
//strip url out of search string
var refineAllString = "";
var splitline = profiles[i].split("|");
refineAllString = mergeCaps(splitline[0], splitline[1], splitline[2])
var allElement = t.toUpperCase();
var OccurNum = 0;
eval("myRE = /" + "[^a-zA-Z0-9_]" +t + "/gi");
OccurArray = refineAllString.match(myRE);
if (OccurArray != null) {
OccurNum = OccurNum + OccurArray.length;
phraseMatch[indexer] = (0-OccurNum) + "|" + profiles[i];
indexer++;
}
}
if (phraseMatch.length == 0) {
noMatch(text);
return;
}
else { formatResults(phraseMatch, text); }
}
function parseURL(u, text) { // Incite the search, looking only in the URL portion of the string
for (i = 0; i < profiles.length; i++) {
var urlConfirmation = true;
var anyURL = profiles[i].toUpperCase();
//strip url out of search string
var splitline = anyURL.split("|");
var refineAnyURL = splitline[splitline.length - 1];
var OccurNum = 0;
for (j = 0; j < u.length; j++) {
var urlPart = u[j].toUpperCase();
if (refineAnyURL.indexOf(urlPart) != -1 && (urlConfirmation)) {
urlConfirmation = false;
urlMatch[indexer] = (0-OccurNum) + "|" + profiles[i];
indexer++;
}
}
}
if (urlMatch.length == 0) {
noMatch(text);
return;
}
else {
urlTest = true;
formatResults(urlMatch, text, urlTest);
}
}
//*************************************************************
// Format no-results page
//*************************************************************
function noMatch(text) { // Dyanmic HTML page with no results
document.writeln("<a name="top_of_page"></a><h3>Search Results</h3>");
document.writeln("<h4><hr size="1"><b>'" + text + "' returned no results.<hr size="1"><h4>");
return true;
}
//*************************************************************
// Format successfull search results page
//*************************************************************
function formatResults(passedArray, text, urlTest) {
results = passedArray;
pgRange = (getQueryString("range") != "")? parseInt(getQueryString("range")):1;
//document.writeln("<hr size="1">Search Query: " + text + " ");
document.writeln("<font size="2">Search Results: "+ passedArray.length + " ");
document.writeln("Search Query: " + text);
document.writeln("<hr size="1">");
thisPg = 1;
endPg = passedArray.length;
if (passedArray.length > maxPages) {
thisPg = (maxPages * pgRange) - (maxPages - 1);
endPg = (parseInt(thisPg + (maxPages - 1)) < passedArray.length)? parseInt(thisPg + (maxPages - 1)):passedArray.length;
document.writeln(thisPg + " - " + endPg + " of " + passedArray.length);
}
document.writeln("<dl>");
passedArray.sort(compare);
wrdArray = (srcCrit != "phrase")? text.split(" "):new Array(text);
if (urlTest) {
for (i = 0; i < passedArray.length ; i++) {
divide = passedArray[i].split("|"); // Print each URL result as a unit of a definition list
document.writeln("<dt>" + "<a href=""+divide[4]+ "" target="_self">" + divide[4] + "</a></dt>");
document.writeln("<dd>" + divide[2] + "</dd><br><br>");
}
}
else {
for (i = (thisPg - 1); i < endPg; i++) {
divide = passedArray[i].split("|"); // Print each profile result as a unit of a definition list
for (j=0; j<wrdArray.length; j++) {
eval("myRE1 = /" + wrdArray[j] + "/gi");
regArr = null;
regArr = divide[2].match(myRE1);
if (regArr != null) {
//look for uniqueness in regArr
beenThere = new Array();
for (k=0; k<regArr.length; k++) {
beenhere = 0;
for (l=0; l<beenThere.length; l++) {
if (beenThere[l] == regArr[k]) {
beenhere = 1;
//break;
}
}
if (beenhere == 0) {
beenThere[beenThere.length] = regArr[k];
eval("myRE2 = /"+regArr[k]+"/g");
divide[2] = divide[2].replace(myRE2, "<|>" + regArr[k] + "</|>");
}
}
}
}
myRE3 = /<|>/g;
myRE4 = /</|>/g;
//divide[2] = divide[2].replace(myRE3, "<font color=red>");
//divide[2] = divide[2].replace(myRE4, "</font>");
divide[2] = divide[2].replace(myRE3, "");
divide[2] = divide[2].replace(myRE4, "");
//document.writeln("<dt><a href=javascript:overlink('"+divide[4]+"') target="main"><b>" + divide[1] + "</b></a><dt>");
//document.writeln("<dt><a href=""+divide[4]+"" onClick="setTimeout('findInPage();', 500)" target="main"><b>" + divide[1] + "</b></a><dt>");
//document.writeln("<dd>" + divide[2] + "</dd><br><br>");
document.writeln("<dt><a href=""+divide[4]+"" onClick="parent.frames[3].focus(); setTimeout('findInPage();', 250)" target="main"><b>" + divide[1] + "</b></a>");
document.writeln(" - " + divide[2] + "<dt><br>");
}
}
document.writeln("</dl>"); // Finish the HTML document
//write results page numbers
if (passedArray.length > maxPages) {
pgNum = parseInt(passedArray.length/maxPages);
if (passedArray.length/maxPages > pgNum) pgNum++;
pgLinks = "go to page: ";
for (i=0; i < pgNum; i ++) {
locationStr = (location.href.indexOf("&range=") > -1)? changeParam("range", parseInt(i + 1)):location.href + "&range=" + parseInt(i + 1);
pgLinks += (parseInt(i + 1) != pgRange)? "<a href="" + locationStr + "" target="_self">" + (i + 1) + "</a> ":"<b>" + (i + 1) + "</b> ";
}
document.writeln(pgLinks + "<hr size="1">");
}
clearOut();
}
function clearOut() { // Clear the arrays and variables generated from the current search
allMatch.length = 0; anyMatch.length = 0;
urlMatch.length = 0; divide.length = 0;
indexer = 0; all = false; urlTest = false;
}
extend.js 입니다.
/*
This script is by Infovets for added manual browsing functionality
*/
//global variables
var hitcount = 0;
var currenthit = 0;
var targetframe = 3;
var hitwordMG = "";
function showInPage()
{
//parent.frames[targetframe].document.write('Hey');
if (!document.all&&document.getElementById)
{
var bodyvar = parent.frames[targetframe].document.getElementsByTagName('body')[0];
var docvar = bodyvar.innerHTML;
if (srcCrit != "phrase")
{
for (i = 0; i < findwords.length; i++)
{
eval("myRE2 = /"+ "([^a-zA-Z])" +findwords[i]+"/gi");
//docvar = docvar.replace(myRE2, "n<font color='#bb0000'><b>" + findwords[i].toUpperCase() + "</b></font>");
docvar = docvar.replace(myRE2, "$1" + findwords[i].toUpperCase());
}
hitwordMG = findwords[0].toUpperCase();
}
else if (srcCrit == "phrase")
{
eval("myRE2 = /"+ "([^a-zA-Z])" +findwords+"/gi");
//docvar = docvar.replace(myRE2, "n<font color='#bb0000'><b>" + findwords.toUpperCase() + "</b></font>");
docvar = docvar.replace(myRE2, "$1" + findwords.toUpperCase());
hitwordMG = findwords.toUpperCase();
}
bodyvar.innerHTML = docvar;
setTimeout('nexthitMG();', 150);
}
else if(document.all)
{
hitcount = 0;
var temp = "";
var dist = 0;
var scroll = true;
var checkchr = 0;
var checklength = 0;
if (srcCrit != "phrase")
{
for (i = 0; i < findwords.length; i++)
{
var txt = parent.frames[targetframe].document.body.createTextRange();
var str = findwords[i];
var found = txt.findText(str);
while (found)
{
txt.moveStart("character", -1);
checkchr = txt.text.charCodeAt(0);
checklength = txt.text.length;
txt.findText(str);
temp= txt.text;
if(((checkchr < 65 || checkchr > 90) && (checkchr < 97 || checkchr > 122)) || (checklength == temp.length && temp.charCodeAt(0) == checkchr))
{
hitcount++;
txt.pasteHTML('<a name="hit'+hitcount+'"></a><span style="font-weight: bold; color: #bb0000;">'+temp+'</span>');
}
txt.moveStart("character", 1);
found = txt.findText(str);
}
}
}
else if (srcCrit == "phrase")
{
var txt = parent.frames[targetframe].document.body.createTextRange();
var str = findwords;
var found = txt.findText(str);
while (found)
{
txt.moveStart("character", -1);
checkchr = txt.text.charCodeAt(0);
checklength = txt.text.length;
txt.findText(str);
temp= txt.text;
if(((checkchr < 64 || checkchr > 91) && (checkchr < 96 || checkchr > 123)) || (checklength == temp.length && temp.charCodeAt(0) == checkchr))
{
hitcount++;
txt.pasteHTML('<a name="hit'+hitcount+'"></a><span style="font-weight: bold; color: #bb0000;">'+temp+'</span>');
}
txt.moveStart("character", 1);
found = txt.findText(str);
}
}
currenthit = 0;
nexthitIE();
}
}
function findInPage()
{
if (document.getElementById && !document.all)
parent.frames[targetframe].document.body.onload = setTimeout("showInPage()",100);
else if (parent.frames[targetframe].document.readyState == "complete" && document.all)
showInPage();
else if(document.getElementById && document.all)
setTimeout("findInPage()",100);
}
function nexthitIE()
{
if(hitcount!=0)
{
if(currenthit>=hitcount) currenthit=1;
else currenthit++;
parent.frames[targetframe].location.hash = "hit" + currenthit;
}
}
function prevhitIE()
{
if(hitcount!=0)
{
if(currenthit<=1) currenthit=hitcount;
else currenthit--;
parent.frames[targetframe].location.hash = "hit" + currenthit;
}
}
function nexthitMG()
{
if(hitwordMG)
{
parent.frames[targetframe].focus();
strFound=parent.frames[targetframe].find(hitwordMG, true, false, true, false, true, false);
if (!strFound)
{
changehitwordup();
strFound=parent.frames[targetframe].find(hitwordMG, true, false, true, false, true, false)
// while (parent.frames[targetframe].find("mare", false, false, true, false, true, false)) continue
}
}
}
function prevhitMG()
{
if(hitwordMG)
{
parent.frames[targetframe].focus();
strFound=parent.frames[targetframe].find(hitwordMG, true, true, true, false, true, false);
if (!strFound)
{
changehitworddown();
strFound=parent.frames[targetframe].find(hitwordMG, true, true, true, false, true, false)
// while (parent.frames[targetframe].find("foal", true, true, true, false, true, false)) continue
}
}
}
function changehitwordup()
{
if(srcCrit != "phrase")
{
if(currenthit>=findwords.length-1) currenthit=0;
else currenthit++;
hitwordMG = findwords[currenthit].toUpperCase();
}
}
function changehitworddown()
{
if(srcCrit != "phrase")
{
if(currenthit<=0) currenthit=findwords.length;
else currenthit--;
hitwordMG = findwords[currenthit].toUpperCase();
}}