我对Zend_Search_Lucene
以及如何构建和搜索添加到标记中的文档有了相当新的了解,但我想知道如果根本没有提供搜索项,是否可以返回文档。
我知道这听起来很奇怪,可能违背了lucene搜索的目的,但我遇到过这样一种情况,如果用户只点击"搜索"而不输入任何搜索词,则首选将前20个文档返回给用户,而不是什么都不返回。
因此,我的问题就在这里:当没有提供搜索词时,我可以提供什么搜索词Zend_Search_Lucene
来返回它遇到的前20个文档,而不是什么都看不到。
我已经做得很好了:
<?php
Zend_Search_Lucene::setResultSetLimit(20);
$index = Zend_Search_Lucene::open("some/path/to/index");
$search_term = trim($_POST["search_term"]);
if ($search_term == "")
{
// adjust the search term to return any documents...
// will obviously be limited to the first 20...
}
$hits = $index->find($search_term);
// display the results...
// ...
?>
非常感谢您抽出时间,以及任何帮助/建议!
当没有提供搜索项时,通过id 1到20的搜索范围来搜索20条记录(但您的文档必须有一个id字段)
$from = new Zend_Search_Lucene_Index_Term(1, 'id');
$to = new Zend_Search_Lucene_Index_Term(20, 'id');
$query = new Zend_Search_Lucene_Search_Query_Range(
$from, $to, true // inclusive
);
$hits = $index->find($query);