Skip to content

Commit

Permalink
Fixed attribute filters in query
Browse files Browse the repository at this point in the history
  • Loading branch information
kurokikaze committed Jan 13, 2012
1 parent 795d9cf commit 9688a08
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions limestone.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ exports.SphinxClient = function() {

initResponseOutput(callback);

// Default query parameters
var query_parameters = {
offset : 0,
limit : 20,
Expand Down Expand Up @@ -258,7 +259,7 @@ exports.SphinxClient = function() {
} */

var request = Buffer.makeWriter();
request.push.int16(Sphinx.command.SEARCH);
request.push.int16(Sphinx.command.SEARCH);
request.push.int16(Sphinx.clientCommand.SEARCH);

request.push.int32(0); // This will be request length
Expand All @@ -283,24 +284,33 @@ exports.SphinxClient = function() {

request.push.lstring(query.indexes); // Indexes used JEZ

request.push.int32(1); // id64 range marker
request.push.int32(1); // id64 range marker

//request.push.int32(0);
request.push.int64(0, query.min_id); // This is actually supposed to be two 64-bit numbers
//request.push.int32(0); // However, there is a caveat about using 64-bit ids
request.push.int64(0, query.max_id);

//console.log('Found ' + query.filters.length + ' filters');
request.push.int32(query.filters.length);
for (var filter in query.filters) {
request.push.int32(filter.attr.length);
for (var filter_id in query.filters) {
var filter = query.filters[filter_id];
//console.log('Found filter of type ' + filter.type)
if (!filter.attr) {
filter.attr = "";
}
if (!filter.exclude) {
filter.exclude = 0;
}
//request.push.int32(filter.attr.length);//WTF? length is included in lstring
request.push.lstring(filter.attr);
request.push.int32(filter.type);
switch (filter.type) {
case Sphinx.filterTypes.VALUES:
request.push.int32(filter.values.length);
for (var value in filter.values) {
request.push.int32(filter.values.length); // Count of values
for (var value_id in filter.values) {
//request.push.int32(0); // should be a 64-bit number
request.push.int64(0, value);
request.push.int64(0, filter.values[value_id]);
}
break;
case Sphinx.filterTypes.RANGE:
Expand All @@ -314,6 +324,7 @@ exports.SphinxClient = function() {
request.push.float(filter.max);
break;
}
request.push.int32(filter.exclude);
}

request.push.int32(query_parameters.groupfunc);
Expand Down Expand Up @@ -383,7 +394,7 @@ exports.SphinxClient = function() {
req_length.push.int32(request_buf.length - 8);
req_length.toBuffer().copy(request_buf, 4, 0);

console.log('Sending search request of ' + request_buf.length + ' bytes');
//console.log('Sending search request of ' + request_buf.length + ' bytes');

server_conn.write(request_buf);
// we also add the command to the search_commands queue
Expand Down Expand Up @@ -475,7 +486,7 @@ exports.SphinxClient = function() {
req_length.push.int32(request_buf.length - 8);
req_length.toBuffer().copy(request_buf,4,0);

console.log('Sending build excerpt request of ' + request_buf.length + 'bytes');
//console.log('Sending build excerpt request of ' + request_buf.length + 'bytes');

server_conn.write(request_buf);
// we also add the command to the search_commands queue
Expand Down

0 comments on commit 9688a08

Please sign in to comment.