NoiseFilter: Dont drop last word of apparent hostnames. Too many non-hostnames can...
[beagle.git] / libbeagle / beagle / beagle-query-part-wildcard.c
blob59b882dadaecbf12ce5859823f74779bc5dee3f9
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; -*- */
3 /*
4 * beagle-query-part-wildcard.c
6 * Copyright (C) 2005-2006 Novell, Inc.
8 */
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 * DEALINGS IN THE SOFTWARE.
30 #include <string.h>
32 #include "beagle-private.h"
33 #include "beagle-query-part.h"
34 #include "beagle-query-part-wildcard.h"
36 typedef struct {
37 const char *query_string;
38 } BeagleQueryPartWildcardPrivate;
40 #define BEAGLE_QUERY_PART_WILDCARD_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BEAGLE_TYPE_QUERY_PART_WILDCARD, BeagleQueryPartWildcardPrivate))
42 static GObjectClass *parent_class = NULL;
44 G_DEFINE_TYPE (BeagleQueryPartWildcard, beagle_query_part_wildcard, BEAGLE_TYPE_QUERY_PART)
46 static GString *
47 beagle_query_part_wildcard_to_xml (BeagleQueryPart *part)
49 BeagleQueryPartWildcardPrivate *priv = BEAGLE_QUERY_PART_WILDCARD_GET_PRIVATE (part);
50 GString *data = g_string_new (NULL);
52 _beagle_query_part_append_standard_header (data, part, "Wildcard");
54 g_string_append (data, "<QueryString>");
55 g_string_append (data, priv->query_string);
56 g_string_append (data, "</QueryString>");
58 _beagle_query_part_append_standard_footer (data);
60 return data;
63 static void
64 beagle_query_part_wildcard_finalize (GObject *obj)
66 if (G_OBJECT_CLASS (parent_class)->finalize)
67 G_OBJECT_CLASS (parent_class)->finalize (obj);
70 static void
71 beagle_query_part_wildcard_class_init (BeagleQueryPartWildcardClass *klass)
73 GObjectClass *obj_class = G_OBJECT_CLASS (klass);
74 BeagleQueryPartClass *query_part_class = BEAGLE_QUERY_PART_CLASS (klass);
76 parent_class = g_type_class_peek_parent (klass);
78 obj_class->finalize = beagle_query_part_wildcard_finalize;
79 query_part_class->to_xml = beagle_query_part_wildcard_to_xml;
81 g_type_class_add_private (klass, sizeof (BeagleQueryPartWildcardPrivate));
84 static void
85 beagle_query_part_wildcard_init (BeagleQueryPartWildcard *part)
89 BeagleQueryPartWildcard *
90 beagle_query_part_wildcard_new (void)
92 BeagleQueryPartWildcard *part = g_object_new (BEAGLE_TYPE_QUERY_PART_WILDCARD, 0);
93 return part;
96 /**
97 * beagle_query_part_wildcard_set_query_string:
98 * @part: a #BeagleQueryPartWildcard
99 * @query_string: a #const char *
101 * Sets the wildcard string to search for in a #BeagleQueryPartWildcard. The
102 * text should contain an asterisk (*) as the wildcard character, for matching
103 * zero or more items.
105 * While wildcards in the middle or end of a term are fine, using wildcards
106 * at the beginning of a term is strongly discouraged, as it cannot be
107 * efficiently done inside Lucene, the Beagle text indexer. It will cause
108 * a very large Lucene query to be built and will be very slow and could
109 * possibly cause a TooManyClauses exception inside Lucene. Try to avoid
110 * them whenever possible.
112 void
113 beagle_query_part_wildcard_set_query_string (BeagleQueryPartWildcard *part,
114 const char *query_string)
116 BeagleQueryPartWildcardPrivate *priv;
118 g_return_if_fail (BEAGLE_IS_QUERY_PART_WILDCARD (part));
119 g_return_if_fail (query_string != NULL);
121 priv = BEAGLE_QUERY_PART_WILDCARD_GET_PRIVATE (part);
122 priv->query_string = query_string;