tracker r1868 - in branches/indexer-split: . src/tracker-indexer tests/tracker-indexer



Author: ifrade
Date: Wed Jul  9 09:59:43 2008
New Revision: 1868
URL: http://svn.gnome.org/viewvc/tracker?rev=1868&view=rev

Log:
Tested and implemented document removing from tracker-index

Modified:
   branches/indexer-split/ChangeLog
   branches/indexer-split/src/tracker-indexer/tracker-index.c
   branches/indexer-split/tests/tracker-indexer/tracker-index-test.c

Modified: branches/indexer-split/src/tracker-indexer/tracker-index.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/tracker-index.c	(original)
+++ branches/indexer-split/src/tracker-indexer/tracker-index.c	Wed Jul  9 09:59:43 2008
@@ -229,8 +229,6 @@
 				/* check for deletion */		
 				if (score < 1) {
 					
-					/* g_print ("Deleting word hit %s\n", word); */
-					
 					/* shift all subsequent records in array down one place */
 					for (k = i + 1; k < old_hit_count; k++) {
 						previous_hits[k - 1] = previous_hits[k];
@@ -255,16 +253,24 @@
 			}
 
 			g_array_append_val (pending_hits, *new_hit);
-			g_debug ("could not update word hit %s - appending", word);
+			/* g_debug ("could not update word hit %s - appending", word); */
 		}
 	}
 	
 	/* write back if we have modded anything */
 	if (write_back) {
-		dpput (index, 
-		       word, -1, 
-		       (char *) previous_hits, (old_hit_count * sizeof (TrackerIndexElement)), 
-		       DP_DOVER);
+		/* 
+		 * If the word has no hits, remove it! 
+		 * Otherwise overwrite the value with the new hits array
+		 */
+		if (old_hit_count < 1) {
+			dpout (index, word, -1);
+		} else {
+			dpput (index, 
+			       word, -1, 
+			       (char *) previous_hits, (old_hit_count * sizeof (TrackerIndexElement)), 
+			       DP_DOVER);
+		}
 	}
 	
 	/*  Append new occurences */
@@ -305,7 +311,7 @@
 	guint size;
 
 	size = g_hash_table_size (index->cache);
-	g_message ("Flushing index with %d items", size);
+	g_message ("Flushing index with %d items in cache", size);
 
 	g_hash_table_foreach_remove (index->cache, cache_flush_foreach, index->index);
 

Modified: branches/indexer-split/tests/tracker-indexer/tracker-index-test.c
==============================================================================
--- branches/indexer-split/tests/tracker-indexer/tracker-index-test.c	(original)
+++ branches/indexer-split/tests/tracker-indexer/tracker-index-test.c	Wed Jul  9 09:59:43 2008
@@ -216,6 +216,23 @@
         
 }
 
+gint
+insert_in_index (TrackerIndex *index, const gchar *text) 
+{
+        gchar **pieces;
+        gint i;
+        static gint doc = 0;
+
+        doc += 1;
+
+        pieces = g_strsplit (text, " ", -1);
+        for (i = 0; pieces[i] != NULL; i++) {
+                tracker_index_add_word (index, pieces[i], doc, 1, 1);
+        }
+        g_strfreev (pieces);
+
+        return doc;
+}
 
 static void
 test_add_with_flushs () 
@@ -223,8 +240,6 @@
 
         TrackerIndex *index;
         const gchar *indexname = "test-add-with-flush.index";
-        gchar **pieces;
-        gint i;
 
         const gchar *text1 = "this is a text to try a kind of real use case of the indexer";
         const gchar *text2 = "this is another text with some common words";
@@ -233,19 +248,11 @@
         index = tracker_index_new (indexname, BUCKET_COUNT);
 
         /* Text 1 */
-        pieces = g_strsplit (text1, " ", -1);
-        for (i = 0; pieces[i] != NULL; i++) {
-                tracker_index_add_word (index, pieces[i], 1, 1, 1);
-        }
-        g_strfreev (pieces);
+        insert_in_index (index, text1);
         tracker_index_flush (index);
 
         /* Text 2 */
-        pieces = g_strsplit (text2, " ", -1);
-        for (i = 0; pieces[i] != NULL; i++) {
-                tracker_index_add_word (index, pieces[i], 2, 1, 1);
-        }
-        g_strfreev (pieces);
+        insert_in_index (index, text2);
         tracker_index_flush (index);
 
         tracker_index_free (index);
@@ -258,6 +265,61 @@
 
 }
 
+void
+remove_in_index (TrackerIndex *index, const gchar *text, gint docid) 
+{
+        gchar **pieces;
+        gint i;
+        static gint doc = 1;
+
+        pieces = g_strsplit (text, " ", -1);
+        for (i = 0; pieces[i] != NULL; i++) {
+                tracker_index_add_word (index, pieces[i], docid, 1, -1);
+        }
+        g_strfreev (pieces);
+
+        doc += 1;
+}
+
+
+static void
+test_remove_document ()
+{
+        TrackerIndex *index;
+        const gchar *indexname = "test-remove-document.index";
+        gint id1, id2;
+
+        const gchar *doc1 = "this is a text to try a kind of real use case of the indexer";
+        const gchar *doc2 = "this is another text with some common words";
+        
+        g_remove (indexname);
+
+        index = tracker_index_new (indexname, BUCKET_COUNT);
+
+        /* Doc 1 */
+        id1 = insert_in_index (index, doc1);
+        tracker_index_flush (index);
+
+        /* Doc 2 */
+        id2 = insert_in_index (index, doc2);
+        tracker_index_flush (index);
+
+        tracker_index_free (index);
+
+        g_assert_cmpint (get_number_words_in_index (indexname), ==, 18);
+
+        index = tracker_index_new (indexname, BUCKET_COUNT);
+        
+        /* Remove doc1 */
+        remove_in_index (index, doc1, id1);
+        tracker_index_flush (index);
+
+        tracker_index_free (index);
+
+        g_assert_cmpint (get_number_words_in_index (indexname), ==, 8);
+
+        g_remove (indexname);
+}
 
 
 int
@@ -282,6 +344,10 @@
 
         g_test_add_func ("/tracker/tracker-indexer/tracker-index/add_with_flush",
                          test_add_with_flushs);
+
+        g_test_add_func ("/tracker/tracker-indexer/tracker-index/remove_document",
+                         test_remove_document);
+
         result = g_test_run ();
         
         return result;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]