symfony-cmf / search-bundle

UNMAINTAINED - search Bundle for the Symfony CMF project integrating with LiipSearchBundle
http://cmf.symfony.com/
8 stars 10 forks source link

allow custom document properties in search results #5

Closed levuro closed 11 years ago

levuro commented 11 years ago

right now a search result entry consists only of url title and summary

how can we return a special property such as image in the result list? its in almost all our content documents

thanks for the feedback eric

$searchResults[$contentId] = array( 'url' => $url, 'title' => $row->getValue($this->searchFields['title']), 'summary' => $this->buildSummary($row), );

dbu commented 11 years ago

i guess the easiest would be to overwrite the search helper to include additional fields and overwrite the template to display them. maybe you can refactor the helper to be easier to customize how to convert the result

levuro commented 11 years ago

which helper are your referring to ? i can see the code is inside PhpcrSearchController - or are i am missing anything? I already tried to extend the controller but i didnt succeed - i tried to extend SymfonyCmfSearchBundle with my own bundle as outlined in the symfony docs but somehow lLiipSearchBundle didnt like this ....

dbu commented 11 years ago

ah i was looking at LiipSearchBundle. there the actual search was in a helper, which is cleaner than the super-fat controller of this bundle. extending the bundle should not be needed, i would recommend you refactor the PhpcrSearchController a bit.

you already can inject the searchFields, telling it which fields to search. buildSearchResults however is limited to hardcoded 'title' and 'summary'. here we should loop over the other searchFields and add them to the result. then you could simply configure your additional fields and adjust the template to show them.

think you can do that PR?

lsmith77 commented 11 years ago

@joiz do you need assistance here?

levuro commented 11 years ago

@lsmith77 - possible - at least conceptual :) - i already tried davids solution but i think this is not good enough for us - we would like to display images and those are actually part of the PHPCR and stored in a subnode instead of the node attributes returned from the query

i think best would be a solution were we define the search fields at one side - and for the output we would generate a list of fully mapped document classes - this way the developer can output whatever he wants in the twigs - including images etc

dbu commented 11 years ago

the search result should tell the paths, with the paths you can use the twig functions to get the odm documents for those paths and access mapped children and everything.

levuro commented 11 years ago

Yes - this actually works

{{ (result.path ~ '/image') | imagine_filter('cmf_111_63') }}

The problem i face now is that all our documents have different paths to image resources - So a video document might have a previewImage - a Host a image and a some other document class event more than one images To make I this work OK in the frontend i implement

interface TeaserInterface {

public function getTeaserTitle();

public function getTeaserImage();

into each document class.

I can then rely on some image resource returned by doing

public function getTeaserImage() {
    return $this->image;
}

this obviously doesnt work with paths.

What do you suggest in this case?

the background of this issues is that we search all documents in our page - and those with a teaserimage should be shown with and image in the result list

On 22.04.2013, at 14:50, David Buchmann notifications@github.com wrote:

the search result should tell the paths, with the paths you can use the twig functions to get the odm documents for those paths and access mapped children and everything.

— Reply to this email directly or view it on GitHub.

dbu commented 11 years ago

i don't get what you mean by "doesn't work with paths". if some images are stored in the filesystem instead of phpcr, you would need some flag or check in twig and use a different imagine filter that is for filesystem rather than phpcr.

levuro commented 11 years ago

Looks like i didnt explain this good enough

just imagine - there is one search result where the path to the image stored in the CR is

/blogs/myblogpost/fullimage

another one might be

/show/noiz/monday/bigimage

a third one might not have a image at all

in the search results i would like to render a small thumbnail next to the result - i dont know what the name is

on the homepage of our new site i can teaser any content because i implement a interface which forces my document class to have at least a getter for a image resource - @lsmith77 this is ok isn't it?

no interface - no teaser :)

so - on the search result page it would be great to use the same aproach

lsmith77 commented 11 years ago

so either force every node with an image to follow this interface. another alternative would be to create a twig helper function that allows you to encapsulate the logic to determine based on the document class which property to consider.

levuro commented 11 years ago

maybe we can chat in skype ;) ?

levuro commented 11 years ago

https://github.com/symfony-cmf/SearchBundle/pull/8 -= easy solution in twig