nostrdb/filter: rename FILTER_GENERIC to FILTER_TAG

it's a bit more intuitive

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-01-05 20:45:02 -08:00
committed by Daniel D’Aquino
parent 206efba58a
commit 77601e77ee
2 changed files with 19 additions and 19 deletions

View File

@@ -529,7 +529,7 @@ static const char *ndb_filter_field_name(enum ndb_filter_fieldtype field)
case NDB_FILTER_IDS: return "ids"; case NDB_FILTER_IDS: return "ids";
case NDB_FILTER_AUTHORS: return "authors"; case NDB_FILTER_AUTHORS: return "authors";
case NDB_FILTER_KINDS: return "kinds"; case NDB_FILTER_KINDS: return "kinds";
case NDB_FILTER_GENERIC: return "generic"; case NDB_FILTER_TAGS: return "tags";
case NDB_FILTER_SINCE: return "since"; case NDB_FILTER_SINCE: return "since";
case NDB_FILTER_UNTIL: return "until"; case NDB_FILTER_UNTIL: return "until";
case NDB_FILTER_LIMIT: return "limit"; case NDB_FILTER_LIMIT: return "limit";
@@ -538,7 +538,7 @@ static const char *ndb_filter_field_name(enum ndb_filter_fieldtype field)
return "unknown"; return "unknown";
} }
static int ndb_filter_start_field_impl(struct ndb_filter *filter, enum ndb_filter_fieldtype field, char generic) static int ndb_filter_start_field_impl(struct ndb_filter *filter, enum ndb_filter_fieldtype field, char tag)
{ {
int i; int i;
struct ndb_filter_elements *els, *el; struct ndb_filter_elements *els, *el;
@@ -569,7 +569,7 @@ static int ndb_filter_start_field_impl(struct ndb_filter *filter, enum ndb_filte
} }
els->field.type = field; els->field.type = field;
els->field.generic = generic; els->field.tag = tag;
els->field.elem_type = 0; els->field.elem_type = 0;
els->count = 0; els->count = 0;
@@ -581,9 +581,9 @@ int ndb_filter_start_field(struct ndb_filter *filter, enum ndb_filter_fieldtype
return ndb_filter_start_field_impl(filter, field, 0); return ndb_filter_start_field_impl(filter, field, 0);
} }
int ndb_filter_start_generic_field(struct ndb_filter *filter, char tag) int ndb_filter_start_tag_field(struct ndb_filter *filter, char tag)
{ {
return ndb_filter_start_field_impl(filter, NDB_FILTER_GENERIC, tag); return ndb_filter_start_field_impl(filter, NDB_FILTER_TAGS, tag);
} }
static int ndb_filter_add_element(struct ndb_filter *filter, union ndb_filter_element el) static int ndb_filter_add_element(struct ndb_filter *filter, union ndb_filter_element el)
@@ -612,7 +612,7 @@ static int ndb_filter_add_element(struct ndb_filter *filter, union ndb_filter_el
if (filter->current->count != 0) if (filter->current->count != 0)
return 0; return 0;
break; break;
case NDB_FILTER_GENERIC: case NDB_FILTER_TAGS:
str = (const char *)filter->data_buf.p; str = (const char *)filter->data_buf.p;
if (!cursor_push_c_str(&filter->data_buf, el.string)) if (!cursor_push_c_str(&filter->data_buf, el.string))
return 0; return 0;
@@ -666,7 +666,7 @@ int ndb_filter_add_str_element(struct ndb_filter *filter, const char *str)
case NDB_FILTER_AUTHORS: case NDB_FILTER_AUTHORS:
case NDB_FILTER_KINDS: case NDB_FILTER_KINDS:
return 0; return 0;
case NDB_FILTER_GENERIC: case NDB_FILTER_TAGS:
break; break;
} }
@@ -686,7 +686,7 @@ int ndb_filter_add_int_element(struct ndb_filter *filter, uint64_t integer)
switch (filter->current->field.type) { switch (filter->current->field.type) {
case NDB_FILTER_IDS: case NDB_FILTER_IDS:
case NDB_FILTER_AUTHORS: case NDB_FILTER_AUTHORS:
case NDB_FILTER_GENERIC: case NDB_FILTER_TAGS:
return 0; return 0;
case NDB_FILTER_KINDS: case NDB_FILTER_KINDS:
case NDB_FILTER_SINCE: case NDB_FILTER_SINCE:
@@ -716,7 +716,7 @@ int ndb_filter_add_id_element(struct ndb_filter *filter, const unsigned char *id
return 0; return 0;
case NDB_FILTER_IDS: case NDB_FILTER_IDS:
case NDB_FILTER_AUTHORS: case NDB_FILTER_AUTHORS:
case NDB_FILTER_GENERIC: case NDB_FILTER_TAGS:
break; break;
} }
@@ -729,8 +729,8 @@ int ndb_filter_add_id_element(struct ndb_filter *filter, const unsigned char *id
return ndb_filter_add_element(filter, el); return ndb_filter_add_element(filter, el);
} }
static int ndb_generic_filter_matches(struct ndb_filter_elements *els, static int ndb_tag_filter_matches(struct ndb_filter_elements *els,
struct ndb_note *note) struct ndb_note *note)
{ {
int i; int i;
union ndb_filter_element el; union ndb_filter_element el;
@@ -751,7 +751,7 @@ static int ndb_generic_filter_matches(struct ndb_filter_elements *els,
continue; continue;
// do we have #e matching e (or p, etc) // do we have #e matching e (or p, etc)
if (str.str[0] != els->field.generic || str.str[1] != 0) if (str.str[0] != els->field.tag || str.str[1] != 0)
continue; continue;
str = ndb_tag_str(note, it->tag, 1); str = ndb_tag_str(note, it->tag, 1);
@@ -774,7 +774,7 @@ static int ndb_generic_filter_matches(struct ndb_filter_elements *els,
// For some reason the element type is not set. It's // For some reason the element type is not set. It's
// possible nothing was added to the generic filter? // possible nothing was added to the generic filter?
// Let's just fail here and log a note for debugging // Let's just fail here and log a note for debugging
fprintf(stderr, "UNUSUAL ndb_generic_filter_matches: have unknown element type %d\n", els->field.elem_type); fprintf(stderr, "UNUSUAL ndb_tag_filter_matches: have unknown element type %d\n", els->field.elem_type);
return 0; return 0;
} }
@@ -860,8 +860,8 @@ static int ndb_filter_matches_with(struct ndb_filter *filter,
continue; continue;
} }
break; break;
case NDB_FILTER_GENERIC: case NDB_FILTER_TAGS:
if (ndb_generic_filter_matches(els, note)) if (ndb_tag_filter_matches(els, note))
continue; continue;
break; break;
case NDB_FILTER_SINCE: case NDB_FILTER_SINCE:
@@ -908,7 +908,7 @@ void ndb_filter_end_field(struct ndb_filter *filter)
qsort(&cur->elements[0], cur->count, qsort(&cur->elements[0], cur->count,
sizeof(cur->elements[0].integer), compare_kinds); sizeof(cur->elements[0].integer), compare_kinds);
break; break;
case NDB_FILTER_GENERIC: case NDB_FILTER_TAGS:
// TODO: generic tag search sorting // TODO: generic tag search sorting
break; break;
case NDB_FILTER_SINCE: case NDB_FILTER_SINCE:

View File

@@ -138,7 +138,7 @@ enum ndb_filter_fieldtype {
NDB_FILTER_IDS = 1, NDB_FILTER_IDS = 1,
NDB_FILTER_AUTHORS = 2, NDB_FILTER_AUTHORS = 2,
NDB_FILTER_KINDS = 3, NDB_FILTER_KINDS = 3,
NDB_FILTER_GENERIC = 4, NDB_FILTER_TAGS = 4,
NDB_FILTER_SINCE = 5, NDB_FILTER_SINCE = 5,
NDB_FILTER_UNTIL = 6, NDB_FILTER_UNTIL = 6,
NDB_FILTER_LIMIT = 7, NDB_FILTER_LIMIT = 7,
@@ -220,7 +220,7 @@ union ndb_filter_element {
struct ndb_filter_field { struct ndb_filter_field {
enum ndb_filter_fieldtype type; enum ndb_filter_fieldtype type;
enum ndb_generic_element_type elem_type; enum ndb_generic_element_type elem_type;
char generic; // for generic queries like #t char tag; // for generic queries like #t
}; };
struct ndb_filter_elements { struct ndb_filter_elements {
@@ -461,7 +461,7 @@ int ndb_filter_add_id_element(struct ndb_filter *, const unsigned char *id);
int ndb_filter_add_int_element(struct ndb_filter *, uint64_t integer); int ndb_filter_add_int_element(struct ndb_filter *, uint64_t integer);
int ndb_filter_add_str_element(struct ndb_filter *, const char *str); int ndb_filter_add_str_element(struct ndb_filter *, const char *str);
int ndb_filter_start_field(struct ndb_filter *, enum ndb_filter_fieldtype); int ndb_filter_start_field(struct ndb_filter *, enum ndb_filter_fieldtype);
int ndb_filter_start_generic_field(struct ndb_filter *, char tag); int ndb_filter_start_tag_field(struct ndb_filter *, char tag);
int ndb_filter_matches(struct ndb_filter *, struct ndb_note *); int ndb_filter_matches(struct ndb_filter *, struct ndb_note *);
void ndb_filter_reset(struct ndb_filter *); void ndb_filter_reset(struct ndb_filter *);
void ndb_filter_end_field(struct ndb_filter *); void ndb_filter_end_field(struct ndb_filter *);