2006-12-16 Gabor Kelemen <kelemeng@gnome.hu>
[beagle.git] / libbeagle / examples / beagle-search-provider.c
blob25fc807d3e39a671b69016027c74f702354ba1a7
1 #include <beagle/beagle.h>
2 #include <stdlib.h>
3 #include <time.h>
5 static void
6 test_indexer (BeagleClient *client)
8 BeagleIndexable *indexable;
9 BeagleProperty *prop1, *prop2, *prop3;
10 BeagleIndexingServiceRequest *request;
11 BeagleTimestamp *timestamp;
13 /* Use a unique URI for this indexable.
15 indexable = beagle_indexable_new ("mybackend:///foobar1");
17 /* We are adding an indexable.
18 * The other possibilities are
19 * Removing indexable - BEAGLE_INDEXABLE_TYPE_REMOVE
20 * Changing property of an indexable - BEAGLE_INDEXABLE_TYPE_PROPERTY_CHANGE
22 beagle_indexable_set_type (indexable, BEAGLE_INDEXABLE_TYPE_ADD);
24 /* No content means only properties will be indexed.
25 * No data is present for this indexable.
27 beagle_indexable_set_no_content (indexable, TRUE);
29 /* Set the source of this indexable.
30 * Use this to define the "backend" for this data.
32 beagle_indexable_set_source (indexable, "MyBackend");
34 /* Type of this indexable.
35 * One backend can produce indexables of various types.
36 * Different backends can generate indexables of same type
37 * e.g., different IM backends create indexables of type "Conversation"
39 beagle_indexable_set_hit_type (indexable, "MyType");
41 /* This indexable does not have any content, so do not try to filter its data.
43 beagle_indexable_set_filtering (indexable, BEAGLE_INDEXABLE_FILTERING_NEVER);
45 /* Create a custom property.
47 prop1 = beagle_property_new (BEAGLE_PROPERTY_TYPE_TEXT, "dc:title", "foo bar");
48 beagle_indexable_add_property (indexable, prop1);
50 prop2 = beagle_property_new (BEAGLE_PROPERTY_TYPE_TEXT, "dc:rights", "GPL");
51 beagle_indexable_add_property (indexable, prop2);
53 prop3 = beagle_property_new (BEAGLE_PROPERTY_TYPE_KEYWORD, "fixme:foo", "1234-4567-8900");
54 beagle_indexable_add_property (indexable, prop3);
56 /* Set timestamp.
58 timestamp = beagle_timestamp_new_from_unix_time (time (NULL));
59 beagle_indexable_set_timestamp (indexable, timestamp);
61 request = beagle_indexing_service_request_new_for_service ("IndexingServiceRequest");
62 beagle_indexing_service_request_add (request, indexable);
64 beagle_client_send_request (client, BEAGLE_REQUEST (request), NULL);
65 g_print ("Data sent to beagle search service.\n");
67 beagle_timestamp_free (timestamp);
68 beagle_property_free (prop1);
69 beagle_property_free (prop2);
70 beagle_property_free (prop3);
74 int
75 main ()
77 BeagleClient *client;
79 g_type_init ();
81 if (! beagle_util_daemon_is_running ()) {
82 g_print ("beagle search service is not running.\n");
83 return 1;
86 client = beagle_client_new (NULL);
88 g_print ("Sending data to beagle search service\n");
89 test_indexer (client);
91 return 0;