Skip to main content

Solr integration for Plone using collective.solr

Project description

Introduction

ftw.solr provides various customizations and enhancements on top of collective.solr which integrates the Solr search engine with Plone.

Features

Atomic updates (aka partial updates)

Since Solr 4.0 it’s possible to update fields in a Solr document individually, sending only the fields that actually changed, whereas before it was necessary to send all the fields again every time something changed (and therefore ask Plone again to index them all, causing a massive performance penalty).

ftw.solr supports atomic updates for Solr version 4.1 and above. In order for atomic updates to work, three things must be taken care of:

  • An <updateLog /> must be enabled in solrconfig.xml. If it’s missing, Solr will reject any update messages that contain atomic update instructions.

  • A _version_ field must be defined in the Solr schema.

  • All fields in the Solr schema must be defined with stored="true"

In the stock Solr configs from 4.1 upwards <updateLog /> and the _version_ field are already configured correctly. If you’re using collective.recipe.solrinstance, check the generated solrconfig.xml, it might not have been updated for the use of atomic updates yet.

If there’s a field in the Solr schema that’s not stored="true", it will get dropped from documents in Solr on the next update to that document. Indexing won’t fail, but that field simply won’t have any content any more.

Apart from those prerequisites, there’s nothing more to be done in order to use atomic updates. ftw.solr will automatically perform atomic updates whenever possible.

Also see http://wiki.apache.org/solr/Atomic_Updates

Highlighting (aka Snippets)

When displaying search results, Plone by default displays the title and the description of an item. Solr, like Google and other search engines, can return a snippet of the text containing the words searched for. ftw.solr enables this feature in Plone.

Live search grouping

Search results in Plone’s live search can be grouped by portal_type. This is the way search results are shown in Spotlight on Mac OS X.

Facet queries

In addition to facet fields support provided by collective.solr, ftw.solr adds support for facet queries. This type of faceting offers a lot of flexibility. Instead of choosing a specific field to facet its values, multiple Solr queries can be specified, that themselves become facets.

Word Cloud

Assuming there is a correctly configured index wordCloudTerms, a Word Cloud showing the most common terms across documents can be displayed.

The Word Cloud is implemented in a browser view that can either be displayed stand-alone by traversing to /@@wordcloud or rendered in a portlet.

Ajax-ified search form

The search form is fully ajax-ified which leads to faster search results when changing search criteria.

Solr connection configuration in ZCML

The connections settings for Solr can be configured in ZCML and thus in buildout. This makes it easier when copying databases between multiple Zope instances with different Solr servers. Example:

zcml-additional =
    <configure xmlns:solr="http://namespaces.plone.org/solr">
        <solr:connection host="localhost" port="8983" base="/solr"/>
   </configure>

Solr Configuration

Search Handlers

ftw.solr requires two custom search handlers that must be configured on the Solr server. Search handlers are configured in solrconfig.xml of your collection.

The livesearch request handler is used for live search and should limit the returned fields to a minimum for maximum speed. Example:

<requestHandler name="livesearch" class="solr.SearchHandler">
    <lst name="defaults">
        <str name="echoParams">explicit</str>
        <int name="rows">1000</int>
    </lst>
    <lst name="invariants">
        <str name="fl">Title Description portal_type path_string getIcon</str>
    </lst>
</requestHandler>

The hlsearch request handler should contain the configuration for highlighting. Example:

<requestHandler name="hlsearch" class="solr.SearchHandler">
    <lst name="defaults">
        <str name="echoParams">explicit</str>
        <int name="rows">10</int>
        <bool name="hl">true</bool>
        <bool name="hl.useFastVectorHighlighter">true</bool>
        <str name="hl.fl">snippetText</str>
        <int name="hl.fragsize">200</int>
        <str name="hl.alternateField">Description</str>
        <int name="hl.maxAlternateFieldLength">200</int>
        <int name="hl.snippets">3</int>
    </lst>
</requestHandler>

Field types and indexes

Highlighting

Highlighting requires an index named snippetText with its own field type which does not do too much text analysis. Fields and indexes are configured in schema.xml of your collection.

Example:

<fieldType name="text_snippets" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
      <tokenizer class="solr.WhitespaceTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
      <tokenizer class="solr.WhitespaceTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

<field name="snippetText" type="text_snippets" indexed="true"
       stored="true" required="false" multiValued="false"
       termVectors="true" termPositions="true"
       termOffsets="true"/>

Word Cloud

The Word Cloud feature requires an index named wordCloudTerms with it’s own field type. It’s basically a copy of SearchableText but with less analysis and filtering (no lowercasing, no character normalization, etc…).

Field type example:

<fieldType name="cloud_terms" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
      <tokenizer class="solr.WhitespaceTokenizerFactory"/>
      <filter class="solr.StopFilterFactory" ignoreCase="true" words="${buildout:directory}/german_stop.txt" enablePositionIncrements="true"/>
      <filter class="solr.WordDelimiterFilterFactory"
              splitOnCaseChange="1"
              splitOnNumerics="1"
              stemEnglishPossessive="1"
              generateWordParts="0"
              generateNumberParts="0"
              catenateWords="0"
              catenateNumbers="0"
              catenateAll="0"
              preserveOriginal="1"/>
      <!-- Strip punctuation characters from beginning and end of terms -->
      <filter class="solr.PatternReplaceFilterFactory" pattern="^(\p{Punct}*)(.*?)(\p{Punct}*)$" replacement="$2"/>
      <!-- Filter everything that does not contain at least 3 regular letters -->
      <filter class="solr.PatternReplaceFilterFactory" pattern="^([^a-zA-Z]*)([a-zA-Z]{0,2})([^a-zA-Z]*)$" replacement=""/>
      <!-- Filter any term shorter than 3 characters (incl. empty string) -->
      <filter class="solr.LengthFilterFactory" min="2" max="50"/>
  </analyzer>
