SetFieldWeights broken, or am I using it incorrectly.
gyaaniguy opened this issue · 5 comments
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
Hey thanks for the quick response! But
There are a few of more changes I had to make to make this work: BUT i am no expert! and wasn't exactly sure with every change.
- The following change is assuming that the value(in the passed object) should be a number.
forEach(weights, function (item, index) {
assert.equal(typeof item, 'number')
})
Should be
forEach(weights, function (item, index) {
assert.equal(typeof index, 'number')
})
- I just removed pb and it started working.
req.push(pb.pack('>L', [len(field)]))
to
req.push(pack('>L', [len(field)]))
- This one I am sure of , obj should be o.
for(k in o) {
l += Number( obj.hasOwnProperty(k) );
}
TO
for(k in o) {
l += Number( o.hasOwnProperty(k) );
}
you found an mistake in the foreach wrapper... I inverted the arguments of the callback.
I 'll fix all the bugs as soon as possible
EDIT: SORRY! I was wrong , it is working. Just that the results are not in the order that I expected.
I hate being a bother, but I think it still could be broken. SetFieldWeights doesn't seem to have any effect. Could you please look into this .
Thanks
Here's my code btw:
var searchQuery = '' + str;
cl.SetServer('localhost', sphinxPort);
cl.SetFieldWeights({
tagds: 15000,
qdt: 30000,
dqb: 1
});
cl.SetMatchMode(SphinxClient.SPH_MATCH_EXTENDED);
Sorry, I forgot to change a line. it was fixed with this commit : b3ca39e.
I also wrote a little test to compare an search and the same search with different weights
https://github.com/touv/node-sphinxapi-test/blob/master/query.js
https://github.com/touv/node-sphinxapi-test/blob/master/setfieldsweights.js
I compare the result with NodeJS's API and the official PHP's API. It looks the same.
https://github.com/touv/node-sphinxapi-test/blob/master/query.php
https://github.com/touv/node-sphinxapi-test/blob/master/setfieldsweights.php
Tell me, if I can close this issue ?