Zend Lucene Range Query

25 views
Skip to first unread message

Bruno Silveira

unread,
May 20, 2013, 2:23:21 PM5/20/13
to diem-...@googlegroups.com
Hi,
I have a problem with the range query, I'm trying use the created_at field to filter the search and building the index with this code:

public function populate()
  {
    $boostValues = $this->getBoostValues();

    // store the page id without indexing it
    $this->store('page_id', $this->page->get('id'));

    // Se a página de tiver um registro de sistema
    if($this->page->hasRecord()){
      //var_dump($this->page->toArray());
      $record_data = $this->page->getRecord();
      if($record_data){
          $record_data = $record_data->toArray();
          // Se essa contiver um timestamp de criação adiciona para o indice
          if(isset($record_data["created_at"])){
              $p = explode(" ", $record_data["created_at"]);
              $p = str_replace("-","",$p[0]);
              $this->index('created_at', $p[0], $boostValues['created_at']);
          }
      }

    // index the page slug
    $this->index('slug', dmString::unSlugify($this->page->get('slug')), $boostValues['slug']);

    // index the page name
    $this->index('name', $this->page->get('name'), $boostValues['name']);

...

and the search:

protected function getLuceneQuery($query)
  {
    $words = str_word_count($query, 1);

    $query = new Zend_Search_Lucene_Search_Query_Boolean();
   
    foreach($words as $word)
    {
      //--- search the term
      $term = new Zend_Search_Lucene_Index_Term($word);
      $subQuery = new Zend_Search_Lucene_Search_Query_Fuzzy($term, 0.4);
      $query->addSubquery($subQuery, true);
      //--- filter by date
      $from = new Zend_Search_Lucene_Index_Term('0020100101', 'created_at');
      $to   = new Zend_Search_Lucene_Index_Term('0020140101', 'created_at');
      $date_query = new Zend_Search_Lucene_Search_Query_Range($from, $to, false);  // true=>inclusive
      $query->addSubquery($date_query, true); /* true=> required */
    }

    return $query;
 
  }

but returned no result and no error.
The code is exactly the documentation ... I do not know what to do.

Bruno Silveira

unread,
May 20, 2013, 3:29:47 PM5/20/13
to diem-...@googlegroups.com
RESOLVED, THE PROBLEM IS:

NOT USE $this->index('created_at', $p[0], $boostValues['created_at']); TO WORK WITH NUMBER, USE $this->addField(Zend_Search_Lucene_Field::keyword("created_at", "0000000000", "UTF-8"));
Reply all
Reply to author
Forward
0 new messages