Hi,
I am using Zend_Search_Lucene (from 0.93) in my php app (running php
5.2.1) and trying to display the results from multiple documents in my
index:
View Code:
Code:
<?php if(!empty($results)){
//pr($results);
echo '<h1>Search results: found '.count($results). ' document(s):</h1>';
foreach($results as $result){
echo 'Score: '.$result->score.'<br />';
$result = $result->getDocument();
if ($result->getFieldValue('news_title')){
echo 'News Title: '.$result->getFieldValue('news_title').'<br />';
}
else { echo "There are no news items matching your query";}
}
} else {
echo '<h1>There are no results to display</h2>';
}
?>
This works if the results object contains a field called 'news_title'
but if it doesn't, i get:
Code:
Fatal error: Uncaught exception 'Zend_Search_Lucene_Exception' with
message 'Field name "news_title" not found in document.' in
/var/www/vhosts/insidecruise.co.uk/subdomains/dev/httpdocs/app/vendors/Zend/Search/Lucene/Document.php:94
Stack trace: #0
/var/www/vhosts/insidecruise.co.uk/subdomains/dev/httpdocs/app/vendors/Zend/Search/Lucene/Document.php(109):
Zend_Search_Lucene_Document->getField('news_title') #1
/var/www/vhosts/insidecruise.co.uk/subdomains/dev/httpdocs/app/views/search/index.thtml(11):
Zend_Search_Lucene_Document->getFieldValue('news_title') #2
/var/www/vhosts/insidecruise.co.uk/subdomains/dev/httpdocs/cake/libs/view/view.php(554):
include('/var/www/vhosts...') #3
/var/www/vhosts/insidecruise.co.uk/subdomains/dev/httpdocs/cake/libs/view/view.php(293):
View->_render('/var/www/vhosts...', Array) #4
/var/www/vhosts/insidecruise.co.uk/subdomains/dev/httpdocs/cake/libs/controller/controller.php(544):
View->render(NULL, NULL, NULL) #5
/var/www/vhosts/insidecruise.co.uk/subdomains/dev/httpdocs/cake/dispatcher.php
in
/var/www/vhosts/insidecruise.co.uk/subdomains/dev/httpdocs/app/vendors/Zend/Search/Lucene/Document.php
on line 94
My question is therefore - how can I check for the existence of a field
in the results? My index contains fields for news, brochures, videos,
galleries etc. so i want a dynamic search page which only tries to
display matching news articles if there are any!
many thanks for any replies.
luke.