Skip to content

Commit

Permalink
Revert "Revert "Adding AND matching to queries""
Browse files Browse the repository at this point in the history
This reverts commit 00bcdbf.
  • Loading branch information
winton committed Dec 13, 2011
1 parent 00bcdbf commit 2643a7b
Showing 1 changed file with 34 additions and 28 deletions.
62 changes: 34 additions & 28 deletions redis_parse.c
Expand Up @@ -220,7 +220,7 @@ bool limit_reached(struct query *q) {
}

void process_record(char *record, int score) {
bool match;
bool exclude, match;
char *field;
char **fields;
fields = to_fields(record);
Expand All @@ -231,45 +231,51 @@ void process_record(char *record, int score) {
// Skip unused query structs
if (queries[q].used != true)
continue;

// Skip if score not within range
if (score >= 0) {
if (queries[q].finish >= 0 && score > queries[q].finish)
continue;
if (queries[q].start >= 0 && score < queries[q].start)
continue;
}

// For each column
match = true;
for (x = 0; x < columns_count; x++) {
match = (
// exclude matches
(
queries[q].exclude_empty ||
queries[q].exclude_empty_at[x] ||
!strstr(fields[x], queries[q].exclude[x])
// include matches
) && (
queries[q].query_empty ||
(
!queries[q].query_empty_at[x] &&
strstr(fields[x], queries[q].query[x])
)
)
// Exclude matches
exclude = (
!queries[q].exclude_empty &&
!queries[q].exclude_empty_at[x] &&
strstr(fields[x], queries[q].exclude[x])
);
if (match) {
if (queries[q].display_count)
queries[q].count++;
if (queries[q].display_group && queries[q].column > -1) {
field = malloc(strlen(fields[queries[q].column]) + 1);
strcpy(field, fields[queries[q].column]);
if (queries[q].column == 2) { // tag
hash_add_or_update(q, xstrtok(field, ","));
while (hash_add_or_update(q, xstrtok(NULL, ",")));
} else
hash_add_or_update(q, field);
}
if (exclude) {
match = false;
break;
}
if (queries[q].query_empty)
break;
// Include matches
if (!queries[q].query_empty_at[x] && !strstr(fields[x], queries[q].query[x])) {
match = false;
break;
}
}
}

if (match) {
if (queries[q].display_count)
queries[q].count++;
if (queries[q].display_group && queries[q].column > -1) {
field = malloc(strlen(fields[queries[q].column]) + 1);
strcpy(field, fields[queries[q].column]);
if (queries[q].column == 2) { // tag
hash_add_or_update(q, xstrtok(field, ","));
while (hash_add_or_update(q, xstrtok(NULL, ",")));
} else
hash_add_or_update(q, field);
}
break;
}
}

free(fields);
Expand Down

0 comments on commit 2643a7b

Please sign in to comment.