beagle r4692 - in trunk/beagle: beagled beagled/LocateQueryable conf-data/config-files tools



Author: dbera
Date: Sun Apr 13 15:21:34 2008
New Revision: 4692
URL: http://svn.gnome.org/viewvc/beagle?rev=4692&view=rev

Log:
Users are treating beagle as a replacement to locate, which is not how I see it. Nevertheless, to not disappoint anybody here is a locate based backend.
* Disabled by default (obviously, since I dont support this idea). Enable using beagle-config/beagle-settings.
* Does not support searching for multiple words (because locate does not support our AND style queries).
* Results are not sorted by date.
* locate freaks out if asked to return results from non-hidden paths; so we prune them later. As a result, if the first 200 (double of MaxHits) paths returned are from a hidden path, no result is returned. Go and buy a book on locate, shell and regular expressions in that case :)
* Its a supplementary backend i.e. will return results in _addition_ to the FileSystem backend. If you really really really want to use this backend without the FSQ, set FSQ to not index anything and pass --indexing-delay -1 to beagled (i.e. keep the FSQ backend enabled, but not let it return anything).

All of the above are hints that you should use only one of beagle or locate. Peace!


Added:
   trunk/beagle/beagled/LocateQueryable/
   trunk/beagle/beagled/LocateQueryable/LocateDriver.cs   (contents, props changed)
Modified:
   trunk/beagle/beagled/AssemblyInfo.cs
   trunk/beagle/beagled/Makefile.am
   trunk/beagle/conf-data/config-files/Daemon.xml
   trunk/beagle/tools/Settings.cs

Modified: trunk/beagle/beagled/AssemblyInfo.cs
==============================================================================
--- trunk/beagle/beagled/AssemblyInfo.cs	(original)
+++ trunk/beagle/beagled/AssemblyInfo.cs	Sun Apr 13 15:21:34 2008
@@ -77,5 +77,6 @@
 	typeof (Beagle.Daemon.PidginQueryable.PidginQueryable),
 	typeof (Beagle.Daemon.StaticQueryable),
 	typeof (Beagle.Daemon.TomboyQueryable.TomboyQueryable),
-	typeof (Beagle.Daemon.EmpathyQueryable.EmpathyQueryable)                   
+	typeof (Beagle.Daemon.EmpathyQueryable.EmpathyQueryable),
+	typeof (Beagle.Daemon.LocateQueryable.LocateDriver)
 )]

Added: trunk/beagle/beagled/LocateQueryable/LocateDriver.cs
==============================================================================
--- (empty file)
+++ trunk/beagle/beagled/LocateQueryable/LocateDriver.cs	Sun Apr 13 15:21:34 2008
@@ -0,0 +1,188 @@
+//
+// LocateDriver.cs
+//
+// A backend which returns results of 'locate'.
+// This is really used as a supplement to the FileSystem backend
+// for say, when FSQ crawling is not finised yet or the user
+// wants usual locate style searching of files everywhere.
+//
+// Copyright (C) 2008 D Bera <dbera web gmail com>
+//
+//
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+
+using Beagle.Daemon;
+using Beagle.Util;
+
+namespace Beagle.Daemon.LocateQueryable {
+
+	[QueryableFlavor (Name="Locate", Domain=QueryDomain.System, RequireInotify=false, DependsOn="Files")]
+	public class LocateDriver : IQueryable {
+
+		public LocateDriver ()
+		{
+		}
+
+		public virtual void Start ()
+		{
+		}
+
+		public bool AcceptQuery (Query query)
+		{
+			// FIXME Process [-/OR] 'source:Locate' if specified
+
+			bool has_text = false;
+			foreach (QueryPart qp in query.Parts)
+				if (! has_text && qp is QueryPart_Text) {
+					has_text = true;
+				} else {
+					Log.Error ("LocateDriver does not support searching for multiple words");
+					return false;
+				}
+
+			if (! has_text) {
+				Log.Error ("LocateDriver can only search for text and does not support 'OR', 'NOT' queries.");
+				return false;
+			}
+			    
+			return true;
+		}
+
+		public void DoQuery (Query query, IQueryResult result, IQueryableChangeData data)
+		{
+			string search = null;
+			foreach (QueryPart qp in query.Parts) {
+				if (qp is QueryPart_Text) {
+					search = ((QueryPart_Text) qp).Text;
+					break;
+				}
+			}
+
+			if (String.IsNullOrEmpty (search))
+				return;
+
+			SafeProcess pc = new SafeProcess ();
+			// Double the max-hits since it is hard to tell locate to ignore
+			// hidden files and directories; so we prune them later.
+			// So if hidden files are returned first, you are doomed
+			pc.Arguments = new string[] { "locate", "-P", "-e", "-l", (2 * query.MaxHits).ToString (), search };
+			pc.RedirectStandardOutput = true;
+			pc.RedirectStandardError = false;
+			pc.UseLangC = true;
+
+			try {
+				pc.Start ();
+			} catch (Beagle.Util.SafeProcessException e) {
+				Log.Error (e, "Error while running 'locate -P -e -l {0} {1}'", (2 * query.MaxHits), search);
+				return;
+			}
+
+			string match = null;
+			ArrayList result_batch = new ArrayList ();
+			const int MAX_QUEUED_HITS = 25;
+			Hit hit;
+			int count = 0;
+
+			using (StreamReader pout = new StreamReader (pc.StandardOutput)) {
+				while (count < query.MaxHits && ! pout.EndOfStream) {
+					match = pout.ReadLine ();
+					hit = PathToHit (match);
+					if (hit == null)
+						continue;
+
+					result_batch.Add (hit);
+
+					if (result_batch.Count >= MAX_QUEUED_HITS) {
+						result.Add (result_batch);
+						result_batch.Clear ();
+					}
+					count ++;
+				}
+			}
+
+			result.Add (result_batch, count);
+
+			pc.Close ();
+		}
+
+		public int DoCountMatchQuery (Query query)
+		{
+			return 0;
+		}
+
+		public ISnippetReader GetSnippet (string[] query_terms, Hit hit, bool full_text, int ctx_length, int snp_length)
+		{
+			return null;
+		}
+
+		public QueryableStatus GetQueryableStatus ()
+		{
+			QueryableStatus status = new QueryableStatus ();
+
+			// FIXME Add Updatedb stats
+			status.ItemCount = -1;
+
+			status.ProgressPercent = -1;
+			status.IsIndexing = false;
+
+			return status;
+		}
+
+		//////////////////////////////////////////////////
+		// Convert matches to Hits
+
+		private Hit PathToHit (string path)
+		{
+			// Check if hidden
+			if (path.IndexOf ("/.") != -1)
+				return null;
+
+			Hit hit = new Hit ();
+			hit.Uri = UriFu.PathToFileUri (path);
+			hit.Timestamp = File.GetLastWriteTimeUtc (path);
+                        hit.AddProperty (Property.NewUnsearched ("beagle:HitType", "File"));
+			// Prevent any mimetype matching
+                        hit.AddProperty (Property.NewUnsearched ("beagle:MimeType", "beagle/x-locate-result"));
+                        hit.AddProperty (Property.NewUnsearched ("beagle:Source", "Locate"));
+			// Use a generic enough filetype to hint there is _no_ special properties
+			// for this hit
+                        hit.AddProperty (Property.NewUnsearched ("beagle:FileType", "document"));
+			hit.Score = 1.0;
+
+			foreach (Property std_prop in Property.StandardFileProperties (Path.GetFileName (path), true))
+				hit.AddProperty (std_prop);
+
+			hit.AddProperty (Property.NewUnsearched (
+					 Property.ParentDirUriPropKey,
+					 UriFu.PathToFileUri (Path.GetDirectoryName (path))));
+
+			return hit;
+		}
+
+	}
+}
+

