tracker r2477 - in trunk: . src/tracker-fts utils/tracker-fts



Author: jamiemcc
Date: Mon Nov 10 03:52:52 2008
New Revision: 2477
URL: http://svn.gnome.org/viewvc/tracker?rev=2477&view=rev

Log:
2008-11-09 Jamie McCracken <jamiemcc at gnome org>

	* src/tracker-fts/tracker-fts.c:
	made rank func use meatdata ranking
	set up default column for storing positions efficiently spacewise

	* utils/tracker-fts/tracker-fts-test.c:
	updated example


Modified:
   trunk/ChangeLog
   trunk/src/tracker-fts/tracker-fts.c
   trunk/utils/tracker-fts/tracker-fts-test.c

Modified: trunk/src/tracker-fts/tracker-fts.c
==============================================================================
--- trunk/src/tracker-fts/tracker-fts.c	(original)
+++ trunk/src/tracker-fts/tracker-fts.c	Mon Nov 10 03:52:52 2008
@@ -318,6 +318,8 @@
 #endif
 
 
+static int default_column = 0;
+
 /*  functions needed from tracker */
 
 static TrackerDBResultSet *
@@ -402,7 +404,18 @@
 	return contents;
 }
 
+static inline int
+get_metadata_weight (int id)
+{
+  if (id == 0) return 1;
 
+  TrackerField *field = tracker_ontology_get_field_by_id (id);
+  
+  if (!field) return 1;
+
+  return tracker_field_get_weight (field);
+
+}
 
 
 
@@ -1074,7 +1087,7 @@
   pReader->pData = dlrPosData(pDLReader);
   pReader->nData = dlrPosDataLen(pDLReader);
   pReader->iType = pDLReader->iType;
-  pReader->iColumn = 0;
+  pReader->iColumn = default_column;
   pReader->iPosition = 0;
   pReader->iStartOffset = 0;
   pReader->iEndOffset = 0;
@@ -1190,7 +1203,9 @@
   pWriter->dlw->has_iPrevDocid = 1;
 #endif
 
-  pWriter->iColumn = 0;
+  /* [tracker] - the default column (ID = 0) should be that of File:Contents for Files db and Email:Body for email db 
+  that way we avoid wrting a column ID and cosuming more bytes for the most voluminous cases */
+  pWriter->iColumn = default_column;
   pWriter->iPos = 0;
   pWriter->iOffset = 0;
 }
@@ -3616,6 +3631,7 @@
 static int fulltextOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
   fulltext_cursor *c;
 
