1

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?

denys281
  • 2,004
  • 2
  • 19
  • 38
  • What exactly don't you understand? – Dziamid Apr 18 '11 at 14:48
  • @Dziamid I find this [link](http://ganeshhs.com/zend-framework/zend-search-lucene-part4-search-results-highlighting), I do not where I must do it, in my table class? probably better to use [this](http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html) ?Thank you! – denys281 Apr 19 '11 at 15:32

2 Answers2

2

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}}
Herman
  • 1,534
  • 10
  • 16
2

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())
denys281
  • 2,004
  • 2
  • 19
  • 38