Giter Club home page Giter Club logo

node-sphinxapi's Introduction

Sphinx Search Client for NodeJS

See ITPatrol repository for the latest developments.

It's native javascript implementation of the standard Sphinx API. The API is totaly similar with the others API clients implementation. It's also respects NodeJS code convention.

This implementation is based on the Python Official Sphinx Client.

Contributors

Installation

With npm do:

$ npm install sphinxapi

Examples

Status

var SphinxClient = require ("sphinxapi"),
	util = require('util'),
	assert = require('assert');

var cl = new SphinxClient();
cl.SetServer('localhost', 19312);
cl.Status(function(err, result) {
		assert.ifError(err);
		console.log(util.inspect(result, false, null, true));
})

Query

var SphinxClient = require ("sphinxapi"),
	util = require('util'),
	assert = require('assert');

var cl = new SphinxClient();
cl.SetServer('localhost', 19312);
cl.Query('test', function(err, result) { 
		assert.ifError(err);
		console.log(util.inspect(result, false, null, true));
});

API Documentation

from the official documentation : http://sphinxsearch.com/docs/current.html#api-reference

Porting Status GetLastError()

Porting Status GetLastWarning()

Porting Status SetServer (host, port)

Porting Status SetConnectTimeout (timeout)

Porting Status SetLimits (offset, limit, maxmatches, cutoff)

Porting Status SetMaxQueryTime (maxquerytime)

Porting Status SetMatchMode (mode)

Porting Status SetRankingMode (ranker, rankexpr)

Porting Status SetSortMode (mode, clause)

Porting Status SetWeights (weights)

Porting Status SetFieldWeights (weights)

Porting Status SetIndexWeights (weights)

Porting Status SetIDRange (minid, maxid)

Porting Status SetFilter (attribute, values, exclude)

Porting Status SetFilterRange (attribute, min, max, exclude)

Porting Status SetGeoAnchor (attrlat, attrlong, latitude, longitude)

Porting Status SetGroupBy (attribute, func, groupsort )

Porting Status SetGroupDistinct (attribute)

Porting Status SetRetries (count, delay)

Porting Status SetOverride (name, type, values)

Porting Status SetSelect (select)

Porting Status ResetOverrides ()

Porting Status ResetFilters ()

Porting Status ResetGroupBy ()

Porting Status Query (query, index, comment, fn)

Porting Status AddQuery (query, index, comment)

Porting Status RunQueries (fn)

Porting Status BuildExcerpts (docs, index, words, opts)

Porting Status UpdateAttributes (index, attrs, values, mva)

Porting Status BuildKeywords (query, index, hits )

Porting Status Status (fn)

Porting Status Open ()

Porting Status Close ()

Porting Status EscapeString (string)

Porting Status FlushAttributes ()

Also

License

MIT/X11

Bitdeli Badge

node-sphinxapi's People

Contributors

biggora avatar bitdeli-chef avatar gormartsen avatar johnmarkg avatar kerphi avatar mdevils avatar petermu avatar reqq avatar senxation avatar shlee322 avatar touv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-sphinxapi's Issues

quick question

When the sphinx search goes out does it all happened async like other database npm's? Or is there any event loop blocking going on?

SetFieldWeights broken, or am I using it incorrectly.

cl.SetFieldWeights({
        question : 20,
        tags : 50,
        body : 10
    });

This throws the error: AssertionError: "undefined" == "object"
in line ../node_modules/sphinxapi/lib/sphinxapi.js:315:9)

This is the code. I think I notice a couple of mistakes there...

SphinxClient.prototype.SetFieldWeights = function (weights) {
  var self = this
    assert.equal(typeof item, 'object')
    forEach(weights, function (item, index) {
            assert.equal(typeof item, 'number')
    })
    self._fieldweights = weights
};

Please have a look. Thanks

BUG:can't search utf8 string ( and can't display correct utf8 encoding result)

When i query '测试' or other string。。。example: 'ふじこ' 。。node-sphinxapi display some error.Whether it not support the search for utf8 encoding string
btw: it do not display correctly results ( utf8 encoding)

the code 1:
var SphinxClient = require ("./node-sphinxapi/lib/sphinxapi.js"),
assert = require('assert');

var cl = new SphinxClient();
cl.SetServer('127.0.0.1', 9312);
cl.Query('忍者', 'xml', function(err, res) { 
      console.log(err, res);
});

I put 'console' in sphinxapi.js (line: 456)

    console.log(err).
            console.log(response).
    console.log(response.toString('utf8')).

the result is:
[Error: searchd error: invalid weight count -1914142587 (should be in 0..256 range)]
null

e:\node-sphinxapi\lib\sphinxapi.js:459
                var max_ = response.length
                 ^
TypeError: Cannot read property 'length' of null
    at E:\project\root\apps\app\minefield\gl\node-sphinxapi\lib\sphinxapi.js:459:22
    at Socket.<anonymous> (E:\project\root\apps\app\minefield\gl\node-sphinxapi\lib\sphinxapi.js:183:7)
    at Socket.emit (events.js:67:17)
    at TCP.onread (net.js:377:14)

the code 2:
var SphinxClient = require ("./node-sphinxapi/lib/sphinxapi.js"),
assert = require('assert');

var cl = new SphinxClient();
cl.SetServer('127.0.0.1', 9312);
cl.Query('loli', 'xml', function(err, res) { 
        console.log(err, res);
});