</fieldType>

Index example:

<field name="wordCloudTerms" type="cloud_terms" indexed="true"
       stored="true" required="false" multiValued="false"
       termVectors="true" termPositions="true"
       termOffsets="true"/>

<copyField source="SearchableText" dest="wordCloudTerms"/>

Installation

Install ftw.solr by adding it to the list of eggs in your buildout or by adding it as a dependency of your policy package. Then run buildout and restart your instance.

Go to Site Setup of your Plone site and activate the ftw.solr-autocomplete add-on. Check the Solr control panel provided by collective.solr for Solr-specific configuration options.

Changelog

1.4.0 (2015-02-26)

  • Add support for search results from external sites. Solr flares having a getRemoteUrl attribute that starts with ‘http’ are handled as external results. External sites can be indexed with ftw.crawler. [buchi]

  • BugFix in “recursive_index_security” method. Do not try to reindex the security on not catalog aware objects. [mathias.leimgruber]

  • Some work on docs (fix Pythonism, add some info, improve markup). [jean]

1.3.1 (2014-06-12)

  • Fix error in suggestions when there is no solr response. [buchi]

  • Make sure that string attributes of a PloneFlare are always utf-8 encoded byte strings to be consistent with catalog brains. [buchi]

1.3 (2013-12-19)

  • Updated jquery.history.js to latest version (1.8.0b2) which fixes issues with URI encoding in IE9. [buchi]

  • Removed link to advanced search in livesearch when no results are found. [buchi]

  • “show all”-link includes the path attribute. [elioschmutz]

  • Added support for forward as well as reverse wildcard search. This is done by providing two additional dynamic variables in the search pattern, value_lwc and value_twc that have leading respectively trailing wildcards appended to each of the search terms. [lgraf]

  • Fix querystring of suggestions with list parameters. [buchi]

1.2.2 (2013-09-24)

  • Added class around link to advanced search. [Julian Infanger]

1.2.1 (2013-09-10)

  • Fixed monkey patch of mangleQuery. [buchi]

1.2 (2013-09-10)

  • Improve reindexing object security performance. We now walk down the children and stop walking down if the security indexes of an object have not changed. [jone]

  • Added support for atomic updates. This means whenever possible, only the necessary / specified attributes get updated in Solr, and more importantly, re-indexed by Plone’s indexers. IMPORTANT: This requires the Solr instance to have an <updateLog/> configured in solrconfig.xml and the schema needs to contain a _version_ field. See http://wiki.apache.org/solr/Atomic_Updates for details. [lgraf]

  • Make sure values in search patterns are all lowercase. [buchi]

1.1.2 (2013-07-18)

  • Sort facet fields in the order specified in the Solr control panel. [buchi]

  • Fixed handling of path filter which was always removed when respect_navroot is set to False. [buchi]

  • Handle invalid facet parameters. [buchi]

  • Monkey patch reindexObjectSecurity for both CatalogAware and CatalogMultiplex so the relevant security indexes in solr also get updated. [lgraf]

  • Only add the default search argument to the query if it’s not None and if Solr has a default search field defined in it’s schema (which is deprecated in Solr). This mainly prevents logging of ‘dropping unknown search attribute’ warnings. [buchi]

  • Escape forward slashes in all query values, not only in paths. [buchi]

  • Always insert the default ‘select’ search handler into the query parameters if no ‘qt’ parameter is provided. We need this because we have to disable the /select search handler in the Solr configuration to be able to select other search handlers by parameter. [buchi]

1.1.1 (2013-06-01)

  • Also use livesearch request handler in livesearch when grouping is disabled. [buchi]

  • Fixed “show more” link in live search to point to @@search view. [buchi]

1.1 (2013-05-31)

  • Reorganized monkey patches. Everything patch-related now lives in the patches subpackage. [lgraf]

  • Make sure @@search view doesn’t fail when called without parameters. [lgraf]

  • Only display selected facets list if there actually are selected facets. [lgraf]

  • Added spellchecking feature (aka “Did you mean …”). [buchi]

  • Made respecting the navroot for searches configurable. Only if ISearchSettings.respect_navroot is set searches will be constrained to the navigation root (defaults to False). [lgraf]

  • Added autocomplete support based on Solr’s suggester component. [buchi]

1.0.2 (2013-05-28)

  • Fixed querytarget of livesearch for Plone 4.2 and later. Use our @@livesearch_reply view instead of livesearch_reply. [buchi]

  • Include description in snippetText. [buchi]

  • If there’s a SearchableText indexer, use it for snippetText generation. [buchi]

  • Make length of breadcrumbs shown in search results configurable. [buchi]

  • Added option to generate breadcrumbs from path rather than calling breadcrumbs_view for each item. [buchi]

  • Added support for dexterity content types in snippetText indexer. [buchi]

1.0.1 (2013-05-21)

  • Monkey patching c.solr.search.Search.buildQuery in order to escape slahes in paths. [lgraf]

  • Overwrite search extender: Add write permissions, fixed translations and allowed content types in textfield. [Julian Infanger]

  • Added option to scale Word Cloud by a constant factor. [lgraf]

  • Added basic portlet to display Word Cloud. [lgraf]

  • Added basic Word Cloud browser view. [lgraf]

1.0a1 (2012-08-22)

  • Initial release

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ftw.solr-1.4.0.zip (127.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page