Skip to content
This repository has been archived by the owner on Mar 28, 2019. It is now read-only.

SetFieldWeights broken, or am I using it incorrectly. #9

Open
gyaaniguy opened this issue May 21, 2013 · 5 comments
Open

SetFieldWeights broken, or am I using it incorrectly. #9

gyaaniguy opened this issue May 21, 2013 · 5 comments

Comments

@gyaaniguy
Copy link

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

@touv touv closed this as completed in 9dc31a2 May 21, 2013
@gyaaniguy
Copy link
Author

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.

  1. 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')
})
  1. I just removed pb and it started working.
req.push(pb.pack('>L', [len(field)])) 
to
req.push(pack('>L', [len(field)]))
  1. 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) );
}

@touv touv reopened this May 21, 2013
@touv
Copy link
Collaborator

touv commented May 21, 2013

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

@touv
Copy link
Collaborator

touv commented May 21, 2013

  1. fixed : c04cd57
  2. fixed : c8f7440
  3. fixed : adf486a

@touv touv closed this as completed May 21, 2013
@gyaaniguy
Copy link
Author

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);

@touv touv reopened this May 27, 2013
@touv
Copy link
Collaborator

touv commented May 27, 2013

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 ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants