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"
17 main(int argc, char **argv)
19 struct image_vector query;
20 if (argc != IMAGE_VEC_K + 1)
21 die("Invalid number of arguments");
23 for (uns i = 0; i < IMAGE_VEC_K; i++)
26 if (sscanf(argv[i + 1], "%d", &v) != 1)
27 die("Invalid numeric format");
32 struct image_search is;
35 uns cardpos[BEST_CNT];
39 log(L_INFO, "Executing query (%s)", stk_print_image_vector(&query));
40 image_search_init(&is, &image_tree, &query, IMAGE_SEARCH_DIST_UNLIMITED);
41 for (uns i = 0; i < BEST_CNT; i++)
43 if (!image_search_next(&is, best + i, dist + i))
45 log(L_INFO, "No more images");
48 log(L_INFO, "*** Found %d. best image with oid=%d", i + 1, best[i]);
51 image_search_done(&is);
54 log(L_INFO, "Resolving URLs");
55 struct mempool *pool = mp_new(1 << 16);
56 struct buck2obj_buf *bob = buck2obj_alloc();
57 struct fastbuf *fb = bopen("index/card-attrs", O_RDONLY, 1 << 10);
58 for (uns i = 0; i < best_n; i++)
60 bsetpos(fb, best[i] * sizeof(struct card_attr));
62 bread(fb, &ca, sizeof(ca));
66 fb = bopen("index/cards", O_RDONLY, 1 << 14);
67 for (uns i = 0; i < best_n; i++)
69 bsetpos(fb, (sh_off_t)cardpos[i] << CARD_POS_SHIFT);
70 uns buck_len = bgetl(fb) - (LIZARD_COMPRESS_HEADER - 1);
71 uns buck_type = bgetc(fb) + BUCKET_TYPE_PLAIN;
73 struct odes *obj = obj_read_bucket(bob, pool, buck_type, buck_len, fb, NULL);
75 printf("%2d. match: dist=%-8d oid=%-8d url=%s\n", i + 1, dist[i], best[i],
76 obj_find_aval(obj_find_attr(obj, 'U' + OBJ_ATTR_SON)->son, 'U'));