0

I'm using Elastica search engine for my Symfony project.

Now, I'm getting the below error :

The autoloader expected class "Elastica_Query_Bool" to be defined in file "/blablabla/vendor/ruflin/elastica/lib/Elastica/Query/Bool.php". The file was found but the class was not in it, the class name or namespace probably has a typo.

If I change new \Elastica_Query_Bool() for new \Elastica\Query\Bool() in my php file, it works fine.

But I can't understand why I'm getting an error now. Any idea ?

Mikolaj
  • 190
  • 1
  • 11

1 Answers1

1

Because when you new Elastica_Query_Bool it's looking for a class actually called Elastica_Query_Bool. And of course the actual class is called Bool.

try:

use Elastica\Query\Bool; // At the top of your file following the namespace line.
...
$bool = new Bool();

Might want to review namespaces in the php manual.

Cerad
  • 48,157
  • 8
  • 90
  • 92
  • Yeah sure, it's looking for this class and it does not exist but it worked before. More, all the examples I can find on Elastica suggest to use new Elastica_Query_Bool(). So maybe something change in Elastica bundle or in a newest version of Symfony ? – Mikolaj Aug 17 '13 at 23:29
  • 1
    Check the Bool.php file. Does it have a namespace deceleration? If it does then it means it has been upgraded from a pre=namespace version. You must be looking at old examples. – Cerad Aug 17 '13 at 23:29
  • This article might help: http://richardmiller.co.uk/2011/11/11/symfony2-integrating-elasticsearch/ – Cerad Aug 17 '13 at 23:32
  • 1
    I've just had a look to the history of the file `Bool.php` in `https://github.com/ruflin/Elastica/` repository, and this commit `https://github.com/ruflin/Elastica/commit/94b4b8ac854fafefaad5b51831094d34f9b4ebfd` introduced the use of namespace. So, no more "_" (like the other bundles) and I have my answer :) By the way, your answer is correct (even if it does not really fit to my question). – Mikolaj Aug 18 '13 at 00:55