2017 © Pedro Peláez
 

silverstripe-vendormodule silverstripe-swiftype

Use Swiftype search with Silverstripe

image

ichaber/silverstripe-swiftype

Use Swiftype search with Silverstripe

  • Friday, April 27, 2018
  • by ichaber
  • Repository
  • 2 Watchers
  • 1 Stars
  • 87 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 43 % Grown

The README.md

SilverStripe Swiftype

Build Status Scrutinizer Code Quality codecov, (*1)

Installation

Install with Composer:, (*2)

composer require ichaber/silverstripe-swiftype

Also see Configuration. Extensions and configurations are not applied automatically., (*3)

Documentation

Provides the necessary code for configuring the swiftype integration code with the access key and for adding metadata tags to the site code so the Swiftype crawler can be index them., (*4)

The code also provides an extension which triggers a re-index after a page is published/unpublished in the SilverStripe CMS admin area., (*5)

How does it work?

MetaTags

There are a bunch of standard SwiftypeMetaTag classes. Each of these classes represents one of the standard SilverStripe SiteTree fields or methods, and will be used to output a single meta tag into your markup., (*6)

Here are the standard classes, and which SiteTree field/method they represent:, (*7)

  • SwiftypeMetaTagDescription (MetaDescription field)
  • SwiftypeMetaTagPublishedAt (LastEdited field)
  • SwiftypeMetaTagTitle (Title field)
  • SwiftypeMetaTagURL (Link() method)

Additionally, there is a robots class, which can be used to output noindex and/or nofollow (configurable) when your SiteTree record has ShowInSearch set to 0. By default, this will render with just noidex, but you can update it's config to also render with nofollow., (*8)

  • SwiftypeMetaTagRobots

Templating

If you are using out of the box functionality (see Configuration), then in your template, you can simply use $SwiftypeMetaTags to output all of the meta tags that you have set up as part of your install., (*9)

Crawling

If you are using out of the box functionality (see Configuration), then when you publish a page, a request will be sent to Swiftype for it to crawl that page., (*10)

Configuration

Simple

If you just want to plug and play, then apply the following three extensions., (*11)

SilverStripe\SiteConfig\SiteConfig:
  extensions:
    - Ichaber\SSSwiftype\Extensions\SwiftypeSiteConfigFieldsExtension
SilverStripe\CMS\Model\SiteTree:
  extensions:
    - Ichaber\SSSwiftype\Extensions\SwiftypeSiteTreeCrawlerExtension
    - Ichaber\SSSwiftype\Extensions\SwiftypeMetaTagContentExtension

These will provide you with: - The standard CMS fields for adding your Swiftype credentials. - A template variable ($SwiftypeMetaTags) for outputting your meta tags. - Re-index requests to Swiftype on SiteTree publishing., (*12)

You will then need specify which Meta Tags you would like to use. You can do this in two ways., (*13)

In a config yaml:, (*14)

App\Page\MyPage:
  swiftype_meta_tag_classes:
    - Ichaber\SSSwiftype\MetaTags\SwiftypeMetaTagDescription
    - Ichaber\SSSwiftype\MetaTags\SwiftypeMetaTagPublishedAt
    - Ichaber\SSSwiftype\MetaTags\SwiftypeMetaTagRobots
    - Ichaber\SSSwiftype\MetaTags\SwiftypeMetaTagTitle
    - Ichaber\SSSwiftype\MetaTags\SwiftypeMetaTagURL

Or in your model:, (*15)

class MyPage extends SiteTree
{
    /**
     * @var array
     */
    private static $swiftype_meta_tag_classes = [
        SwiftypeMetaTagDescription::class,
        SwiftypeMetaTagPublishedAt::class,
        SwiftypeMetaTagRobots::class,
        SwiftypeMetaTagTitle::class,
        SwiftypeMetaTagURL::class,
    ];
}

Either of these methods should provide you with good control if you have different page types needing different meta tags., (*16)

A quick note on the Robots class, (*17)

