IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Symfony PHP Discussion :

Librairie Lucene !Moteur de recherche


Sujet :

Symfony PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé

    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    788
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 788
    Par défaut Librairie Lucene !Moteur de recherche
    Bonjour j'ai suivi le tutoriel de Jobeet pour installer un moteur de recherche sur mon site!!
    Le seul problème c'est que je n'ai pas d'erreur mais le moteur de recherche ne me retourne jamais aucun résultat... :'(
    Donc voici le code lié au moteur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    //GeekGeekerie.class.php
    public function save(Doctrine_Connection $conn = null)
    	{
    	  // ...
     
    	  $conn = $conn ? $conn : $this->getTable()->getConnection();
    	  $conn->beginTransaction();
    	  try
    	  {
    	    $ret = parent::save($conn);
     
    	    $this->updateLuceneIndex();
     
    	    $conn->commit();
     
    	    return $ret;
    	  }
    	  catch (Exception $e)
    	  {
    	    $conn->rollBack();
    	    throw $e;
    	  }
    	}
     
    	public function delete(Doctrine_Connection $conn = null)
    	{
    	  $index = $this->getTable()->getLuceneIndex();
     
    	  if ($hit = $index->find('pk:'.$this->getId()))
    	  {
    	    $index->delete($hit->id);
    	  }
     
    	  return parent::delete($conn);
    	}
     
    	public function updateLuceneIndex()
    	{
    	  $index = $this->getTable()->getLuceneIndex();
     
    	  // remove an existing entry
    	  if ($hit = $index->find('pk:'.$this->getId()))
    	  {
    	    $index->delete($hit->id);
    	  }
     
    	  // don't index non active geekerie
    	  if (!$this->isActive($this))
    	  {
    	    return;
    	  }
     
    	  $doc = new Zend_Search_Lucene_Document();
     
    	  // store job primary key URL to identify it in the search results
    	  $doc->addField(Zend_Search_Lucene_Field::UnIndexed('pk', $this->getId()));
     
    	  // index job fields
    	  $doc->addField(Zend_Search_Lucene_Field::UnStored('content', $this->getContent(), 'utf-8'));
    	  $doc->addField(Zend_Search_Lucene_Field::UnStored('author', $this->getAuthor(), 'utf-8'));
     
    	  // add job to the index
    	  $index->addDocument($doc);
    	  $index->commit();
    	}  
     
     
    //GeekGeekerieTable.class.php
    static public function getLuceneIndex()
    	{
    	  ProjectConfiguration::registerZend();
     
    	  if (file_exists($index = self::getLuceneIndexFile()))
    	  {
    	    return Zend_Search_Lucene::open($index);
    	  }
    	  else
    	  {
    	    return Zend_Search_Lucene::create($index);
    	  }
    	}
     
    	static public function getLuceneIndexFile()
    	{
    	  return sfConfig::get('sf_data_dir').'/geekerie.'.sfConfig::get('sf_environment').'.index';
    	}
     
     
     
    	public function getForLuceneQuery($query)
    	{
    	  $hits = $this->getLuceneIndex()->find($query);
     
    	  $pks = array();
    	  foreach ($hits as $hit)
    	  {
    	    $pks[] = $hit->pk;
    	  }
     
    	  if (empty($pks))
    	  {
    	    return 'no results';
    	  }
     
    	  $q = $this->createQuery('g')
    	    ->whereIn('g.id', $pks)
    	    ->limit(20);
     
    	  return $q->execute();
    	}
    //L'action
     
    public function executeSearch(sfWebRequest $request)
      {
        if (!$query = $request->getParameter('query'))
        {
          return $this->forward('geekerie', 'index');
        }
     
        $this->geek_geekerie_list = Doctrine::getTable('GeekGeekerie')->getForLuceneQuery($query);
        echo $this->geek_geekerie_list;
      }
    //Le tpl
     
    <?php foreach ($geek_geekerie_list as $geek_geekerie): ?>
    	<?php include_partial('geekerie', array('geek_geekerie' => $geek_geekerie,'aVote' => $aVote)); ?>
    <?php endforeach; ?>

    Voilà bon c'est un code très long mais si il y a un spécialiste qui passe dans le coin je veux bien un coup de main .
    Merci

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    47
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 47
    Par défaut
    ton soucis ressemble fortement au mien
    http://www.developpez.net/forums/d68...search_lucene/

    si tu trouves une solution tiens moi au courant ...

    perso je pense que je vais pas tarder à virer la biblio zend et installé directement le plugin sfLucene

Discussions similaires

  1. [1.x] Moteur de recherche Zend Lucene
    Par fallais dans le forum Symfony
    Réponses: 0
    Dernier message: 15/09/2010, 16h15
  2. Moteur de recherche lucene.net ou bien Swish-e
    Par zalalus dans le forum C#
    Réponses: 1
    Dernier message: 09/02/2010, 10h05
  3. Lucene moteur de recherche par index
    Par plombier00 dans le forum Développement Web en Java
    Réponses: 1
    Dernier message: 09/02/2010, 09h56
  4. Moteur de recherche " Lucene "
    Par tarikx dans le forum Servlets/JSP
    Réponses: 2
    Dernier message: 19/03/2009, 11h40
  5. Moteur de recherche .. lucene ?
    Par laurentibus dans le forum API standards et tierces
    Réponses: 6
    Dernier message: 23/04/2008, 11h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo