sulu/search-bundle

This package is abandoned and no longer maintained. The author suggests using the sulu/sulu package instead.

Sulu Search Bundle

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

This bundle is part of the Sulu Content Management Framework and licensed under the MIT License.

The SuluSearchBundle extends the MassiveSearchBundle to provide a metadata driver for Sulu Structure classes. This enables Sulu content to be indexed.

Usage

This bundle integrates the MassiveSearchBundle into Sulu. For general usage informsation refer to the documentation for that bundle.

Mapping structure documents

You can map search indexes on structure documents in the structure template:

<?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>

The tag in the property is a hint for the search indexer. It will index the field as type "string" and it will use this field as the "title" for the search results.

Roles

When you tag structure properties you can optionally assign roles. Roles tell the search engine which fields should be available in the document via. various standard getters:

  • title: The title for the search result: $document->getTitle()
  • description: The description / excerpt for the search result: $document->getDescription()
  • image: Indicate a field which should be used to determine the image URL: $document->getImageUrl()

NOTE: If you are using the SuluMediaBundle you can specify a media field as the image field.

Indexing Structure documents

You index structure documents as you would any other object with the MassiveSearchBundle:

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

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

Searching

Likewise, searching is exactly the same as with the 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();

Search from the command line

See the MassiveSearchBundle documentation.

Rendering results

You can iterate over search results and retrieve the associated search document. The URL will be the Structure URL (determined automatically).

{% 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 %}

Requirements