Coder Social home page Coder Social logo

pg-sphinx's Introduction

pg-sphinx

https://travis-ci.org/andy128k/pg-sphinx.svg?branch=master

Pg-sphinx is an extension for PostgreSQL which allows to integrate Sphinx search engine.

Installation

Compile

make

Install

sudo make install

Define sphinx functions in your database

Superuser is required.

echo 'CREATE EXTENSION sphinx;' | psql -U postgres mydatabase

Uninstall

sudo make uninstall

Configuration

Extension can be configured by modifying corresponding rows in table sphinx_config. Following options are available: ‘host’, ‘post’, ‘username’, ‘password’, ‘prefix’.

‘Prefix’ is a string which is prepended to index names. This option is useful to simulate namespaces. For example, if prefix is ‘test_’ and index name in a request is ‘blog_posts’, real request will be addressed to index named ‘test_blog_posts’.

Functions

Search query

sphinx_select(
    /*index*/     varchar,
    /*query*/     varchar,
    /*condition*/ varchar,
    /*order*/     varchar,
    /*offset*/    int,
    /*limit*/     int,
    /*options*/   varchar)

Returns pairs (id, weight).

Update data

sphinx_replace(
    /*index*/     varchar,
    /*id*/        int,
    /*data*/      varchar[])

Updates document with specified id. Data array must have following format: ARRAY[‘key1’, ‘value2’, …]

Update data for disk index

sphinx_update(
    /*index*/     varchar,
    /*id*/        int,
    /*data*/      varchar[])

Updates document with specified id in disk index. Data array must have following format: ARRAY[‘key1’, ‘value2’, …] Values may be only integer type.

Delete data

sphinx_delete(
    /*index*/     varchar,
    /*id*/        int)

Removes specified document.

Get snippet

sphinx_snippet(
    /*index*/     varchar,
    /*query*/     varchar,
    /*data*/      varchar,
    /*before*/    varchar,
    /*after*/     varchar)

Returns snippets for a given data and search query.

Example:

SELECT sphinx_snippet('blog_posts', 'photo', 'There are photos from monday meeting', '<b>', '</b>')

This query will return following text:

'There are <b>photos</b> from monday meeting'
sphinx_snippet_options(
    /*index*/     varchar,
    /*query*/     varchar,
    /*data*/      varchar,
    /*options*/   varchar[])

Returns snippets for a given data and search query. This function is similar to sphinx_snippet but it also accepts a list of additional options.

Because of array type limitations all values must be represented as text. Integer values have to be represented as decimal values (e. g. ‘19’). For boolean values ‘1’, ‘t’, ‘true’, ‘y’, and ‘yes’ are recognized as true, any other value is considered as false.

Example (similar to previous one):

SELECT sphinx_snippet_options('blog_posts', 'photo', 'There are photos from monday meeting',
                              ARRAY['before_match', '<b>',
                                    'after_match', '</b>'])

One more example:

SELECT sphinx_snippet_options('blog_posts', 'photo', 'There are photos from monday meeting',
                              ARRAY['before_match', '<b>',
                                    'after_match', '</b>',
                                    'query_mode', 'yes'])

pg-sphinx's People

Contributors

andy128k avatar k2fl avatar

Watchers

 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.