This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

sf lucene not showing results

Questions relating to sfLucenePlugin, sfSearch etc

sf lucene not showing results

by vishant » Fri Mar 12, 2010 5:07 pm

Hi everyone,

I configured the plugin manually but it's not returning any results.
My search terms are saved in the database.

These are the steps:

1. i inserted the zend search library in the vendor folder
2. i made the schema
3. i made a route
4. i created a search module (frontend)
5. i made a search form:
Code: Select all
<div class="component search" id="search_container_side">
    <form action="<?php echo url_for('search'); ?>"  method="post">
        <fieldset>
            <legend>
                Zoeken
            </legend>
            <input name="search[query]" type="text" />
            <button type="submit">
                <span>Zoek</span><!--[if IE]>&nbsp;&nbsp;&nbsp;&nbsp;<![endif]-->
            </button>
        </fieldset>
    </form>
</div>


6. this is my action:
Code: Select all
public function executeIndex(sfWebRequest $request)
  {
        $this->form = new AdvancedSearchForm();

        if ($request->getParameter('search'))
        {
            $this->form->bind($request->getParameter('search'));

            if($this->form->isValid())
            {
                $this->query = strtolower($this->form->getValue('query'));

                print($this->query).'<br />';

                SearchTermPeer::addOrUpdateTerm($this->query);

                $query = '';
                $query .= $this->query;

                $this->hits = LuceneHelper::getLuceneIndex()->find($query);
                #$this->jobs = LuceneHelper::getLuceneIndex()->find($this->query);

                var_dump($this->hits);

            }
        }
  }


7. i added : LuceneHelper class in the lib folder;

Code: Select all
<?php

class LuceneHelper
{
    /**
     * Return an array of Documents that match the given query
     */
    static public function search($query)
    {
        $hits = array();

        if ($query) {
            $hits  = self::getLuceneIndex()->find($query);
        }

        return $hits;
    }

    /*
     * Returns the Lucene Index
     */
    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);
        }
    }


    /*
     * Clears the index
     */
    static public function clearLuceneIndex()
    {
        if (file_exists($index = self::getLuceneIndexFile()))
        {
            sfToolkit::clearDirectory($index);
            rmdir($index);
        }
    }

    /*
     * Convenience method to generate the index path
     */
    static public function getLuceneIndexFile()
    {
        return sfConfig::get('sf_data_dir') . '/lucene.' . sfConfig::get('sf_environment') . '.index';
    }
}


8. I edited the NewsPeer:
Code: Select all
 static public function reIndexLucene($fresh = false)
    {

        if($fresh)
        {
            LuceneHelper::clearLuceneIndex();
        }

        $index = LuceneHelper::getLuceneIndex();

        $crit = new Criteria();
        $crit->add(NewsPeer::ACTIVE, 1);
        $abouts = NewsPeer::doSelectJoinAll($crit);


        foreach($abouts as $obj)
        {
            $doc = new Zend_Search_Lucene_Document();

            $doc->addField(Zend_Search_Lucene_Field::UnIndexed('pk', $obj->getId()));

            $doc->addField(Zend_Search_Lucene_Field::UnStored('title', $obj->getTitle(), 'utf-8'));
            $doc->addField(Zend_Search_Lucene_Field::UnStored('titleSlug', $obj->getTitleSlug(), 'utf-8'));
            //$doc->addField(Zend_Search_Lucene_Field::Text('catId', $obj->getCatId()));
            $doc->addField(Zend_Search_Lucene_Field::UnStored('intro', $obj->getIntro(), 'utf-8'));
            $doc->addField(Zend_Search_Lucene_Field::UnStored('body', $obj->getBody(), 'utf-8'));

           
            //$doc->addField(Zend_Search_Lucene_Field::unIndexed('route', 'about_detail', 'utf-8'));
            //$doc->addField(Zend_Search_Lucene_Field::UnStored('searchTags', $obj->getTags(), 'utf-8'));

            $index->addDocument($doc);
            $index->commit();

        }




        return $index;
    }



Can anyone help me?
I added content in my db.
My search doesn't show any results.

Thanx in advance everyone.
vishant
Junior Member
 
Posts: 14
Joined: Thu Jan 14, 2010 1:08 pm
Location: suriname

Re: sf lucene not showing results

by ricardojguzman » Wed Jun 30, 2010 2:15 am

Hello vishant.

I'm in the same situation as you are. The only difference is that I followed the jobeet way. Lucene is not returning anything.

I tried changing the partial file and still nothing :?~ :-?~ :???:

EDIT:
Seems like I did the same steps as you.
ricardojguzman
Member
 
Posts: 30
Joined: Tue Mar 09, 2010 3:05 pm

Re: sf lucene not showing results

by ricardojguzman » Wed Jun 30, 2010 2:51 pm

My old reply only appears when I press the reply button but not on the thread..

I had the same problem but solved it. Can you post your partial file? My problem was there. I found the solution via this post, had to translate it:
http://www.developpez.net/forums/d883623/php/bibliotheques-f rameworks/symfony/jointure-relation-1-n/
This is my _luceneList partial

Code: Select all
 <?php foreach ($personas as $personass): ?>
    <tr>
      <td><a href="<?php echo url_for('admins/edit?usuarioid='.$personass->getUsuarioid()) ?>"><?php echo $personass->getUsuarioid() ?></a></td>
      <td><?php echo $personass->getCedula() ?></td>
      <td><?php echo $personass->getNombres() ?></td>



Edit:
>_< nvm now I see it in the thread. Sorry for the double post!.
ricardojguzman
Member
 
Posts: 30
Joined: Tue Mar 09, 2010 3:05 pm