3 #include "sherlock/sherlock.h"
4 #include "lib/fastbuf.h"
5 #include "images/images.h"
6 #include "images/image-search.h"
7 #include "sherlock/index.h"
8 #include "lib/mempool.h"
9 #include "sherlock/object.h"
10 #include "sherlock/lizard-fb.h"
11 #include "sherlock/lizard-fb.h"
18 main(int argc, char **argv)
20 struct image_vector query;
21 if (argc != IMAGE_VEC_K + 1)
22 die("Invalid number of arguments");
24 for (uns i = 0; i < IMAGE_VEC_K; i++)
27 if (sscanf(argv[i + 1], "%d", &v) != 1)
28 die("Invalid numeric format");
33 struct image_search is;
36 uns cardpos[BEST_CNT];
40 log(L_INFO, "Executing query (%s)", stk_print_image_vector(&query));
41 image_search_init(&is, &image_tree, &query, IMAGE_SEARCH_DIST_UNLIMITED);
42 for (uns i = 0; i < BEST_CNT; i++)
44 if (!image_search_next(&is, best + i, dist + i))
46 log(L_INFO, "No more images");
49 log(L_INFO, "*** Found %d. best image with oid=%d", i + 1, best[i]);
52 image_search_done(&is);
55 log(L_INFO, "Resolving URLs");
56 struct mempool *pool = mp_new(1 << 16);
57 struct buck2obj_buf *bob = buck2obj_alloc();
58 struct fastbuf *fb = bopen("index/card-attrs", O_RDONLY, 1 << 10);
59 for (uns i = 0; i < best_n; i++)
61 bsetpos(fb, best[i] * sizeof(struct card_attr));
63 bread(fb, &ca, sizeof(ca));
67 fb = bopen("index/cards", O_RDONLY, 1 << 14);
68 for (uns i = 0; i < best_n; i++)
70 bsetpos(fb, (sh_off_t)cardpos[i] << CARD_POS_SHIFT);
71 uns buck_len = bgetl(fb) - (LIZARD_COMPRESS_HEADER - 1);
72 uns buck_type = bgetc(fb) + BUCKET_TYPE_PLAIN;
74 struct odes *obj = obj_read_bucket(bob, pool, buck_type, buck_len, fb, NULL);
76 printf("%2d. match: dist=%-8d oid=%-8d url=%s\n", i + 1, dist[i], best[i],
77 obj_find_aval(obj_find_attr(obj, 'U' + OBJ_ATTR_SON)->son, 'U'));