Giter VIP home page Giter VIP logo

sphinxsearch's Introduction

Sphinx Search

Handler for Sphinx API Client. It contains most used functions to setup field weights, filter, sorting and multi-quering.

Tested on Sphinx Server 2.1.9 / 2.2.4 and sphinx PECL package 1.3.2.

Requirements

This package requires PHP 5.4.

Installation

The best way to install this package is using Composer

$ composer require "rikiless/sphinx-search:@dev"

Nette Framework

If you are using Nette Framework you can simply register service:

sphinx:
		host: localhost
		port: 9312

services:
	- Rikiless\Sphinx\Search(%sphinx%)

In presenter:

class Presenter ...
{

	/** @var Rikiless\Sphinx\Search @inject */
	public $fulltextSearch;

}

Use

Examples

Simple query:

$fulltext = new Rikiless\Sphinx\Search([
    'host' => 'localhost',
    'port' => 9312
]);

try {
 	/** @var Rikiless\Sphinx\Data $results */
    $results = $fulltext->query('search something');
	var_dump($results->getMatchesList());
	
} catch (Rikiless\Sphinx\Exception $e) {
    print $e->getMessage();
}

Multiple queries with basic setup:

$search = 'search something';

$this->fulltextSearch->setIndex('myindex');
$this->fulltextSearch->setLogComment(sprintf('Fulltext query on %s', $this->domain));
$this->fulltextSearch->setFieldWeights([
    'name' => 10,
	'content' => 5,
	'subject_name' => 3,
	'city' => 2,
	'contact_person' => 2
]);

$this->fulltextSearch->resetFilters();
$this->fulltextSearch->setFilterRange('position', 0, 19999999);
$this->fulltextSearch->addQuery($search);

$this->fulltextSearch->resetFilters();
$this->fulltextSearch->setFilterRange('position', 20000000, 29999999);
$this->fulltextSearch->addQuery($search);

try {
    $results = $this->fulltextSearch->runQueries();
} catch (Rikiless\Sphinx\Exception $e) {
    print $e->getMessage();
}

foreach ($results as $row) {
	/** @var Rikiless\Sphinx\Data $row */
	var_dump($row->getMatches());
}

Sources

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.