adair-creative/searching

There is no license information available for the latest version (dev-master) of this package.

A tool for easy and advanced search and analytical functionality

dev-master 2019-08-12 15:09 UTC

This package is auto-updated.

Last update: 2024-04-13 01:39:15 UTC


README

About

A tool for flexible and advanced search functionality including:

  • CMS Analytics
  • Search term routing
  • Non-intrusive implementation

Installation

composer require adair-creative/searching

Guide

Basic Usage

use AdairCreative\Searching;

class YourPage_Controller extends PageController {
	 public function index(HTTPRequest $request) {
		if ($query = $request->getVar('q')) {
			return $this->customise([
				"Results" => Searching::search(Product::class, "Title", $search);
			]);
		}
	}
}

Term Linking

// ...

$link = null;
$resources = Searching::search(Product::class, "Title", $query, $link, true);

if ($link != null) {
	if ($link->Type == 1) return $this->redirect($link->Redirect()->Link());
	else $query = $link->Substitute;
}

// ...

Reference

AdairCreative\Searching

function search() : ArrayList

string|string[] $from - The model(s) to search from

string|string[] $fieldName - The field(s) to search from, if array items will map to corresponding model

string $query - Value to seach with; trimmed and no-case

Default null TermLink &$term - A pointer to the first found term (null if none)

Default false bool $useSubstitute - When true, If $term is of type substitute then update $search to the substitute value

AdairCreaitve\Searching\TermLink

string $Term - the search term to override

int $Type - The action to perform on override

0 - Use substitute

1 - Use redirect

string $Substitute - The search value substitute

function Redirect() : SiteTree