[gnome-characters] searchProvider: Tighten up the search results
- From: Daiki Ueno <dueno src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-characters] searchProvider: Tighten up the search results
- Date: Mon, 8 Feb 2016 07:26:18 +0000 (UTC)
commit 1f1346d17673fa153bc62fe3dd72160940f0a65c
Author: Daiki Ueno <dueno src gnome org>
Date: Mon Feb 8 16:06:51 2016 +0900
searchProvider: Tighten up the search results
When search is invoked from the search provider, only show results which
match at the beginning of each word. This should reduce the number of
results so not to pollute the shell search screen.
Suggested by Michael Catanzaro.
lib/gc.c | 40 ++++++++++++++++++++++++++++++++++++----
lib/gc.h | 10 +++++++++-
src/characterList.js | 2 +-
src/searchProvider.js | 3 ++-
4 files changed, 48 insertions(+), 7 deletions(-)
---
diff --git a/lib/gc.c b/lib/gc.c
index b6bd9f2..9705ccc 100644
--- a/lib/gc.c
+++ b/lib/gc.c
@@ -106,6 +106,7 @@ struct GcCharacterIter
const uc_script_t * const * scripts;
uc_general_category_t category;
const gchar * const * keywords;
+ GcSearchFlag flags;
gboolean (* filter) (GcCharacterIter *iter, ucs4_t uc);
};
@@ -438,8 +439,24 @@ filter_keywords (GcCharacterIter *iter, ucs4_t uc)
return FALSE;
while (*keywords)
- if (g_strstr_len (buffer, UNINAME_MAX, *keywords++) == NULL)
- return FALSE;
+ {
+ const gchar *keyword = *keywords++;
+ size_t length = strlen (keyword);
+
+ if (length >= UNINAME_MAX)
+ return FALSE;
+
+ if (iter->flags & GC_SEARCH_FLAG_WORD)
+ {
+ if (strncmp (buffer, keyword, strlen (keyword)) != 0)
+ return FALSE;
+ }
+ else
+ {
+ if (g_strstr_len (buffer, UNINAME_MAX, keyword) == NULL)
+ return FALSE;
+ }
+ }
return TRUE;
}
@@ -657,6 +674,7 @@ struct _GcSearchContext
enum GcSearchState state;
GcCharacterIter iter;
GcSearchCriteria *criteria;
+ GcSearchFlag flags;
};
struct SearchData
@@ -882,6 +900,7 @@ gc_character_iter_init_for_related (GcCharacterIter *iter,
enum {
SEARCH_CONTEXT_PROP_0,
SEARCH_CONTEXT_PROP_CRITERIA,
+ SEARCH_CONTEXT_PROP_FLAGS,
SEARCH_CONTEXT_LAST_PROP
};
@@ -902,6 +921,9 @@ gc_search_context_set_property (GObject *object,
case SEARCH_CONTEXT_PROP_CRITERIA:
context->criteria = g_value_dup_boxed (value);
break;
+ case SEARCH_CONTEXT_PROP_FLAGS:
+ context->flags = g_value_get_flags (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -931,6 +953,11 @@ gc_search_context_class_init (GcSearchContextClass *klass)
g_param_spec_boxed ("criteria", NULL, NULL,
GC_TYPE_SEARCH_CRITERIA,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE);
+ search_context_props[SEARCH_CONTEXT_PROP_FLAGS] =
+ g_param_spec_flags ("flags", NULL, NULL,
+ GC_TYPE_SEARCH_FLAG,
+ GC_SEARCH_FLAG_NONE,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE);
g_object_class_install_properties (object_class, SEARCH_CONTEXT_LAST_PROP,
search_context_props);
}
@@ -942,9 +969,13 @@ gc_search_context_init (GcSearchContext *context)
}
GcSearchContext *
-gc_search_context_new (GcSearchCriteria *criteria)
+gc_search_context_new (GcSearchCriteria *criteria,
+ GcSearchFlag flags)
{
- return g_object_new (GC_TYPE_SEARCH_CONTEXT, "criteria", criteria, NULL);
+ return g_object_new (GC_TYPE_SEARCH_CONTEXT,
+ "criteria", criteria,
+ "flags", flags,
+ NULL);
}
static void
@@ -1051,6 +1082,7 @@ gc_search_context_search (GcSearchContext *context,
"search context destroyed");
return;
}
+ context->iter.flags = context->flags;
g_mutex_unlock (&context->lock);
data = g_slice_new0 (struct SearchData);
diff --git a/lib/gc.h b/lib/gc.h
index 96d3900..898e8c5 100644
--- a/lib/gc.h
+++ b/lib/gc.h
@@ -7,6 +7,7 @@
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <pango/pango.h>
+#include "gc-enumtypes.h"
G_BEGIN_DECLS
@@ -43,6 +44,12 @@ typedef enum
GC_SEARCH_ERROR_INVALID_STATE
} GcSearchError;
+typedef enum
+{
+ GC_SEARCH_FLAG_NONE = 0,
+ GC_SEARCH_FLAG_WORD = 1 << 0
+} GcSearchFlag;
+
#define GC_TYPE_SEARCH_CRITERIA (gc_search_criteria_get_type ())
typedef struct _GcSearchCriteria GcSearchCriteria;
@@ -71,7 +78,8 @@ GcSearchCriteria *gc_search_criteria_new_scripts
GcSearchCriteria *gc_search_criteria_new_related
(gunichar uc);
-GcSearchContext *gc_search_context_new (GcSearchCriteria *criteria);
+GcSearchContext *gc_search_context_new (GcSearchCriteria *criteria,
+ GcSearchFlag flags);
void gc_search_context_search
(GcSearchContext *context,
gint max_matches,
diff --git a/src/characterList.js b/src/characterList.js
index 24e06dc..a35d02d 100644
--- a/src/characterList.js
+++ b/src/characterList.js
@@ -504,7 +504,7 @@ const CharacterListView = new Lang.Class({
searchByKeywords: function(keywords) {
this._characters = [];
- let criteria = Gc.SearchCriteria.new_keywords(keywords);
+ let criteria = Gc.SearchCriteria.new_keywords(keywords, Gc.SearchFlag.NONE);
this._searchContext = new Gc.SearchContext({ criteria: criteria });
this._searchWithContext(this._searchContext, MAX_SEARCH_RESULTS);
},
diff --git a/src/searchProvider.js b/src/searchProvider.js
index 19781e1..92c4a2c 100644
--- a/src/searchProvider.js
+++ b/src/searchProvider.js
@@ -52,7 +52,8 @@ const SearchProvider = new Lang.Class({
let upper = keywords.map(String.toUpperCase);
let criteria = Gc.SearchCriteria.new_keywords(upper);
- let context = new Gc.SearchContext({ criteria: criteria });
+ let context = new Gc.SearchContext({ criteria: criteria,
+ flags: Gc.SearchFlag.WORD });
context.search(
MAX_SEARCH_RESULTS,
this._cancellable,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]