Lucene.Net.Linq icon indicating copy to clipboard operation
Lucene.Net.Linq copied to clipboard

Array support

Open uksus70 opened this issue 12 years ago • 5 comments

Are array properties supported? Seems no.

Lucene supports multiple field instances with the same name for a single doc. Is this feature supported in Lucene.Net.Linq?

uksus70 avatar Jul 22 '13 04:07 uksus70

Currently properties of type IEnumerable<T> are supported. To support more specific collections and arrays, changes will be required in FieldMappingInfoBuilder:58 and CollectionReflectionFieldMapper. Test cases can be added to FieldMappingInfoBuilderCollectionComplexTypeTests and/or FieldMappingInfoBuilderCollectionTests.

I'll keep this open until I get to it, or you can submit a PR if you'd like to see support sooner.

chriseldredge avatar Jul 22 '13 14:07 chriseldredge

Thank you for fast response. Using IEnumerable is okay for me. However, is it possible to costruct a query on a multi-valued field to find documents having one of its values present in a fixed list of values? Actually, I would express it this way: obj.Tags.Intersect(values).Any().

uksus70 avatar Jul 23 '13 10:07 uksus70

You can test for the presence of a single value as in:

var result = from doc in documents where doc.Tags.Contains("c") select doc;

There is not currently a way to do an intersection with an arbitrary number of terms and I don't think Lucene supports this concept natively anyway. At best the LINQ library would probably have to transform doc.Tags.Intersect(values).Any() into doc.Tags.Contains(value[0]) || doc.Tags.Contains(value[1])

chriseldredge avatar Jul 23 '13 13:07 chriseldredge

protected internal virtual IFieldMapper<T> ToFieldMapper()
{
  ReflectionFieldMapper<T> inner = this.ToFieldMapperInternal();
  Type collectionType;
  if (FieldMappingInfoBuilder.IsCollection(this.propInfo.PropertyType, out collectionType))
    return (IFieldMapper<T>) new CollectionReflectionFieldMapper<T>(inner, collectionType);
  return (IFieldMapper<T>) inner;
}

This thing actually fails for string[] propperty, this.ToFieldMapperInternal(); must be called AFTER if (FieldMappingInfoBuilder.IsCollection(this.propInfo.PropertyType, out collectionType))

xumix avatar Jun 23 '15 11:06 xumix

Moreover, there is not way I can ignore this property :( I've tried map.Property(p => p.Photos).NotStored().NotIndexed(); but session still fails with:

System.NotSupportedException occurred
  HResult=-2146233067
  Message=Property Photos of type System.String[] cannot be converted from System.String
  Source=Lucene.Net.Linq
  StackTrace:
       at Lucene.Net.Linq.Mapping.FieldMappingInfoBuilder.GetConverter(PropertyInfo p, Type type, FieldAttribute metadata)
       at Lucene.Net.Linq.Fluent.PropertyMap`1.ResolveConverter()
       at Lucene.Net.Linq.Fluent.PropertyMap`1.ToFieldMapperInternal()
       at Lucene.Net.Linq.Fluent.PropertyMap`1.ToFieldMapper()
       at Lucene.Net.Linq.Fluent.ClassMap`1.ToDocumentMapper()
       at RestChild.Booking.TourIndexer.IndexAll() in c:\Projects\RestChild\RestChild.Booking\TourIndexer.cs:line 38
  InnerException: 

xumix avatar Jun 23 '15 11:06 xumix