Sourcefabric Manuals

 English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

Newscoop 4.2 Cookbook

Templates to Search with Solr

Instead of list_search_results you have to use list_search_results_solr in your Newscoop templates for Solr search results to be displayed. The parameters are:

ParameterDescription
q Query string. Default value: $_GET['q'].
qf Fields to query. Can be titletypewebcodeauthorstopicskeywordscustom field name. You can use multiple separated by space e.g. qf="title full_text". You can also boost relevancy of any field with ^number operator e.g. fq="title^3.4". Default value: title.
rows Number of rows to be returned. Use for pagination. Default value: 10.
start Number of row to start with. Use for pagination. Default value: 0.
fq Optional filter query. Can be used for results filtering e.g. fq="type:news".
sort Set sorting of results. Default value: score desc.

The search form

Here is an example of a search form you could use in a Newscoop template.

{{ form_search_solr id="search" class="hidden-phone" }}
  {{ form_text name="q" value=$smarty.get.q }}
  {{ form_submit name="" value=" " }}
{{ /form_search_solr }}

Listing the results

Here is example template code that would list search results including article titles. author names, images and photographer credits:  

{{ list_search_results_solr fq="type:news" qf="title^5 deck^3 full_text" start=$smarty.get.start }}

{{ if $gimme->current_list->at_beginning }} <ul> {{ /if }}

<li class="news_item {{ cycle values="odd,even" }}"> {{ image rendition="thumb" }} <img src="{{ $image->src }}" alt="{{ $image->caption }} (photo: {{ $image->photographer }})" /> <span>{{$gimme->section->name}}</span> {{/image}} <div class="content"> <h2 class="title"><a href="{{url options="article"}}"> {{$gimme->article->title}}</a></h2> <h5 class="author">{{list_article_authors}} {{$gimme->author->name}} {{/list_article_authors}}</h5> <p>{{$gimme->article->deck|strip_tags|truncate:200:"...":false}}</p> </div> </li>
{{ if $gimme->current_list->at_end }} </ul> {{ /if }}

{{ /list_search_results_solr }}

There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.