我目前正在使用tesseract讀取掃描文檔並將內容存儲爲文本文件的個人項目。我將文本文件和jpeg文件保存在我的web目錄中,並使用mySQL數據庫保持它們之間的鏈接。該項目的目標是能夠搜索關鍵術語並能夠返回圖像。Zend lucene - 在文本文件中搜索
我到目前爲止能夠使用Zend Lucene索引文本文件,但是在處理搜索文檔時遇到了很多問題,索引中的字段爲: 上傳圖像的日期,主體(文本文件的內容)以及圖像的URI。
//Create document
$doc = new Zend_Search_Lucene_Document();
//Select database and get item to be indexed
mysql_select_db("database", $con);
$exampleSQL = "SELECT date_format(dateUploaded, '%Y%m%d') as formatted_date, imageLink, textLink
FROM `mappingTable`
WHERE imageLink='$item'";
$fileItem = mysql_fetch_assoc(mysql_query($exampleSQL));
//Add fields to document
$doc->addField(Zend_Search_Lucene_Field::UnIndexed('URL',
$fileItem['imageLink']));
$doc->addField(Zend_Search_Lucene_Field::Keyword('created',
$fileItem['formatted_date']));
$contents = file_get_contents("/path/to/data/".$fileItem['textLink']);
$doc->addField(Zend_Search_Lucene_Field::UnStored('body',
$contents));
以上所有我相信工作得很好。 對於我的搜索,我打算按照文本文件中的內容搜索,並按照日期將圖像上傳到目錄,所以我設計了以下查詢,這些查詢對於某些重播根據需要未能生成,特別是在按日期搜索時或按內容和日期。
if($queryType === "contentSearch"){
$term = new Zend_Search_Lucene_Index_Term($query, 'body');
$searchQuery = new Zend_Search_Lucene_Search_Query_Term($term);
try{
$hits = $index->find($searchQuery);
}
catch (Zend_Search_Lucene_Exception $ex) {
$hits = array();
}
} elseif ($queryType === "dateSearch"){
$searchQuery = '['.str_replace('/','',$fQuerydate)." TO ".str_replace('/','',$tQuerydate).']';
try{
$hits = $index->find($searchQuery);
}
catch (Zend_Search_Lucene_Exception $ex) {
$hits = array();
}
} elseif ($queryType === "bothSearch"){
$searchQuery = new Zend_Search_Lucene_Search_Query_MultiTerm();
$searchQuery->addTerm(new Zend_Search_Lucene_Index_Term($query, 'body'), true);
$searchQuery->addTerm(new Zend_Search_Lucene_Index_Term('['.str_replace('/','',$fQuerydate).' TO '.str_replace('/','',$tQuerydate).']', 'created'), true);
// $searchQuery = 'body:"'.$query.'" && created:'.$fQuerydate." TO ".$tQuerydate;
try{
$hits = $index->find($searchQuery);
} catch (Zend_Search_Lucene_Exception $ex) {
$hits = array();
}
} else {
$searchQuery = null;
}
正如你可以看到我甚至還用解析器嘗試,但儘管我與至少兩個文件應當歸還的知識進行我的搜索上面會不返回任何結果。
e.g:+體:山+創建:[20110328 TO 20110628]
返回零文件。如你所見,我擺脫了所有的'/','。'。和' - '在我的日期(創建)字段中,我使用關鍵字聲明來確保它符合搜索條件,但即使如此也不會返回任何內容。
我也想知道如何應用我自己的停止列表來使用,因爲有一些術語我希望被包含在當前不存在的搜索中,並且對文檔很重要。
因爲我沒有在我自己的服務器上工作,並且訪問權限有限,所以我沒有選擇,只能使用lucene或mySQL,在數據庫中使用全文搜索會更好嗎?
在此先感謝。