4

私はSymfony2でElasticSearchBundleをいじり始めましたが、エンティティを使った検索機能について質問があります。

このような構成がある場合:

foq_elastica:
clients:
    default: { host: localhost, port: 9200 }
indexes:
    website:
        client: default
        types:
            user:
                mappings:
                    username: { boost: 5 }
                    firstName: { boost: 3 }
                persistence:
                    driver: orm # orm, mongodb, propel are available
                    model: Application\UserBundle\Entity\User
                    provider:

次に、次のようにインデックスを検索できます。

$userType = $this->container->get('foq_elastica.index.website.user');

$resultSet = $userType->search('bob');

しかし、単一の関数で複数のエンティティを検索したい場合はどうでしょうか。何かのようなもの...

構成:

foq_elastica:
clients:
    default: { host: localhost, port: 9200 }
indexes:
    website:
        client: default
        types:
            user:
                mappings:
                    username: { boost: 5 }
                    firstName: { boost: 3 }
                persistence:
                    driver: orm
                    model: Application\UserBundle\Entity\User
                    provider:
            client:
                mappings:
                    clientname: { boost: 5 }
                persistence:
                    driver: orm 
                    model: Application\UserBundle\Entity\Client
                    provider:

検索機能:

$Type = $this->container->get(['foq_elastica.index.website.user', 'foq_elastica.index.website.client']);

$resultSet = $Type->search('bob');

上記のコードは機能しませんが、複数のエンティティで単一の検索を実行し、それらのブーストプロパティに基づいて結果を取得するような方法があるかどうか疑問に思いましたか?

4

2 に答える 2

4

OPからの回答

これが私の解決策です...私は設定ファイルを編集して、次のように私のWebサイトのルートにファインダーを配置しました:

foq_elastica:
clients:
    default: { host: localhost, port: 9200 }
indexes:
    website:
        client: default
        finder:
        types:
            user:
                mappings:
                    username: { boost: 5 }
                    firstName: { boost: 3 }
                persistence:
                    driver: orm
                    model: Application\UserBundle\Entity\User
                    provider:
            client:
                mappings:
                    clientname: { boost: 5 }
                persistence:
                    driver: orm 
                    model: Application\UserBundle\Entity\Client
                    provider:

そして、私は私の検索をこのように呼びます...

$finder = $this->container->get('foq_elastica.finder.website');

$results = $finder->find('bob');

これは私のユーザーとクライアントエンティティを検索します!

于 2012-10-12T15:52:46.297 に答える
1

私が見ているように、あなたがやりたいことをするための2つの方法があります。ユーザーとクライアントの親エンティティを作成し、それをタイプとしてインデックスに追加できます。Doctrineの継承マッピングを見てください; ただし、これらのエンティティをインデックスに永続化するときにFOQ_ElasticaBundleがこれらを処理するかどうか、およびどのように処理するかはわかりません。これは方向への単なるポインタであり、これがまったく機能するかどうかはわかりません!

次のアプローチをお勧めします。タイプではなくインデックスを検索します。を使用foq_elastica.index_managerして、必要なインデックス(Webサイト)を取得し、タイプフィルターを使用して結果をユーザーとクライアントタイプに制限するクエリを作成できます。

于 2012-10-02T07:52:47.477 に答える