Re: Beagle,Querying extended properties

2007/7/5, Daniel Labella de la Cruz <dani labella gmail com>:
Hi Joe, thank you again for the response...
Now I can store extended attribute to indexable, but I found one problem,  I think  maybe is a bug...
Beagle deletes extended attributes introduced by user
by example:
tocuh test.txt
setfattr -n user.test -v test_attribute test.txt
beagle-query --verbose test.txt
-- In this step I can see the xattr:test = test_attribute
-- if I do getfattr test.txt I see user.test attribute
vim test.txt
-- put some chars to file and save
beagle-query --verbose test.txt
-- Now I don't see the property
-- if I do getfattr test.txt I don't see user.test attribute

and now one more thing, when I add a new extended attribute to a file, beagle don't reindex de file due to that modification don't implies date modification or last access modification. I try to find a way to do it...

an the last, the working code to add extended attributes (only for the first index)
It only works if the file exists and have extended attributes before launch beagle daemon.
How to test:

touch test.txt
setfattr -n user.test -v test_attribute test.txt
beagle-query --verbose test.txt

here is the code:
- Added function

 public static void AddExtendedPropertiesToIndexable(Indexable indexable,
                                                                       string    path)
                        string[] XProperties;
                        string[] XPropertyNames;
                        string XValue="";
                        string XProperty="";
                        XProperties=Util.ExtendedAttribute.List (path);
                        for( int i=0; i < XProperties.Length ; i++)
                                XPropertyNames = XProperties[i].Split('.');
                                XProperty = XPropertyNames[ XPropertyNames.Length-1];
                                XValue    = Util.ExtendedAttribute.Get(path,XProperties[i],true);

then a I make a call on the next function in the same file...

 public static void AddStandardPropertiesToIndexable (Indexable indexable,
                                                                     string    name,
                                                                     Guid      parent_id,
                                                                     bool      mutable)
                        foreach (Property std_prop in Property.StandardFileProperties (name, mutable))
                                indexable.AddProperty (std_prop);

                        AddExtendedPropertiesToIndexable (indexable, name);

                        if (parent_id == Guid.Empty)

                        string str = GuidFu.ToUriString (parent_id);
                        // We use the uri here to recycle terms in the index,
                        // since each directory's uri will already be indexed.
                        Property prop = Property.NewUnsearched (Property.ParentDirUriPropKey, str);
                        prop.IsMutable = mutable;
                        indexable.AddProperty (prop);

the I modified ExtendedAttribute.cs
added List function

 public static string[]  List (string path)
                        string[] XPropertiesNames;
                        if(! FileSystem.Exists(path))
                            throw new IOException (path);
                            Syscall.listxattr (path,out XPropertiesNames);
                        return XPropertiesNames;
modification to Get function and added one new call

 public static string Get (string path, string name)
                        return Get(path,name,false);

                public static string Get (string path, string name,bool getByAbsoluteName)
                        if (! FileSystem.Exists (path))
                                throw new IOException (path);
                        if (! getByAbsoluteName)
                                name = AddPrefix (name);

                        byte[] buffer;
                        long size = Syscall.lgetxattr (path, name, out buffer);
                        if (size <= 0)
                                return null;
                        return encoding.GetString (buffer);
that's all, sorry for this long email...

Thank you for all!!!

2007/7/2, Joe Shaw <joe joeshaw org>:

Sorry for the delay, I'm digging myself out from a mountain of
neglected email. :(

On 6/19/07, Daniel Labella de la Cruz < dani labella gmail com> wrote:
> Hello!!, I have a problem, I'm trying to put the code on
> FIleSystemQueryable.cs but I don't know if I'm doing somethig wrong or it
> just don't work....
> I added this code on ExtendedAttribute.cs inside Util directory for listing
> extended properties...
>         public static ArrayList List (string path)
>         {
>             string[] XPropertiesNames;
>             ArrayList XPropertiesList=new ArrayList();
>             if(! FileSystem.Exists(path))
>                 throw new IOException (path);
>             Syscall.listxattr (path,out XPropertiesNames);
>             for (int i=0 ; i<XPropertiesNames.Length ; i++)
>             {
>                 XPropertiesList.Add (XPropertiesNames[i]);
>             }
>             return XPropertiesList;
>         }

I don't see anything wrong with this function, but I would probably
change it to just return string[], since you wouldn't ever need to
change the return value.

> and then added the following method to FileSystemQueryable.cs
>        public static void AddExtendedProperties (Indexable      indexable,
> string         path)
>         {
>             ArrayList XPropertyList=new ArrayList();
>             string XPropertyValue;
>             string[] PropertyName;
>             XPropertyList=Util.ExtendedAttribute.List(path);
>             foreach (string XPropertyName in XPropertyList)
>             {
> XPropertyValue=Util.ExtendedAttribute.Get(path,XPropertyName);
>                 PropertyName=XPropertyName.Split('.');
>                 indexable.AddProperty(Beagle.Property.New
> ("xattr:"+XPropertyValue,
> PropertyName[PropertyName.Length-1]));
>             }
>         }

I'm not really sure what you're trying to use for key-value here.
You're taking the value of the xattr and using it as part of the
property key.  If I have an xattr "user.testing.key" = "value", your
Beagle property will be "xattr:value" = "key", and I'm pretty sure
that's not what you want.

> and then I make a call to this method on AddFile method
>          .
>          .
>          .
>           if (indexable != null) {
>                 Scheduler.Task task;
>                 //a call to add extended properties
>                 AddExtendedProperties (indexable,path);
>                 //
>                 task = NewAddTask (indexable);
>                 task.Priority = Scheduler.Priority.Immediate;
>                 ThisScheduler.Add (task);
>             }
>             .
>             .
>             .
> after this, it compile ok, but I don't know if I'm doing somethig wrong
> querying the extended attributes (maybe I'm querying with wrong syntax) or
> simply the code I put doesn't work...

I think the item I mentioned above is why searches aren't working for
you.  You might want to search for other things you know will match
(like the file name, or a unique word contained inside the document)
and use beagle-query --verbose.  That will give you the list of all
the properties on the document.


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