Symfony and Zend Lucene highlighting

1.1k Views Asked by At

I use symfony 1.4 and I use Zend Lucene search like in Jobbet And I need to make Search Results Highlighting, I read this , but I do not understend how it make in my case with symfony(

$ highlightedHTML = $ query-> highlightMatches ($sourceHTML);

What is $sourceHTML? And is it all makes by only one row?

upd:

 $ highlightedHTML = $ query-> highlightMatches ($sourceHTML);

It works in my model, but how it implement in my view?

2

There are 2 best solutions below

1
On BEST ANSWER

I do not now , if it is right , but it is work :) Just in view:

$query = Zend_Search_Lucene_Search_QueryParser::parse($queryStr);
$highlightedHTML = $query->highlightMatches($sourceHTML);

In my case for example:

echo $query->highlightMatches($ad->getCompany())
0
On

You need to store this highlighted HTML in your model. Or make a function that is accessible from the view. For example:

<?php
class Model {
  private $content;

  public function getContent(){
    return $this->content;
  }

  public function getContentHighlighted(){
    // Search term, usually in $_GET or $_POST
    $term = $_GET['searchterm'];
    // Parse query
    $query = Zend_Search_Lucene_Search_QueryParser::parse($term);
    // Return highlighted
    return $query->highlightMatches($this->getContent());
  }

}
?>

In your view (like in this case: Twig) you use:

<h1>The content</h1>
{{model.getContentHighlighted}}