Swiftype uses the standard <meta name="robots" content="noindex"> meta tag, so if you are already outputting this tag through some other means, then you will want to exclude it here. Also see [Customising the robots Meta Tag](#Customising the robots Meta Tag), (*18)

Piece by piece

To use the standard SiteConfig CMS fields, you can apply SwiftypeSiteConfigFieldsExtension to your SiteConfig. This will provide you with some basic options to set up a single engine for your site., (*19)

Currently there is minimal support for multiple engines on a single site - you will (most likely) need to add your own implementation if you desire this., (*20)

SilverStripe\SiteConfig\SiteConfig:
  extensions:
    - Ichaber\SSSwiftype\Extensions\SwiftypeSiteConfigFieldsExtension

If you are using the Swiftype Crawler, and would like to add "re-crawl" actions after your pages un/publish, you can apply SwiftypeSiteTreeCrawlerExtension to SiteTree (or another model of your choice)., (*21)

SilverStripe\CMS\Model\SiteTree:
  extensions:
    - Ichaber\SSSwiftype\Extensions\SwiftypeSiteTreeCrawlerExtension

If you would like SiteTree to have access to the standard template variable, then apply the following extension., (*22)

SilverStripe\CMS\Model\SiteTree:
  extensions:
    - Ichaber\SSSwiftype\Extensions\SwiftypeMetaTagContentExtension

Indexing Files

If you are using the Swiftype Crawler, and would like to add "re-crawl" actions after your Files un/publish, you can apply SwiftypeFileCrawlerExtension to File (or another model of your choice)., (*23)

SilverStripe\CMS\Model\File:
  extensions:
    - Ichaber\SSSwiftype\Extensions\SwiftypeFileCrawlerExtension

There is also a config to allow certain file types from being indexed/reindexed. yml Ichaber\SSSwiftype\Extensions\SwiftypeFileCrawlerExtension: reindex_allowed_extensions: - pdf, (*24)

NB: by default this config does not set any extensions to be indexed., (*25)

Indexing custom DataObjects

If you want to index your own custom DataObjects, simply create your own crawler extension by extending, (*26)

Adding your own Meta Tags

You can easily add your own classes to your objects (see Installation)., (*27)

Any classes that you add are expected to implement SwiftypeMetaTagInterface, but that's about it., (*28)

You can also feel free to extend SwiftypeMetaTag, if you would like access to methods like generateMetaTagsString()., (*29)

Customising the robots Meta Tag

There are two configs available for the robots Meta Tag. These allow you to control whether you add noindex and/or nofollow. By befault, noindex is added, but we allow robots to follow., (*30)

Ichaber\SSSwiftype\MetaTags\SwiftypeMetaTagRobots:
  no_index: true
  no_follow: false

You can override these by adding your own config. EG: Adding both noidex and nofollow., (*31)


--- Name: app_swiftype_tags After: swiftype_tags --- Ichaber\SSSwiftype\MetaTags\SwiftypeMetaTagRobots: no_index: true no_follow: true

Requirements

  • PHP 7.1 or higher
  • SilverStripe Framework 4.x
  • SilverStripe CMS 4.x

The Versions

27/04 2018

dev-master

9999999-dev http://github.com/ichaber/silverstripe-swiftype

Use Swiftype search with Silverstripe

  Sources   Download

BSD-3-Clause

The Requires

 

by Chris Penny
by Charlie Bergthaler

search silverstripe swiftype

27/04 2018

0.1.3

0.1.3.0 http://github.com/ichaber/silverstripe-swiftype

Use Swiftype search with Silverstripe

  Sources   Download

BSD-3-Clause

The Requires

 

by Chris Penny
by Charlie Bergthaler

search silverstripe swiftype

27/04 2018

dev-develop

dev-develop http://github.com/ichaber/silverstripe-swiftype

Use Swiftype search with Silverstripe

  Sources   Download

BSD-3-Clause

The Requires

 

by Chris Penny
by Charlie Bergthaler

search silverstripe swiftype

24/04 2018

0.1.2

0.1.2.0 http://github.com/ichaber/silverstripe-swiftype

Use Swiftype search with Silverstripe

  Sources   Download

BSD-3-Clause

The Requires

 

by Chris Penny
by Charlie Bergthaler

search silverstripe swiftype

09/04 2018

0.1.1

0.1.1.0 http://github.com/ichaber/silverstripe-swiftype

Use Swiftype search with Silverstripe

  Sources   Download

BSD-3-Clause

The Requires

 

by Chris Penny
by Charlie Bergthaler

search silverstripe swiftype

26/03 2018

0.1

0.1.0.0 http://github.com/ichaber/silverstripe-swiftype

Use Swiftype search with Silverstripe

  Sources   Download

BSD-3-Clause

The Requires

 

by Chris Penny
by Charlie Bergthaler

search silverstripe swiftype