private void SetDocumentMetaDataFields(IndexingOptions options, DataManager manager, IndexDocument doc) { HasMetadata md = manager.ActsAs(typeof(HasMetadata)) as HasMetadata; if (md == null) return; MetaDataCollection metadata = manager[md.FieldName] as MetaDataCollection; if (metadata == null) return; Dictionary<string, double> tagHighestValues = new Dictionary<string, double>(StringComparer.CurrentCultureIgnoreCase); foreach (Tag t in metadata) { if (t.StringValueNormalized == null) { doc.AddField(FieldType.Keyword, t.Name, t.NumericValue); } else { if (!tagHighestValues.ContainsKey(t.Name)) { tagHighestValues.Add(t.Name, 0f); foreach (Tag weighted in metadata.Get(t.Name)) { if (tagHighestValues[t.Name] < weighted.NumericValue) { tagHighestValues[t.Name] = weighted.NumericValue; } } } float highest = (float)tagHighestValues[t.Name]; float boost = (float)Math.Abs(t.NumericValue - highest); if ("author".Equals(t.Name, StringComparison.CurrentCultureIgnoreCase)) { doc.AddField(FieldType.Keyword, t.Name, t.StringValue.ToLower()); } else { doc.AddField(FieldType.Keyword, t.Name, t.StringValueNormalized.ToLower()); } //doc.AddField(FieldType.Keyword, t.Name, t.StringValueNormalized.ToLower(), boost); } } }
private void SetDocumentPermissions(IndexingOptions options, DataManager manager, IndexDocument doc) { LockedDown ld = manager.ActsAs(typeof(LockedDown)) as LockedDown; if (ld == null) return; PermissionsCollection permissions = manager[ld.FieldName] as PermissionsCollection; if (permissions == null) return; string[] groups = (options.GroupsWithViewPermissions != null) ? options.GroupsWithViewPermissions : permissions.GroupsWithViewPermissions; Array.Sort<string>(groups); foreach (string group in groups) { doc.AddField(FieldType.Keyword, "GroupWithViewPermissions", group.ToLower()); } groups = permissions.GroupsWithCreatePermissions; Array.Sort<string>(groups); foreach (string group in groups) { doc.AddField(FieldType.Keyword, "GroupWithCreatePermissions", group.ToLower()); } groups = permissions.GroupsWithEditPermissions; Array.Sort<string>(groups); foreach (string group in groups) { doc.AddField(FieldType.Keyword, "GroupWithEditPermissions", group.ToLower()); } }