Giter Site home page Giter Site logo

elemental-search's Introduction

SilverStripe - Elemental search

Introduction

This module integrates dnadesign/silverstripe-elemental into SilverStripe's Fulltext search and provides extensions to create search documents for your Pages or any data objects which you need to work with the full text search. The module comes in handy for systems where you dont want to make use of complex search systems like Solr.

Requirements

  • SilverStripe ^4.0
  • Elemental ^2.0

Installation

Install with Composer:

composer require silverstripers/elemental-search dev-master

Ensure you run dev/build?flush=1 to build your database and flush your cache.

Usage

Enable Full text search

The module once installed elables Full text search by itself on the SearchDocument dataobject. There are no additional configs you want to use.

Create a search form

Create a search form with the code below and display on a template

use SilverStripe\CMS\Search\SearchForm;


class  MyController extends Controller {

   public function SearchForm() 
   {
      return SearchForm::create($this, 'SearchForm');
   }
   
   public function results($data, $form, $request)
    {
        $data = array(
            'Results' => $form->getResults(),
            'Query' => DBField::create_field('Text', $form->getSearchQuery()),
            'Title' => _t('SilverStripe\\CMS\\Search\\SearchForm.SearchResults', 'Search Results')
        );
        return $this->owner->customise($data)->renderWith(array('Page_results', 'Page'));
    }

}

Include objects to search.

Any data object you'd like to include in the search has to be decorated with the SilverStripers\ElementalSearch\Extensions\SearchDocumentGenerator. After doing this this extension will make a search document each time when the data object is created, updated, and when deleted it will delete the search document. For Versioned data objects it will only create search documents when the object is published.

Specify which contents needs to be searched.

For the webpages you have the option to configure which dom elements to include in the search. Eg: You wont need it to cache the whole page and run search on certain info which duplicates over the site like the navigations.

SilverStripers\ElementalSearch\Model\SearchDocument:
    search_x_path:
        - main-content

In the situation where you have content outside of elemental elements that you want to include in the search.

SilverStripers\ElementalSearch\Model\SearchDocument:
    only_use_x_path: true

The above settings will render the page and exract content within the main-content DOM node, and create the document.

How it works

The module adds a new DataObject SearchDocument. This gets created when each of the search enabled pages. And it is how it creates aggregated search results.

The module overrides the MySQLDatabase and the search result queries.

Reporting Issues

Please create an issue for any bugs, or submit merge requests.

elemental-search's People

Contributors

fonsekaean avatar abstractk avatar robertlecreux avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.