【问题标题】:Error: text index required for $text query错误:$text 查询需要文本索引
【发布时间】:2020-09-07 23:54:51
【问题描述】:

我想知道如何通过 XML 在我的 ODM 配置中添加文本类型索引来解决这个问题并按名称搜索。

感谢一切。

问候。

PD:对不起我的英语。

<document name="App\Document\Doc" db="db" collection="collection"
          repository-class="App\Repository\DocRepository">
    <id field-name="id" strategy="INCREMENT" type="int"/>
    <field field-name="code" name="code" type="string"/>
    <field field-name="name" name="name" type="string"/>
    <field field-name="type" name="type" type="string"/>

    <indexes>
        ???
    </indexes>
</document>

【问题讨论】:

    标签: mongodb indexing text document odm


    【解决方案1】:

    在深入研究了一些代码后,我发现这是可行的:

    <document name="App\Document\Doc" db="db" collection="collection"
              repository-class="App\Repository\DocRepository">
        <id field-name="id" strategy="INCREMENT" type="int"/>
        <field field-name="code" name="code" type="string"/>
        <field field-name="name" name="name" type="string"/>
        <field field-name="type" name="type" type="string"/>
    
        <indexes>
            <index name="fts">
                <key name="code" order="text" />
                <key name="name" order="text" />
                <key name="type" order="text" />
            </index>
        </indexes>
    </document>
    

    然而,order 这个关键字似乎违反直觉。

    【讨论】:

      猜你喜欢
      • 2020-05-12
      • 2019-08-16
      • 1970-01-01
      • 1970-01-01
      • 2021-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-02
      相关资源
      最近更新 更多