Drupal-drupal7 搜索结果截字问题
drupal7默认的搜索功能,搜索出来的结果内容有些仅出现“...”,没有其它文字,中英文内容都一样。我已经查过代码,内容的输出在search.module里,用$snippet来输出。该怎么解决呢?
以下是问题的例子:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
drupal7默认的搜索功能,搜索出来的结果内容有些仅出现“...”,没有其它文字,中英文内容都一样。我已经查过代码,内容的输出在search.module里,用$snippet来输出。该怎么解决呢?
以下是问题的例子:
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
我曾以做过自定义的搜索,我把代友贴一下。大概的需求是这样的,用户根据邮编,地址,距离,关键词搜索。
elseif(isset($_GET['submit'])):
foreach($_GET as $key=>$value){
$$key=$value;
};
$querycevents = new EntityFieldQuery();
$querycevents->entityCondition("entity_type", "node");
$querycevents->entityCondition('bundle', 'events');
$querycevents ->propertyCondition("type", "events");
$querycevents->propertyCondition("status", 1);
if($_GET['eventdate'] && $eventdate !='Event Date'){
$eventdate = date("Y-m-d H:i:s", strtotime($eventdate)) ;
$querycevents->fieldCondition('field_events_date','value',$eventdate,'=');
}
if($_GET['keywords'] && $keywords !='Keywords'){
$querycevents->propertyCondition('title', $keywords,'CONTAINS');
}
if($_GET['city'] && $city!='City'){
$querycevents->fieldCondition('field_events_address', 'locality', $city,'=');
}
if($_GET['state'] && $state!='State'){
$querycevents ->fieldCondition('field_events_address', 'administrative_area', $state,'=');
}
if($_GET['radius'] && $radius!='Radius'){
/* if($zipcode=='Zip'){
$zipcode = '94108';
} */
// $zipcode = (int)$zipcode;
$point = db_query("SELECT latitude,longitude FROM {zipcodes} WHERE zipcode = $zipcode")->fetchAll();
$latitude = $point['0']->latitude;
$longitude = $point['0']->longitude;
// echo "SELECT *, (((acos(sin((".$latitude."*pi()/180))*sin(('latitude'*pi()/180))+cos((".$latitude."*pi()/180))*cos((`latitude`*pi()/180)) * cos(((".$longitude."- `longitude`)*pi()/180))))*180/pi())*60*1.1515) FROM `zipcodes` WHERE (((acos(sin((".$latitude."*pi()/180))*sin(('latitude'*pi()/180))+cos((".$latitude."*pi()/180))*cos((`latitude`*pi()/180)) * cos(((".$longitude."- `longitude`)*pi()/180))))*180/pi())*60*1.1515) >= ".$radius;
$dist ="3956 * 2 * ASIN(";
$dist .=" SQRT( POWER(SIN(({$latitude} - latitude) *";
$dist .=" pi()/180 / 2), 2) + ";
$dist .=" COS({$latitude} * pi()/180) * COS(latitude * pi()/180) * ";
$dist .=" POWER(SIN(({$longitude} -longitude) * pi()/180 / 2), 2) ))";
$sql =" SELECT *, $dist as distance from zipcodes where $dist <= ".$radius . " ORDER BY $dist";
$qrys = db_query($sql)->fetchAll();
$zipcodes = array();
foreach($qrys as $qry){
$zipcodes[] = $qry->zipcode;
}
$querycevents ->fieldCondition('field_events_address', 'postal_code', $zipcodes,'IN');
}elseif($radius=='Radius'){
if($zipcode!='Zip'){
$querycevents ->fieldCondition('field_events_address', 'postal_code', $zipcode,'=');
}
}
if($_GET['event_type'] && $event_type!='EventType'){
$querycevents ->fieldCondition('field_christian_event_type', 'tid', $event_type,'=');
}
$querycevents->propertyOrderBy("created", 'desc');
$querycevents->pager(10);
$result = $querycevents->execute();
$churchnumber = $querycevents->count()->execute();
pager_default_initialize(100, 10, $element = 1);
$output = theme('pager', array('quantity' =>10));
// var_dump($output);
// var_dump($result);
得到这些搜索关键词后:
if (isset($result['node'])) {
$news_items_nids = array_keys($result['node']);
$news_items = entity_load('node', $news_items_nids);
foreach($news_items as $news_item): // echo '<pre>';var_dump($news_item);echo '</pre>';
$nodeurl = url('node/'. $news_item->nid);
$field_event_thumbnail = $news_item->field_events_picture;
$field_address = $news_item->field_events_address;
$event_phone = $news_item->field_events_contact_phone;
$event_website = $news_item->field_event_website;
$event_detail= $news_item->body;
$autho = $news_item->name;
$statistics = statistics_get($news_item->nid);
$eventtime= $news_item->field_events_date;
... ... ....
endforeach;
endif;
http://webwash.net/tutorials/intro-search-api-part-1-how-create-search-pages
http://webwash.net/tutorials/how-create-search-pages-using-views-drupal-7
找到以上两个页面,介绍怎么定制search result page。不过我目前用修改search template的方法解决。
// search-result.tpl.php
$featured_img = "";
//field_landing_image field_featured_image
if(!empty($result['node']->field_featured_image[LANGUAGE_NONE][0]['uri'])) {
if(!(isset($result['node']->field_featured_image[LANGUAGE_NONE][0]['is_default']) && $result['node']->field_featured_image[LANGUAGE_NONE][0]['is_default'])) {
$featured_img = '<div class="featured-img">'.theme('image_style', array('style_name' => 'news-listing', 'path' => $result['node']->field_featured_image[LANGUAGE_NONE][0]['uri'])) . "</div>";
}
}
?>
<li class="<?php print $classes; ?>"<?php print $attributes; ?>>
<?php print render($title_prefix); ?>
<h3 class="title"<?php print $title_attributes; ?>>
<a href="<?php print $url; ?>"><?php print $title; ?></a>
</h3>
<?php print render($title_suffix); ?>
<div class="search-snippet-info">
<?php if (drupal_strlen($snippet) > 50): ?>
<p class="search-snippet"<?php print $content_attributes; ?>><?php echo $featured_img;?><?php print $snippet; ?></p>
<?php else:?>
<p class="search-snippet"<?php print $content_attributes; ?>>
<?php echo $featured_img;?>
<?php if($module == 'node'):?>
<?php
if(preg_match("/(\d+)$/i", $url, $matches)) {
$node_id = $matches[1];
$node = node_load($node_id);
$body = $node->body[LANGUAGE_NONE][0]['value'];
print drupal_substr(strip_tags($body), 0, 200).'...';
}
?>
<?php endif;?>
</p>
<?php endif; ?>
</div>
</li>