sulu/search-bundle

此包已被弃用且不再维护。作者建议使用 sulu/sulu 包。

Sulu 搜索包

0.4.0 2014-10-29 17:29 UTC

This package is not auto-updated.

Last update: 2016-03-10 09:13:12 UTC


README

Scrutinizer Code Quality

此包是 Sulu 内容管理框架 Sulu Content Management Framework 的一部分,并使用 MIT 许可证

SuluSearchBundle 扩展了 MassiveSearchBundle,为 Sulu 结构类提供元数据驱动程序。这使得 Sulu 内容可以被索引。

使用方法

此包将 MassiveSearchBundle 集成到 Sulu 中。有关一般使用信息,请参阅该包的文档。

映射结构文档

您可以在结构模板中将搜索索引映射到结构文档上

<?xml version="1.0" ?>

<template xmlns="http://schemas.sulu.io/template/template"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/template-1.0.xsd">

    <!-- ... -->

    <properties>
        <property name="title" type="text_line" mandatory="true">
            <!-- ... -->

            <tag name="sulu.search.field" index="true" type="string" role="title" />

            <!-- ... -->
        </property>
    </properties>
</template>

属性中的 tag 是搜索索引器的提示。它将以 "字符串" 类型索引字段,并使用此字段作为搜索结果的 "标题"。

角色

当您标记结构属性时,您可以可选地分配角色。角色告诉搜索引擎哪些字段应通过各种标准获取器在文档中可用

  • title: 搜索结果的标题: $document->getTitle()
  • description: 搜索结果的描述/摘录: $document->getDescription()
  • image: 指示一个用于确定图像 URL 的字段: $document->getImageUrl()

注意:如果您正在使用 SuluMediaBundle,您可以指定媒体字段作为图像字段。

索引结构文档

您可以使用 MassiveSearchBundle 将结构文档索引为任何其他对象

// we get a structure from somewhere..
$yourStructure = $magicalStructureService->getStructure();

$searchManager = $container->get('massive_search.search_manager');
$searchManager->index($yourStructure);

搜索

同样,搜索与 massive search bundle 完全相同

// we get a structure from somewhere..
$searchManager = $container->get('massive_search.search_manager');
$searchManager->createSearch('This is a search string')->locale('de')->index('content')->execute();

从命令行搜索

请参阅 MassiveSearchBundle 文档。

渲染结果

您可以遍历搜索结果并检索相关的搜索文档。URL 将是结构 URL(自动确定)。

{% for hit in hits %}
    <section>
        <h3><a href="{{ hit.document.url }}">{{ hit.document.title }}</a></h3>
        <p><i>Class: {{ hit.document.class }}</i></p>
        <p>{{ hit.document.description }}</p>
        <p><img src="{{ hit.document.imageUrl }}" /></p>
    </section>
{% endfor %}

要求