地理空间索引“找不到场的映射”与YAML [英] Geospatial Indexing "No mapping found for field" with YAML

查看:148
本文介绍了地理空间索引“找不到场的映射”与YAML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用YAML格式使用Doctrine2的OD映射嵌入式文档进行地理空间索引,MongoDB:
我会尝试在Place文档中嵌入一个Coordinate文档,以便能够执行一些地理空间索引查询,但是有一个映射问题。

I have a problem trying to map an embedded document for geospatial indexing using Doctrine2's OD with YAML format, and MongoDB : I would try to embed a "Coordinate" Document in the "Place" document to be able to execute some geospatial indexed queries, but got a mapping problem.

正如官方文档所示:
http://docs.doctrine-project.org/projects/doctrine-mongodb -odm / en / latest / reference / indexes.html#geospatial-indexing

但是我使用YAML映射格式...
和得到这个问题:

But I work with YAML mapping format... And got this problem :

找不到映射映射/ Applications / MAMP / htdocs / intramuros-web / src / IntraMuros / CoreBundle / Resources / config / doctrine / Coordinates .mongodb.yml'在类'IntraMuros\CoreBundle\Document\Coordinates'。

"No mapping found for field '/Applications/MAMP/htdocs/intramuros-web/src/IntraMuros/CoreBundle/Resources/config/doctrine/Coordinates.mongodb.yml' in class 'IntraMuros\CoreBundle\Document\Coordinates'."

这是我的YAML文件:Place.mongodb.y ml,正确放置在我的Symfony2软件包的Res​​ources\config目录中。

Here's my YAML file : Place.mongodb.yml, correctly placed in Resources\config directory of my Symfony2's bundle.

IntraMuros\CoreBundle\Document\Place:
  type: document
  db: intramuros
  collection: places
  repositoryClass: IntraMuros\CoreBundle\Repository\PlaceRepository
  fields:
    id:
      type: id
      id:  true
    name:
      type: string
    address:
      type: string
    coordinates:
      embedded: true
      type: one
      targetDocument: IntraMuros\CoreBundle\Document\Coordinates
      cascade: all
      strategy: set
    indexes:
      coordinates:
        keys:
          coordinates: 2d

IntraMuros\CoreBundle\Document\Coordinates:
  type: EmbeddedDocument
  db: intramuros
  fields:
    latitude:
      type: float
    longitude:
      type: float

这是我将要使用的PHP Document类。

And Here's the PHP Document class I would to use.

<?php

namespace IntraMuros\CoreBundle\Document;


/**
 * @Document(requireIndexes=true)
 * @Indexes({
 *     @Index(keys={"coordinates"="2d"})
 * })
 */
class Place
{
    /**
     * @Id
     */
    protected $id;

    /**
     * @String
     */
    protected $name;

    /**
     * @String 
     */
    protected $address;

    /**
     * @EmbedOne(targetDocument="IntraMuros\CoreBundle\Document\Coordinates")
     */
    protected $coordinates;

    public function __construct($latitude = NULL, $longitude = NULL)
    {
        $coordinates = new Coordinates($latitude, $longitude);
        $this->setCoordinates($coordinates);
    }

    public function getId()
    {
        return $this->id;
    }

    public function setName($name)
    {
        $this->name = $name;
    }

    public function getName()
    {
        return $this->name;
    }

    public function setAddress($address)
    {
        $this->address = $address;
    }

    public function getAddress()
    {
        return $this->address;
    }

    public function setCoordinates($coordinates)
    {
        $this->coordinates = $coordinates;
    }

    public function getCoordinates($toArray = false)
    {
        if ($toArray) {
            if ($this->coordinates) {
                return $this->coordinates->toArray();
            }
        }
        return $this->coordinates;
    }

    public function toArray()
    {
        return array(
            'id' => $this->getId(),
            'name' => $this->getName(),
            'address' => $this->getAddress(),
            'coordinates' => $this->getCoordinates(true)
        );
    }
}


/**
 * @EmbeddedDocument
 */
class Coordinates
{
    /**
     * @Float
     */
    protected $latitude;

    /**
     * @Float
     */
    protected $longitude;

    public function __construct($latitude = NULL, $longitude = NULL)
    {
        $this->latitude = $latitude;
        $this->longitude = $longitude;
    }

    public function setLatitude($latitude)
    {
        $this->latitude = $latitude;
    }

    public function getLatitude()
    {
        return $this->latitude;
    }

    public function setLongitude($longitude)
    {
        $this->longitude = $longitude;
    }

    public function getLongitude()
    {
        return $this->longitude;
    }

    public function toArray()
    {
        return array(
            'latitude' => $this->getLatitude(),
            'longitude' => $this->getLongitude()
        );
    }
}

提前谢谢你,
Bobby。

Thank you a lot in advance, Bobby.

推荐答案

您应该使用注释而不是YML映射文档。

You should use annotations instead of YML for mapping your documents.

它会很容易工作。

祝你好运! ;)

这篇关于地理空间索引“找不到场的映射”与YAML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