Modified: trunk/beagle/beagled/Makefile.am
==============================================================================
--- trunk/beagle/beagled/Makefile.am	(original)
+++ trunk/beagle/beagled/Makefile.am	Sun Apr 13 15:21:34 2008
@@ -220,10 +220,14 @@
 	$(nautilusqueryable)/NautilusMetadataQueryable.cs
 
 networkservicesqueryable = $(srcdir)/NetworkServicesQueryable
-NETWORK_SERVICES_QUERYABLE =					\
+NETWORK_SERVICES_QUERYABLE_CSFILES =				\
 	$(networkservicesqueryable)/NetworkServicesQueryable.cs	\
 	$(networkservicesqueryable)/HttpTransport.cs
 
+locatequeryable = $(srcdir)/LocateQueryable
+LOCATE_QUERYABLE_CSFILES = 					\
+	$(locatequeryable)/LocateDriver.cs
+
 DAEMON_DLL_CSFILES = 						\
 	$(LUCENE_CSFILES)					\
 	$(SNOWBALL_CSFILES)					\
@@ -245,8 +249,9 @@
 	$(KONVERSATION_QUERYABLE_CSFILES)			\
 	$(OPERA_QUERYABLE_CSFILES)				\
 	$(NAUTILUS_QUERYABLE_CSFILES)				\
-	$(NETWORK_SERVICES_QUERYABLE)				\
-	$(EMPATHY_QUERYABLE_CSFILES)			\
+	$(NETWORK_SERVICES_QUERYABLE_CSFILES)			\
+	$(EMPATHY_QUERYABLE_CSFILES)				\
+	$(LOCATE_QUERYABLE_CSFILES)				\
 	$(srcdir)/AssemblyInfo.cs				\
 	$(srcdir)/BatteryMonitor.cs				\
 	$(srcdir)/ExternalMetadataQueryable.cs			\

Modified: trunk/beagle/conf-data/config-files/Daemon.xml
==============================================================================
--- trunk/beagle/conf-data/config-files/Daemon.xml	(original)
+++ trunk/beagle/conf-data/config-files/Daemon.xml	Sun Apr 13 15:21:34 2008
@@ -8,6 +8,8 @@
     <ListOption Name="DeniedBackends" Description="Disabled backends" Params="Backend name" Separator=",">
 	<!-- Disabled by default EXPERIMENTAL -->
 	<Value>NetworkServices</Value>
+	<!-- Directly use locate; needed for exceptional uses only -->
+	<Value>Locate</Value>
     </ListOption>
     <BoolOption Name="AllowStaticBackend" Description="Search static indexes">true</BoolOption>
     <BoolOption Name="IndexSynchronization" Description="Synchronize indexes locally if home directory is on a network device (eg. NFS/Samba)">true</BoolOption>

Modified: trunk/beagle/tools/Settings.cs
==============================================================================
--- trunk/beagle/tools/Settings.cs	(original)
+++ trunk/beagle/tools/Settings.cs	Sun Apr 13 15:21:34 2008
@@ -1579,6 +1579,7 @@
 			"Kopete",
 			"Labyrinth",
 			"Liferea",
+			"Locate",
 			"NautilusMetadata",
 			"NetworkServices", // This should be configurable in the network tab
 			"Opera",
@@ -1609,6 +1610,7 @@
 			"IMs and chats from Kopete",
 			"Mind-maps from Labyrinth.",
 			"RSS feeds from Liferea.",
+			"Supplementary search results using 'locate' command",
 			"Nautilus' metadata (emblems, notes, etc.)",
 			"Search other search services in the network (EXPERIMENTAL)",
 			"Opera's bookmarks and browsing history.",



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