4 #include <beagle/beagle.h>
9 print_feed_item_hit (BeagleHit
*hit
)
13 if (beagle_hit_get_one_property (hit
, "dc:title", &text
))
14 g_print ("Blog: %s\n", text
);
18 print_file_hit (BeagleHit
*hit
)
20 g_print ("File: %s\n", beagle_hit_get_uri (hit
));
24 print_other_hit (BeagleHit
*hit
)
26 g_print ("%s (%s)", beagle_hit_get_uri (hit
),
27 beagle_hit_get_source (hit
));
31 print_hit (BeagleHit
*hit
)
33 if (strcmp (beagle_hit_get_type (hit
), "FeedItem") == 0) {
34 print_feed_item_hit (hit
);
36 else if (strcmp (beagle_hit_get_type (hit
), "File") == 0) {
39 print_other_hit (hit
);
44 hits_added_cb (BeagleQuery
*query
, BeagleHitsAddedResponse
*response
)
51 hits
= beagle_hits_added_response_get_hits (response
);
52 total_matches
= beagle_hits_added_response_get_num_matches (response
);
54 nr_hits
= g_slist_length (hits
);
55 total_hits
+= nr_hits
;
56 g_print ("Found hits (%d) out of total %d matches:\n", nr_hits
, total_matches
);
57 g_print ("-------------------------------------------\n");
58 for (l
= hits
, i
= 1; l
; l
= l
->next
, ++i
) {
61 print_hit (BEAGLE_HIT (l
->data
));
65 g_print ("-------------------------------------------\n\n\n");
69 finished_cb (BeagleQuery
*query
,
70 BeagleFinishedResponse
*response
,
73 g_main_loop_quit (main_loop
);
77 main (int argc
, char **argv
)
85 g_print ("Usage %s \"query string\"\n", argv
[0]);
93 client
= beagle_client_new (NULL
);
95 main_loop
= g_main_loop_new (NULL
, FALSE
);
97 query
= beagle_query_new ();
99 for (i
= 1; i
< argc
; ++i
) {
100 beagle_query_add_text (query
, argv
[i
]);
103 g_signal_connect (query
, "hits-added",
104 G_CALLBACK (hits_added_cb
),
107 g_signal_connect (query
, "finished",
108 G_CALLBACK (finished_cb
),
111 beagle_client_send_request_async (client
, BEAGLE_REQUEST (query
),
114 g_main_loop_run (main_loop
);
115 g_object_unref (query
);
116 g_object_unref (client
);
117 g_main_loop_unref (main_loop
);
119 g_print ("Found a total of %d hits\n", total_hits
);