static gboolean
rejilla_search_beagle_set_query_mime (RejillaSearchEngine *search,
                                      const gchar **mimes)
{
	int i;
	BeagleQueryPartOr *or_part;
	RejillaSearchBeaglePrivate *priv;

	priv = REJILLA_SEARCH_BEAGLE_PRIVATE (search);

	if (!priv->query)
		return FALSE;

	or_part = beagle_query_part_or_new ();
	for (i = 0; mimes [i]; i ++) {
		BeagleQueryPartProperty *filetype;

		filetype = beagle_query_part_property_new ();
		beagle_query_part_property_set_property_type (filetype, BEAGLE_PROPERTY_TYPE_KEYWORD);
		beagle_query_part_property_set_key (filetype, "beagle:MimeType");
		beagle_query_part_property_set_value (filetype, mimes [i]);
		beagle_query_part_or_add_subpart (or_part, BEAGLE_QUERY_PART (filetype));
	}

	beagle_query_add_part (priv->query, BEAGLE_QUERY_PART (or_part));

	return TRUE;
}
static gboolean
rejilla_search_beagle_query_new (RejillaSearchEngine *search,
				 const gchar *keywords)
{
	RejillaSearchBeaglePrivate *priv;
	BeagleQueryPartHuman *text;

	priv = REJILLA_SEARCH_BEAGLE_PRIVATE (search);

	rejilla_search_beagle_clean (REJILLA_SEARCH_BEAGLE (search));
	priv->query = beagle_query_new ();

	if (keywords) {
		BeagleQueryPartHuman *text;

		text = beagle_query_part_human_new ();
		beagle_query_part_human_set_string (text, keywords);
		beagle_query_part_set_logic (BEAGLE_QUERY_PART (text),
					     BEAGLE_QUERY_PART_LOGIC_REQUIRED);

		beagle_query_add_part (priv->query, BEAGLE_QUERY_PART (text));
	}

	text = beagle_query_part_human_new ();
	beagle_query_part_human_set_string (text, "type:File");
	beagle_query_add_part (priv->query, BEAGLE_QUERY_PART (text));

	return TRUE;
}
static GString *
beagle_query_part_or_to_xml (BeagleQueryPart *part)
{
	BeagleQueryPartOrPrivate *priv = BEAGLE_QUERY_PART_OR_GET_PRIVATE (part);    
	GString *data = g_string_new (NULL);
	GSList *iter;
	
	_beagle_query_part_append_standard_header (data, part, "Or");

	g_string_append (data, "<SubParts>");

	for (iter = priv->subparts; iter != NULL; iter = iter->next) {
		BeagleQueryPart *subpart = BEAGLE_QUERY_PART (iter->data);
		GString *sub_data;

		sub_data = _beagle_query_part_to_xml (subpart);
		g_string_append_len (data, sub_data->str, sub_data->len);
		g_string_free (sub_data, TRUE);
	}

	g_string_append (data, "</SubParts>");
	
	_beagle_query_part_append_standard_footer (data);
	
	return data;
}
static gboolean
rejilla_search_beagle_query_set_scope (RejillaSearchEngine *search,
                                       RejillaSearchScope scope)
{
	BeagleQueryPartOr *or_part = NULL;
	RejillaSearchBeaglePrivate *priv;

	priv = REJILLA_SEARCH_BEAGLE_PRIVATE (search);

	if (!priv->query)
		return FALSE;

	if (scope & REJILLA_SEARCH_SCOPE_DOCUMENTS) {
		BeagleQueryPartProperty *filetype;

		if (!or_part)
			or_part = beagle_query_part_or_new ();

		filetype = beagle_query_part_property_new ();
		beagle_query_part_property_set_property_type (filetype, BEAGLE_PROPERTY_TYPE_KEYWORD);
		beagle_query_part_property_set_key (filetype, "beagle:FileType");
		beagle_query_part_property_set_value (filetype, "document");
		beagle_query_part_or_add_subpart (or_part, BEAGLE_QUERY_PART (filetype));
	}

	if (scope & REJILLA_SEARCH_SCOPE_PICTURES) {
		BeagleQueryPartProperty *filetype;

		if (!or_part)
			or_part = beagle_query_part_or_new ();

		filetype = beagle_query_part_property_new ();
		beagle_query_part_property_set_property_type (filetype, BEAGLE_PROPERTY_TYPE_KEYWORD);
		beagle_query_part_property_set_key (filetype, "beagle:FileType");
		beagle_query_part_property_set_value (filetype, "image");
		beagle_query_part_or_add_subpart (or_part, BEAGLE_QUERY_PART (filetype));
	}

	if (scope & REJILLA_SEARCH_SCOPE_MUSIC) {
		BeagleQueryPartProperty *filetype;

		if (!or_part)
			or_part = beagle_query_part_or_new ();

		filetype = beagle_query_part_property_new ();
		beagle_query_part_property_set_property_type (filetype, BEAGLE_PROPERTY_TYPE_KEYWORD);
		beagle_query_part_property_set_key (filetype, "beagle:FileType");
		beagle_query_part_property_set_value (filetype, "audio");
		beagle_query_part_or_add_subpart (or_part, BEAGLE_QUERY_PART (filetype));
	}

	if (scope & REJILLA_SEARCH_SCOPE_VIDEO) {
		BeagleQueryPartProperty *filetype;

		if (!or_part)
			or_part = beagle_query_part_or_new ();

		filetype = beagle_query_part_property_new ();
		beagle_query_part_property_set_property_type (filetype, BEAGLE_PROPERTY_TYPE_KEYWORD);
		beagle_query_part_property_set_key (filetype, "beagle:FileType");
		beagle_query_part_property_set_value (filetype, "video");
		beagle_query_part_or_add_subpart (or_part, BEAGLE_QUERY_PART (filetype));
	}

	if (!or_part)
		return FALSE;

	beagle_query_add_part (priv->query, BEAGLE_QUERY_PART (or_part));
	return TRUE;
}