Completed
Push — master ( 707688...6da863 )
by Mike
04:47 queued 02:08
created

Tests/ODM/CouchDB/Functional/LuceneQueryTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Doctrine\Tests\ODM\CouchDB\Functional;
4
5
use Doctrine\CouchDB\View\DesignDocument;
6
use Doctrine\Tests\ODM\CouchDB\CouchDBFunctionalTestCase;
7
8
class LuceneQueryTest extends CouchDBFunctionalTestCase
9
{
10
    /**
11
     * @var DocumentManager
12
     */
13
    private $dm;
14
15
    public function setUp()
16
    {
17
        $this->markTestSkipped('not working?');
18
19
        $this->dm = $this->createDocumentManager();
20
    }
21
22
    public function testLuceneIndexing()
23
    {
24
        $this->dm->getConfiguration()->addDesignDocument(
25
            'lucene_users', 'Doctrine\Tests\ODM\CouchDB\Functional\LuceneQueryDesignDoc', array()
26
        );
27
28
        $query    = $this->dm->createLuceneQuery('lucene_users', 'by_name');
29
        $response = $query->createDesignDocument();
30
31
        $user1 = new \Doctrine\Tests\Models\CMS\CmsUser();
32
        $user1->username = "beberlei";
33
        $user1->status = "active";
34
        $user1->name = "Benjamin";
35
36
        $user2 = new \Doctrine\Tests\Models\CMS\CmsUser();
37
        $user2->username = "lsmith";
38
        $user2->status = "active";
39
        $user2->name = "Lukas";
40
41
        $this->dm->persist($user1);
42
        $this->dm->persist($user2);
43
        $this->dm->flush();
44
45
        $query->setQuery("Lukas");
46
47
        try {
48
            $result = $query->execute();
49
        } catch(\Doctrine\CouchDB\HTTP\HTTPException $e) {
50
            if ($e->getCode() == 404) {
51
                $this->markTestSkipped("Lucene is not integrated");
52
            } else {
53
                throw $e;
54
            }
55
        }
56
57
        $this->assertEquals(1, count($result));
58
        foreach ($result AS $user) {
59
            $this->assertEquals($user2->id, $user['id']);
60
            $this->assertEquals(1, $user['score']);
61
        }
62
63
        $query->setIncludeDocs(true)->setDocumentName('Doctrine\Tests\Models\CMS\CmsUser');
64
        $result = $query->execute();
65
        $this->assertSame($user2, $result[0]['doc']);
66
    }
67
}
68
69
class LuceneQueryDesignDoc implements DesignDocument
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
70
{
71
    public function getData()
72
    {
73
        return array(
74
            "fulltext" => array(
75
                "by_name" => array(
76
                    "index" => "function(doc) {
77
                        var ret = new Document();
78
                        ret.add(doc.name);
79
                        ret.add(doc.type, {field: \"type\"});
80
                        return ret;
81
                    }"
82
                )
83
            ),
84
        );
85
    }
86
}
87