public IEnumerable<Field> ToFields(EntityProjection entity, MetadataDefinitionGroupProjection group, IEnumerable<EntityValueProjection> values) { yield return new Field(FIELD_ID, entity.Identity.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED); yield return new Field(FIELD_NAME, entity.Name, Field.Store.YES, Field.Index.ANALYZED); yield return new Field(FIELD_NAME_RAW, entity.Name, Field.Store.NO, Field.Index.NOT_ANALYZED); if (group!= null) { yield return new Field(FIELD_GROUP_ID, group.Identity.ToString(), Field.Store.YES, Field.Index.ANALYZED); yield return new Field(FIELD_GROUP_NAME, group.Name, Field.Store.YES, Field.Index.ANALYZED); } foreach (var value in values) { foreach (var keyword in MetadataDefinition.KeywordDefinitions.Where(x => x.Equals(value.Name, StringComparison.InvariantCultureIgnoreCase))) { yield return new Field(keyword, value.Value, Field.Store.YES, Field.Index.ANALYZED); } yield return new Field(FIELD_METADATA, value.Value, Field.Store.YES, Field.Index.ANALYZED); } }
private Document ToDocument(EntityProjection entity, MetadataDefinitionGroupProjection group, IEnumerable<EntityValueProjection> values) { var doc = new Document(); foreach (var field in ToFields(entity, group, values)) doc.Add(field); return doc; }
public void SaveIndex(EntityProjection entity, MetadataDefinitionGroupProjection group, IEnumerable<EntityValueProjection> values) { var doc = ToDocument(entity, group, values); var term = new Term(FIELD_ID, entity.Identity.ToString()); using (var writer = OpenWriter()) { writer.UpdateDocument(term, doc); writer.Commit(); writer.Optimize(); } }