floriansemm / SolrBundle

Solr-Integration into Symfony and Doctrine2
http://floriansemm.github.io/SolrBundle
MIT License
123 stars 73 forks source link

The results returns true all the time #114

Closed safwan74 closed 8 years ago

safwan74 commented 8 years ago

I have the following code:

public function searchPageAction(Request $request)
{

        $searchfor = $request->query->get('textbox');

   $query = $this->get('solr.client')->createQuery('PagesBundle:Article');

$query->addSearchTerm('title_s', $searchfor); $query->addField('title_s'); $query->addField('id'); $query->addField('content_s'); //$query->addSearchTerm('content_s', $searchfor);

$results = $query->getResult();

    return $this->render('PagesBundle:page:search-results.html.twig', array('message'=>$results,
        ));
}

The problem I have is that the query returns true all the time even if the string from the request is empty! It doesn't filter the results.

I can see that I can index the data in solr using the bundle, however the problem I have is that it returns all the results even if the string is empty "". What am I doing wrong.

By the way, I like the extension and thank you for the efforts, please excuse me as I am newbie to solr.

floriansemm commented 8 years ago

try this:

$query = $this->get('solr.client')->createQuery('PagesBundle:Article');
$query->setUseWildcard(false);
$query->addSearchTerm('title', $searchfor);
// rest of your code
safwan74 commented 8 years ago

Thank you very much.