sulu / search-bundle
Sulu Search Bundle
Installs: 1 275
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 19
Forks: 0
Open Issues: 0
Requires
- massive/search-bundle: 0.3.*
- sulu/sulu: 0.9.*
Requires (Dev)
- massive/build-bundle: 0.2.*
- sulu/test-bundle: 0.9.*
- zendframework/zend-stdlib: ~2.3
- zendframework/zendsearch: @dev
Suggests
- zendframework/zend-stdlib: Needed (as in require dev) in addition to zendsearch
- zendframework/zendsearch: To use the PHP based Zend Search library (based on Lucene)
This package is not auto-updated.
Last update: 2016-03-10 09:13:12 UTC
README
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
- Symfony: 2.3.*
- See the require section of composer.json