+  fulltext_vtab *v = (fulltext_vtab *)pVTab;
   c = (fulltext_cursor *) sqlite3_malloc(sizeof(fulltext_cursor));
   if( c ){
     memset(c, 0, sizeof(fulltext_cursor));
@@ -3623,7 +3639,7 @@
     *ppCursor = &c->base;
     
     c->offsets = g_string_new ("");
-    
+        
     FTSTRACE(("FTS3 Open %p: %p\n", pVTab, c));
     return SQLITE_OK;
   }else{
@@ -4239,13 +4255,16 @@
   
     
     for ( ; !plrAtEnd(&plReader); plrStep(&plReader) ){
-   
-      c->rank++;
+     
+      int col = plrColumn (&plReader);
+      
+      c->rank += get_metadata_weight (col);
+      
       if (first_pos) {
-        g_string_append_printf (c->offsets, "%d,%d", plrColumn (&plReader), plrPosition (&plReader));
+        g_string_append_printf (c->offsets, "%d,%d", col, plrPosition (&plReader));
         first_pos = FALSE;
       } else {
-        g_string_append_printf (c->offsets, ",%d,%d", plrColumn (&plReader), plrPosition (&plReader));
+        g_string_append_printf (c->offsets, ",%d,%d", col, plrPosition (&plReader));
       }
     }
        
@@ -4842,6 +4861,7 @@
 int Catid,
 #endif
 		      const char *zText, int iColumn){
+		      
   const char *pToken;
   int nTokenBytes;
   int iStartOffset, iEndOffset, iPosition, stop_word, new_paragraph;
@@ -4934,9 +4954,13 @@
   
 #ifdef STORE_CATEGORY   
   
+  /* tracker- category is at column 0 so we dont want to add that value to index */
   for(i = 1; i < v->nColumn ; ++i){
     char *zText = (char*)sqlite3_value_text(pValues[i]);
-    int rc = buildTerms(v, iDocid, sqlite3_value_int (pValues[0]), zText, i);
+    
+    /* tracker - as for col id we want col 0 to be the default metadata field (file:contents or email:body) , 
+    col 1 to be meatdata id 1, col 2 to be metadat id 2 etc so need to decrement i here */
+    int rc = buildTerms(v, iDocid, sqlite3_value_int (pValues[0]), zText, i-1);
     if( rc!=SQLITE_OK ) return rc;
   }
   

Modified: trunk/utils/tracker-fts/tracker-fts-test.c
==============================================================================
--- trunk/utils/tracker-fts/tracker-fts-test.c	(original)
+++ trunk/utils/tracker-fts/tracker-fts-test.c	Mon Nov 10 03:52:52 2008
@@ -95,17 +95,17 @@
 	}
 	
 	if (!db_exists) {
-		exec_sql (db, "create virtual table recipe using trackerfts (cat, name, ingredients)");
-		exec_sql (db, "insert into recipe (cat, name, ingredients) values (3, 'broccoli stew stew stew', 'broccoli,peppers,cheese and tomatoes')");
-		exec_sql (db, "insert into recipe (cat, name, ingredients) values (4, 'pumpkin stew stew stew', 'pumpkin,onions,garlic and celery')");
-		exec_sql (db, "insert into recipe (cat, name, ingredients) values (2, 'broccoli pie stew', 'broccoli,cheese,onions and flour.')");
-		exec_sql (db, "insert into recipe (cat, name, ingredients) values (7, 'stew pumpkin pie stew', 'pumpkin,sugar,flour and butter.')");
-		exec_sql (db, "insert into recipe (cat, name, ingredients) values (6, 'stew pumpkin pie stew', 'pumpkin,sugar,flour and butter.')");
+		exec_sql (db, "create virtual table recipe using trackerfts (cat, col_default, col_1, col_2)");
+		exec_sql (db, "insert into recipe (cat, col_default, col_1, col_2) values (3, 'broccoli stew stew stew', 'broccoli,peppers,cheese and tomatoes', 'mix them all up and have fun')");
+		exec_sql (db, "insert into recipe (cat, col_default, col_1, col_2) values (4, 'pumpkin stew stew stew', 'pumpkin,onions,garlic and celery', 'spread them thinly')");
+		exec_sql (db, "insert into recipe (cat, col_default, col_1, col_2) values (2, 'broccoli pie stew', 'broccoli,cheese,onions and flour.', 'mash em up')");
+		exec_sql (db, "insert into recipe (cat, col_default, col_1, col_2) values (7, 'stew pumpkin pie stew', 'pumpkin,sugar,flour and butter.', 'spread them all thinly')");
+		exec_sql (db, "insert into recipe (cat, col_default, col_1, col_2) values (6, 'stew pumpkin pie stew', 'pumpkin,sugar,flour and butter.', 'mash and spread')");
 	}
 //	sql = g_strdup_printf ("select cat, count (*) from recipe where recipe match '%s' group by Cat", argv[1]);
 //	exec_sql (db, sql);
 //	g_free (sql);
-	sql = g_strdup_printf ("select rowid, cat, name, ingredients, offsets(recipe), rank(recipe) from recipe where recipe match '%s' and Cat<8", argv[1]);
+	sql = g_strdup_printf ("select rowid, cat, col_default, col_1, col_2, offsets(recipe), rank(recipe) from recipe where recipe match '%s' and Cat<8 order by rank(recipe) desc", argv[1]);
 	exec_sql (db, sql);
 	g_free (sql);
 	



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