Index: src/yelp-search-pager.c
===================================================================
RCS file: /cvs/gnome/yelp/src/yelp-search-pager.c,v
retrieving revision 1.25
diff -u -r1.25 yelp-search-pager.c
--- src/yelp-search-pager.c	28 May 2006 18:32:24 -0000	1.25
+++ src/yelp-search-pager.c	7 Jun 2006 21:35:49 -0000
@@ -106,6 +106,8 @@
     GHashTable  *entities;
     gchar **     search_term;
     gboolean *   found_terms;
+    gboolean *   stop_word;
+    gfloat *       score_per_word;
     gchar *      top_element;
     gint         search_status;
     gchar *      elem_type;
@@ -938,7 +940,7 @@
 {
     SearchContainer *c = (SearchContainer *) data;
 
-    if (g_str_equal (name, "xi:include")) {
+    if (g_str_equal (name, "xi:include") || g_str_equal (name, "include")) {
 	gint i=0;
 	while (attrs[i]) {
 	    if (g_str_equal (attrs[i], "href")) {
@@ -1020,11 +1022,12 @@
 	gchar *tmp = g_utf8_casefold ((gchar *) ch, len);
 	gint i = 0;
 	gchar *s_term = c->search_term[i];
-	while (s_term && !c->found_terms[i]) {
+	while (s_term && c->score_per_word[i] < 1.0) {
 	    gchar *location = strstr (tmp, s_term);
-	    if (location) {
+	    if (location && !c->stop_word[i]) {
 		gchar before = *(location-1);
 		gchar after = *(location+strlen(s_term));
+		gfloat local_score = 0.0;
 		if (location == tmp)
 		    before = ' ';
 		if (strlen(location) == strlen(s_term))
@@ -1033,23 +1036,27 @@
 		if ((g_ascii_ispunct (before) || g_ascii_isspace (before)) 
 		    && (g_ascii_ispunct (after) || g_ascii_isspace (after))) {
 
-		    c->result_found = TRUE;
-		    if (!c->snippet) {
-			c->snippet = g_strndup (g_utf8_casefold ((gchar *) ch,
-								 len), 
-						len);
-			c->result_subsection = g_strdup (c->current_subsection);
-		    }
-		    c->found_terms[i] = TRUE;
 		    if (g_str_equal(c->elem_type, "primary")) {
-			c->score += 1.0;
+			local_score = 1.0;
 		    } else if (g_str_equal (c->elem_type, "secondary")) {
-			c->score += 0.9;
+			local_score = 0.9;
 		    } else if (g_str_equal (c->elem_type, "title") || 
 			       g_str_equal (c->elem_type, "titleabbrev")) {
-			c->score += 0.8;
+			local_score = 0.8;
 		    } else {
-			c->score += 0.5;
+			local_score = 0.1;
+		    }
+		    if (local_score > c->score_per_word[i]) {
+			g_free (c->snippet);
+			c->snippet = g_strndup (g_utf8_casefold ((gchar *) ch,
+								 len), 
+						len);
+			c->result_subsection = g_strdup (c->current_subsection);
+			if (!c->found_terms[i]) {
+			    c->score += local_score;
+			}
+			c->score_per_word[i] = local_score;
+			c->found_terms[i] = TRUE;
 		    }
 		}
 	    }
@@ -1117,6 +1124,8 @@
     gchar  *stderr_str;
     gchar  *lang;
     gchar  *command;
+    gchar *ignore_words;
+    gchar **ignore;
     static xmlSAXHandler sk_sax_handler = { 0, };
     xmlParserCtxtPtr parser;
     if (langs && langs[0])
@@ -1143,6 +1152,16 @@
     g_free (stderr_str);
     g_free (command);
 
+    ignore_words = g_strdup (_("a:about:an:are:as:at:be:broke:broken:by"
+			       ":can:can't:dialog:dialogue:do:doesn't"
+			       ":doesnt:don't:dont:explain:for:from:has"
+			       ":have:help:how:i:in:is:it:item:me:my:of"
+			       ":on:or:tell:that:the:thing:this:to:what"
+			       ":where:who:will:with:won't:wont:why:work"
+			       ":working:works"));
+    ignore = g_strsplit (ignore_words, ":", -1);
+
+
     while (omf_pending) {
 	GSList  *first = NULL;
 	gchar   *file  = NULL;
@@ -1157,6 +1176,9 @@
 	gchar *fname;
 	gchar *realfname;
 	gint nsearchterms;
+	gchar **sterm;	
+	gchar **sterm1;
+	int i = 0;
 
 	first = omf_pending;
 	omf_pending = g_slist_remove_link (omf_pending, first);
@@ -1212,8 +1234,35 @@
 			" ", -1);
 	nsearchterms = g_strv_length (container->search_term);
 	container->found_terms = g_new0 (gboolean, nsearchterms);
+	container->score_per_word = g_new0 (gfloat, nsearchterms);
 	container->search_status = NOT_SEARCHING;
 
+	container->stop_word = g_new0 (gboolean, nsearchterms);
+	for (sterm1 = container->search_term; *sterm1 != NULL; sterm1++) {
+	    if (g_str_has_suffix (*sterm1, "?")) {
+		gchar *tmp;
+		tmp = g_strndup (*sterm1, strlen (*sterm1)-1);
+		g_free (*sterm1);
+		*sterm1 = g_strdup (tmp);
+		g_free (tmp);
+	    }
+	    if (g_str_has_suffix (*sterm1, "'s")) {
+		gchar *tmp;
+		tmp = g_strndup (*sterm1, strlen (*sterm1)-2);
+		g_free (*sterm1);
+		*sterm1 = g_strdup (tmp);
+		g_free (tmp);
+	    }
+	    for (sterm = ignore; *sterm != NULL; sterm++) {
+		if (g_str_equal (*sterm1, *sterm)) {
+		    container->stop_word[i] = TRUE;
+		    continue;
+		}
+	    }
+	    i++;
+	}
+
+
 	pager->priv->pending_searches = 
 	    g_slist_prepend (pager->priv->pending_searches, container);
 	
@@ -1244,6 +1293,7 @@
 {
     SearchContainer *c;
     GSList *first = pager->priv->pending_searches;
+    gint i, j=0;
 
     pager->priv->pending_searches = 
 	g_slist_remove_link (pager->priv->pending_searches, first);
@@ -1256,6 +1306,12 @@
     }
 
     c = (SearchContainer *) first->data;
+    for (i=0; i< g_strv_length (c->search_term); ++i) {
+	if (c->found_terms[i])
+	    j++;
+    }
+    if (j == i)
+	c->result_found = TRUE;
 
     xmlSAXUserParseFile (&handlers, c, c->base_filename);
 
@@ -1266,6 +1322,13 @@
 	c->components = g_slist_remove_link (c->components, next);
 	c->search_status = NOT_SEARCHING;
 	xmlSAXUserParseFile (&handlers, c, (gchar *) next->data);
+	j = 0;
+	for (i=0; i< g_strv_length (c->search_term); ++i) {
+	    if (c->found_terms[i])
+		j++;
+	}
+	if (j == i)
+	    c->result_found = TRUE;
 	if (c->result_found) {
 	    search_parse_result (pager, c);
 	    break;
@@ -1403,8 +1466,9 @@
     int nterms = 0;
 
     for (i=0; i<g_strv_length (c->search_term); i++) {
-	if (c->found_terms[i])
-	    nterms++;
+	if (!c->found_terms[i]) {
+	    return;
+	}
     }
 
     new_uri = g_strconcat (c->base_filename, "#", c->result_subsection, 
@@ -1443,9 +1507,7 @@
 	xmlNode *child;
 	gchar *tmp = NULL;
 	gchar *after = NULL;
-	gchar *before = NULL;
 	gchar *title = NULL;
-	gint i;
 
 	if (line == NULL || line[0] == NULL)
 	    continue;