result is :
null [ { error: '',
warning: '',
status: [ 0 ],
fields: [ 'name' ],
attrs: [ [Object], [Object] ],
matches: [ [Object] ],
total: 1,
total_found: 1,
time: 0.001,
words: [ [Object] ] } ]
I put 'console' in sphinxapi.js (line: 456)
console.log(err).
console.log(response).
console.log(response.toString('utf8')).
its display some data like:
null
<Buffer 00 00 00 00 00 00 00 01 00 00 00 04 6e 61 6d 65 00 00 00 02 00 00 ...>
loli忍者 .......

explicit version for "put" dependency

Is it possible to specify explicit version of put dependency? We use npm shrinkwrap in a project and get an error about unexpected version.

"put": "^0.0.6" should work just fine

I can (and will) file corresponding bug against npm, but it should be an easy fix on your side, while fixing npm will take quite some time

connection problem

I tried query but got this error

null

assert.js:324
assert.ifError = function(err) { if (err) {throw err;}};
^
Error: searchd connexion error
at Socket. (/home/arief/programming/nodejs/sphinxapi/node_modules/sphinxapi/lib/sphinxapi.js:220:7)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:441:14
at process._tickCallback (node.js:415:13)

please help

Why not use persist connect in sphinxapi ?

SphinxClient.prototype.Open = function (fn) {
// var self = this
// command, command version = 0, body length = 4, body = 1
// var request = pack ( '>hhII', [SphinxClient.SEARCHD_COMMAND_PERSIST, 0, 4, 1] )
// self._SendRequest(null, request, function (err, response) {
// fn(err, null)
// })
};
comment in code ?

Getting nothing!

I am getting no results or returned value even errors. here's my code:

const SphinxClient = require('sphinxapi'),util = ('util'),assert = ('assert');

var cl = new SphinxClient();
cl.SetServer('localhost', 9300);

var q = "SELECT *,weight() as w from myindex where match('@find *test*') ORDER BY w DESC";
cl.Query(q, 'myindex', function(err, result){
    console.log(result);
});

can someone help?

SetGeoAnchor does not work.

I use this code below:

client.SetGeoAnchor('dep_latitude', 'dep_longitude', 0.21, 0.2);

then sphinxd reports:
query error: index rt: unknown latitude attribute ''

rt index informations:
mysql> desc rt;

+---------------------+-----------+
| Field               | Type      |
+---------------------+-----------+
| id                  | integer   |
| nickname            | field     |
| sponsor             | field     |
| departure           | field     |
| destination         | field     |
| remark              | field     |
| dep_geohash         | field     |
| dest_geohash        | field     |
| event_mode          | uint      |
| sponsor_code        | uint      |
| event_sub_type_code | uint      |
| car_type            | uint      |
| gender              | uint      |
| source              | uint      |
| dep_longitude       | float     |
| dep_latitude        | float     |
| dest_longitude      | float     |
| dest_latitude       | float     |
| start_time          | timestamp |
| update_time         | timestamp |
+---------------------+-----------+
20 rows in set (0.31 sec)

I use SphinxSE:

select * from sphinx where query = 'select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23);'

it works well.

Slow script speed

nodejs:
var SphinxClient = require('sphinxapi'),

docs = ['this is my test text to be highlighted','this is another test text to be highlighted'];
words = 'test text';
index = 'test';
opts = {'before_match':'', 'after_match':'', 'chunk_separator':' ... ', 'limit':400, 'around':15};

var cl = new SphinxClient();
cl.SetServer('localhost', 9312);
for (i=0;i<1000;i++) {
cl.BuildExcerpts (docs, index, words, opts, function(error, results) {
console.log(results)
})
}

real 0m31.281s

python:
from sphinxapi import *
import sys

docs = ['this is my test text to be highlighted','this is another test text to be highlighted']
words = 'test text'
index = 'test'

opts = {'before_match':'', 'after_match':'', 'chunk_separator':' ... ', 'limit':400, 'around':15}

i = 0

cl = SphinxClient()
cl.Open()
while i < 1000:
res = cl.BuildExcerpts(docs, index, words, opts)
print res
i = i + 1
print i
cl.Close()

real 0m0.854s
user 0m0.071s
sys 0m0.021s

Why ?

SortMode not working

Hi, im trying to sort my results by a UNIX_TIMESTAMP field, with no results, first i think that may be my sphinx conf or someting but i write a simple php script and works the sort by date

ive try t sort using this config

cl._sort = "fecha_ingreso";
cl._sort = { SPH_SORT_ATTR_DESC: 'fecha_ingreso' }
cl._sort = {'SPH_SORT_ATTR_DESC': 'fecha_ingreso' }

any ideas..

regards.

SetGeoAnchor function's assert should not be float

Line 391:

SphinxClient.prototype.SetGeoAnchor = function (attrlat, attrlong, latitude, longitude) {
  var self = this
    assert.equal(typeof attrlat, 'string')
    assert.equal(typeof attrlong, 'string')
    assert.equal(typeof latitude, 'float')
    assert.equal(typeof longitude, 'float')

The last two statements should be:

    assert.equal(typeof latitude, 'number')
    assert.equal(typeof longitude, 'number')

Support for BigInt ids

How can we implement support for records with BigInt Ids using the bigint library?

Cheers

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.