我使用node-sphinx模块作为节点并让它工作,但我能弄清楚的是如何设置属性。看完示例代码后:
var SphinxClient = require ("sphinxapi"),
util = require('util'),
assert = require('assert');
var cl = new SphinxClient();
cl.SetServer('localhost', 19312);
我认为你只是用过:
cl.SetRankingMode(ranker, rankexpr);
cl.SetSortMode(mode, clause);
cl.SetFilter(attribute, values, exclude);
etc...
但不确定需要什么,字符串,整数,什么值或常量如php连接器等
是否有使用此模块的示例?
修改
我能够像下面这样设置这些属性:
cl.SetMatchMode(SphinxClient.SPH_MATCH_EXTENDED2);
cl.SetRankingMode(SphinxClient.SPH_RANK_SPH04);
cl.SetFieldWeights({ 'text': 100, 'tags': 200});
设置字段权重中的文本和标签是我索引中数据库的字段。
感谢Mark Dickson Jr。
答案 0 :(得分:1)
在查看http://github.com/touv/node-sphinxapi/blob/master/lib/sphinxapi.js时,有一个非常大的"常数"从第980行开始:
// known searchd commands
SphinxClient.SEARCHD_COMMAND_SEARCH = 0
SphinxClient.SEARCHD_COMMAND_EXCERPT = 1
SphinxClient.SEARCHD_COMMAND_UPDATE = 2
SphinxClient.SEARCHD_COMMAND_KEYWORDS = 3
SphinxClient.SEARCHD_COMMAND_PERSIST = 4
SphinxClient.SEARCHD_COMMAND_STATUS = 5
SphinxClient.SEARCHD_COMMAND_FLUSHATTRS = 7
// current client-side command implementation versions
SphinxClient.VER_COMMAND_SEARCH = 0x119
SphinxClient.VER_COMMAND_EXCERPT = 0x104
SphinxClient.VER_COMMAND_UPDATE = 0x102
SphinxClient.VER_COMMAND_KEYWORDS = 0x100
SphinxClient.VER_COMMAND_STATUS = 0x100
SphinxClient.VER_COMMAND_FLUSHATTRS = 0x100
// known searchd status codes
SphinxClient.SEARCHD_OK = 0
SphinxClient.SEARCHD_ERROR = 1
SphinxClient.SEARCHD_RETRY = 2
SphinxClient.SEARCHD_WARNING = 3
// known match modes
SphinxClient.SPH_MATCH_ALL = 0
SphinxClient.SPH_MATCH_ANY = 1
SphinxClient.SPH_MATCH_PHRASE = 2
SphinxClient.SPH_MATCH_BOOLEAN = 3
SphinxClient.SPH_MATCH_EXTENDED = 4
SphinxClient.SPH_MATCH_FULLSCAN = 5
SphinxClient.SPH_MATCH_EXTENDED2 = 6
// known ranking modes (extended2 mode only)
SphinxClient.SPH_RANK_PROXIMITY_BM25= 0 // default mode, phrase proximity major factor and BM25 minor one
SphinxClient.SPH_RANK_BM25 = 1 // statistical mode, BM25 ranking only (faster but worse quality)
SphinxClient.SPH_RANK_NONE = 2 // no ranking, all matches get a weight of 1
SphinxClient.SPH_RANK_WORDCOUNT = 3 // simple word-count weighting, rank is a weighted sum of per-field keyword occurence counts
SphinxClient.SPH_RANK_PROXIMITY = 4
SphinxClient.SPH_RANK_MATCHANY = 5
SphinxClient.SPH_RANK_FIELDMASK = 6
SphinxClient.SPH_RANK_SPH04 = 7
SphinxClient.SPH_RANK_EXPR = 8
SphinxClient.SPH_RANK_TOTAL = 9
// known sort modes
SphinxClient.SPH_SORT_RELEVANCE = 0
SphinxClient.SPH_SORT_ATTR_DESC = 1
SphinxClient.SPH_SORT_ATTR_ASC = 2
SphinxClient.SPH_SORT_TIME_SEGMENTS = 3
SphinxClient.SPH_SORT_EXTENDED = 4
SphinxClient.SPH_SORT_EXPR = 5
// known filter types
SphinxClient.SPH_FILTER_VALUES = 0
SphinxClient.SPH_FILTER_RANGE = 1
SphinxClient.SPH_FILTER_FLOATRANGE = 2
// known attribute types
SphinxClient.SPH_ATTR_NONE = 0
SphinxClient.SPH_ATTR_INTEGER = 1
SphinxClient.SPH_ATTR_TIMESTAMP = 2
SphinxClient.SPH_ATTR_ORDINAL = 3
SphinxClient.SPH_ATTR_BOOL = 4
SphinxClient.SPH_ATTR_FLOAT = 5
SphinxClient.SPH_ATTR_BIGINT = 6
SphinxClient.SPH_ATTR_STRING = 7
SphinxClient.SPH_ATTR_MULTI = 0x40000001
SphinxClient.SPH_ATTR_MULTI64 = 0x40000002
SphinxClient.SPH_ATTR_TYPES = [
SphinxClient.SPH_ATTR_NONE,
SphinxClient.SPH_ATTR_INTEGER,
SphinxClient.SPH_ATTR_TIMESTAMP,
SphinxClient.SPH_ATTR_ORDINAL,
SphinxClient.SPH_ATTR_BOOL,
SphinxClient.SPH_ATTR_FLOAT,
SphinxClient.SPH_ATTR_BIGINT,
SphinxClient.SPH_ATTR_STRING,
SphinxClient.SPH_ATTR_MULTI,
SphinxClient.SPH_ATTR_MULTI64
]
// known grouping functions
SphinxClient.SPH_GROUPBY_DAY = 0
SphinxClient.SPH_GROUPBY_WEEK = 1
SphinxClient.SPH_GROUPBY_MONTH = 2
SphinxClient.SPH_GROUPBY_YEAR = 3
SphinxClient.SPH_GROUPBY_ATTR = 4
SphinxClient.SPH_GROUPBY_ATTRPAIR = 5