floriansemm / SolrBundle

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

All fields are returned #116

Closed wassafr closed 7 years ago

wassafr commented 8 years ago

I've followed the example of the README to have only one field to be mapped :

$search = $request->get('search_query');

$query = $this->get('solr.client')->createQuery('WassaIndoorWayfindingAdminBundle:Poi'); $query->addSearchTerm('name', $search); $query->setHydrationMode(HydrationModes::HYDRATE_INDEX); $query->addField('id'); $pois = $query->getResult();

foreach ($pois as $poi) { echo $poi->getMapId(); // Display the real value whilst the doc says it should be empty }

floriansemm commented 8 years ago

this was an bug in solr. should be fixed.

wassafr commented 8 years ago

I think your fix broke something. With the exact same code I don't get any result anymore, $pois is always empty.

floriansemm commented 8 years ago

What is the result when you run the query without addField?

wassafr commented 8 years ago

Same result, it doesn’t return anything.

floriansemm commented 8 years ago

Please add $query->setUseWildcard(false); and run the query again.

For extra debugging information start tail -f app/logs/dev.log | grep solr. You can see something like solr.INFO: run request: select?omitHeader=true&wt=json&json.nl=flat&q=title_s:"relation 1"&start=0&rows=10&fl=id [] [] (in your case something like name_s:"foo" instead of title_s)

Run the query in your solr-admin to make sure that your index contains data.

wassafr commented 8 years ago

Working with $query->setUseWildcard(false);.

By looking at the log, I can only see one difference when using wildcard between the bundle and running the query directly in Solr admin : the bundle generate title_s:"*relation 1*" while the Solr admin generate title_s:*relation 1* (no double quotes).

The latter works while the first doesn't.

floriansemm commented 8 years ago

Which version do you use? The double quotes issue was fixed in https://github.com/floriansemm/SolrBundle/commit/439ed223861f1dadcc6396b1d433ad21d4462484 which is part of the last release.

wassafr commented 8 years ago

I use the latest version 1.3.2. In the commit you talk about, you added the double quotes. That's precisely my problem because if I remove them from your code, it's working perfectly.

Finally, not using wildcard is not an option for me because I need have results that only match substrings of the fields.

floriansemm commented 8 years ago

@wassafr Is the problem still existent?