Skip to content

Commit

Permalink
pass query filter to query
Browse files Browse the repository at this point in the history
  • Loading branch information
sspathare97 committed Nov 24, 2022
1 parent c7ed825 commit 5c49bc6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/giggle_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -1288,12 +1288,21 @@ struct giggle_index *giggle_load_with_metadata(char *data_dir,
}
//}}}

//{{{struct giggle_query_result *giggle_query(struct giggle_index *gi,
struct giggle_query_result *giggle_query(struct giggle_index *gi,
char *chrm,
uint32_t start,
uint32_t end,
struct giggle_query_result *_gqr)
{
return giggle_query_with_query_filter(gi, chrm, start, end, NULL, _gqr);
}

struct giggle_query_result *giggle_query_with_query_filter(struct giggle_index *gi,
char *chrm,
uint32_t start,
uint32_t end,
struct query_filter *query_filter,
struct giggle_query_result *_gqr)
{
#if GIGGLE_QUERY_TRACE
fprintf(stderr, "giggle_query\t%s\t%u\t%u\n", chrm, start, end);
Expand Down
8 changes: 8 additions & 0 deletions src/giggle_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "pq.h"
#include "offset_index.h"
#include "metadata_index.h"
#include "query_filter.h"

#define PROGRAM_NAME "giggle"
#define MAJOR_VERSION "0"
Expand Down Expand Up @@ -88,6 +89,13 @@ struct giggle_query_result *giggle_query(struct giggle_index *gi,
uint32_t end,
struct giggle_query_result *gqr);

struct giggle_query_result *giggle_query_with_query_filter(struct giggle_index *gi,
char *chrm,
uint32_t start,
uint32_t end,
struct query_filter *query_filter,
struct giggle_query_result *gqr);

void giggle_query_result_destroy(struct giggle_query_result **gqr);

struct giggle_query_iter
Expand Down
12 changes: 10 additions & 2 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,12 @@ int search_main(int argc, char **argv, char *full_cmd)
if (gi == NULL)
errx(1, "Error loading giggle index %s.", index_dir_name);

struct query_filter *query_filter = NULL;
if (query_filter_string != NULL) {
query_filter = parse_query_filter_string(gi->metadata_idx, query_filter_string);
// print_query_filter(query_filter);
}

struct giggle_query_result *gqr = NULL;

uint32_t num_intervals = 0;
Expand All @@ -432,7 +438,7 @@ int search_main(int argc, char **argv, char *full_cmd)
char *region;
ret = asprintf(&region, "%s", regions + last);
if (parse_region(region, &chrm, &start, &end) == 0) {
gqr = giggle_query(gi, chrm, start, end, gqr);
gqr = giggle_query_with_query_filter(gi, chrm, start, end, query_filter, gqr);
free(region);
} else {
errx(EX_USAGE,
Expand Down Expand Up @@ -463,7 +469,7 @@ int search_main(int argc, char **argv, char *full_cmd)
&end,
&offset,
&line) >= 0 ) {
gqr = giggle_query(gi, chrm, start, end, gqr);
gqr = giggle_query_with_query_filter(gi, chrm, start, end, query_filter, gqr);
if ( (o_is_set == 1) && (gqr->num_hits > 0) ) {
char *str;
input_file_get_curr_line_bgzf(q_f, &str);
Expand Down Expand Up @@ -513,6 +519,8 @@ int search_main(int argc, char **argv, char *full_cmd)
o_is_set);

giggle_query_result_destroy(&gqr);
if (query_filter)
query_filter_destroy(query_filter);
giggle_index_destroy(&gi);
cache.destroy();
free(full_cmd);
Expand Down

0 comments on commit 5c49bc6

Please sign in to comment.