How to FIlter ImageVault Files based on Categories

 

In our application different type (images, word documents, pdfs, videos) of files are stored in ImageVault. I was able to index these ImageVault files and even query them using the following query:

client.Search().Select(x => new SearchHit{Title = x.Name, Url = x.LinkURL}).GetResult()

Further to this, I would like to add filtering option to the above query which is where I'm stuck now. Following is the representation of ImageVault class structure:

public class IVFileData : IFileHandler {

public IVCategoryCollection Categories { get; set; }

public DateTime Changed { get; }

public string ColorDepth { get; }

public string ColorSpace { get; }

public IVConversionFormatCollection ConversionFormats { get; }

public DateTime Created { get; }

public User CreatedBy { get; }

public string Extension { get; }

public string FileName { get; }

public long FileSize { get; }

public int Height { get; }

public int Id { get; }

public bool IsArchived { get; }

public bool IsImage { get; }

public long Length { get; }

public string LinkURL { get; }

public IVMetaDataCollection MetaData { get; }

public string Name { get; }

public int Resolution { get; }

public string Title { get; }

public int Width { get; }

public void Delete();

public void MoveTo(IDirectoryHandler dir);

public Stream OpenRead();

public Stream OpenWrite();

public static IVFileData Parse(object property);

public static IVFileData Parse(object property, IVAccessLevel accessLevel);

public bool QueryDistinctAccess(IVAccessLevel access);

public void Rename(string newName);

}

public class IVCategoryCollection : CollectionBase, ICategoryList, ICollection, IEnumerable {

public IVCategoryCollection();

public IVCategory this[int i] { get; set; }

public IVCategory this[string name] { get; set; }

public int Add(IVCategory category);

public int GetIndex(IVCategory category);

public void Insert(int index, IVCategory category);

protected override void OnInsert(int index, object value);

protected override void OnRemove(int index, object value);

protected override void OnSet(int index, object oldValue, object newValue);

protected override void OnValidate(object value);

public void Remove(IVCategory category);

}

public class IVCategory {

public IVCategory(int id);

public int Id { get; }

public string Name { get; }

public string OriginalName { get; }

}

Each file in ImageVault is accessed via the IVFileData object. As represented, the "Categories" property in IVFIleData class is a collection of type IVCategoryCollection. I now want to filter the IVFileData objects based on a particular category. Say I have 2 IVFileData files, one with categories - RegionEurope and LanguageEnglish and another with only LanguageGerman category. I want to filter the objects and get only those with LanguageGerman category. I'm not able to write the ".Match" or ".MatchContained" filters on "client.Search().Filter(x => x.Categories.", as I dont get these options on the intellisense.

Hence, I'm not able to do a query like "client.Search().Filter(x => x.Categories.MatchContained(y = y.Name, "LanguageGerman"))". Kindly let me know on how to filter IVFileData objects based on desired categories. Thanks.

#64521 Dec 26, 2012 14:41
  •  

    I have now found out the way to filter the IVFileData objects based on the categories, which is:

    client.Search<IVFileData>().Filter(x => x.Categories.Cast<IVCategory>().MatchContained(y => y.Id, <SomeId>)).GetResult();

    However, I dont get any results eventhough I have files under the specified Category. On analysing found out that collection of complex types are not indexed by default. Hence the "IVCategoryCollection" collection in "IVFileData" seem to be not indexed, eventually resulting in the above category filter query returning zero hits.

    On going through the documentation came across the code snippet(the third and final code sample) shown in IncludingFields section, which states about including the complex type properties through delegates. Is there any way that I can include the category information to be indexed similarly? If so kindly let me know how to go about it with reference to the "IVCategoryCollection" property in "IVFileData" class.

    #64527 Edited, Dec 27, 2012 15:46
  •  

    Hi Rajesh,

    Collections if complex types should be indexed but if the collection isn't strongly typed (IEnumerable<T>) you will have to use casts in the expression when using MatchContained. That is, .Filter(x => x.Categories.MatchContained(y => ((IVCategory) y).Id, <SomeId>))

    Either way, you are on the right track with including fields as that will make the querying much easier. I would create an extension method for IVFileData which returns the category names. Then configure the conventions to index it. You should do that only once, in global.asax or better yet in an initialization module.

    If you do that and call the method CategoryNames you could simply filter using .Filter(x => x.CategoryNames.Match("some name"))

    #64557 Jan 01, 2013 17:25