我正在尝试创建一个搜索框,搜索整个coldfusion网站并显示搜索结果。到目前为止,我已经发布了我的HTML和JS代码。我不太了解搜索或冷血,所以任何帮助都会非常感激。
<script type="text/javascript">
function submitSearch() {
var q = document.getElementById('q');
if (q.value.length == 0) {
alert('Please enter a search word');
}
else {
var frmSearch = document.getElementById('frmSearch');
}
}
</script>
<div id="header-search">
<form action="" method="post" id="frmSearch">
<input type="text" name="q" id="q" value="Search">
<input src="images/mag.png" id="searchsubmit" value="Search" class="btn" type="Button" onClick="submitSearch()" />
</form>
</div>
答案 0 :(得分:3)
由mbseid发布,请查看cfindex
和cfsearch
。您不能使用JS来搜索驻留在服务器上的文件。唯一的方法是使用cfsearch
。在此处阅读更多相关信息:cfsearch
希望这有帮助。
答案 1 :(得分:0)
您想要用什么作为搜索的基础?如果它只是在几个页面上使用的数据库内容,那么你可能会很幸运地看到Solr集合。
如果它是完整的网站,您也可以集成自定义Google搜索。如果网站内容是公开的,他们可能会将整个内容编入索引。无需重新发明轮子。
答案 2 :(得分:-2)
如果内容位于实际的ColdFusion页面中,您最简单的方法是使用自定义Google搜索。如果那不是一个选项,那么你会想做这样的事情(伪代码):
cfdirectory to get list of *.cfm files
cffile to read in each cfm file
if (content of file) contains (what you're looking for, e.g. #form.search#), store filename in an array or a structure.
continue doing this through all files.
然后编写一个例程来输出片段,或者包含内容的文件列表。
它不优雅,但是它可以完成这项工作。