Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array support #32

Open
uksus70 opened this issue Jul 22, 2013 · 5 comments
Open

Array support #32

uksus70 opened this issue Jul 22, 2013 · 5 comments

Comments

@uksus70
Copy link

uksus70 commented Jul 22, 2013

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?

@chriseldredge
Copy link
Owner

Currently properties of type IEnumerable 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.

@uksus70
Copy link
Author

uksus70 commented Jul 23, 2013

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().

@chriseldredge
Copy link
Owner

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])

@xumix
Copy link

xumix commented Jun 23, 2015

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
Copy link

xumix commented Jun 23, 2015

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: 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants