예제 #1
0
        private DefaultSphinxDocument BuildSphinxDocument(IDatabaseEntity entity, FieldSetInfo info)
        {
            if (entity == null || info == null)
                return null;

            var sb = new StringBuilder(1024);
            info.FormatAsText(sb);
            string body = sb.ToString();

            if (string.IsNullOrWhiteSpace(body))
                return null;

            string title = string.Format("{0} / {1}", GetTitle(), info.Title);
            string url = EntityUri() + info.Url;

            return new DefaultSphinxDocument(new DocumentId(entity.id, info.Id), title, body, url, entity.ProtoName);
        }
예제 #2
0
        private static FieldSetInfo BuildFieldSetInfo(fieldsets fieldset, IDatabaseEntity entity, bool announce = false)
        {
            if (fieldset == null)
                return null;

            var result = new FieldSetInfo
            {
                Id = fieldset.id,
                Title = fieldset.title,
                Url = fieldset.url,
                ShowGallery = fieldset.show_gallery,
                ShowMap = fieldset.show_map
            };

            var fields = new List<entity_fields>();
            if (announce)
            {
                fields = Meridian.Default.entity_fieldsStore.All()
                    .Where(item => item.fieldsets_items.Any(f => f.id == fieldset.id))
                    .OrderBy(item => item.announce_order).ToList();
            }
            else
            {
                var fieldsOrders = Meridian.Default.fieldset_fields_orderStore.All()
                    .Where(item => item.fieldset_id == fieldset.id)
                    .OrderBy(item => item.order_number).ToList();
                foreach (var fieldOrder in fieldsOrders)
                {
                    var item = fieldset.fieldsets_items.Find(f => f.id == fieldOrder.field_id);
                    if (item != null)
                    {
                        fields.Add(item);
                    }
                }
            }

            foreach (var field in fields)
            {
                var fieldValue = Meridian.Default.field_valuesStore.All()
                        .FirstOrDefault(item =>
                            item.proto_name == entity.ProtoName && item.field_id == field.id && item.entity_id == entity.id);

                if (fieldValue != null || (!string.IsNullOrEmpty(field.controller) && !string.IsNullOrEmpty(field.action)))
                {
                    result.Fields.Add(new FieldInfo
                    {
                        Title = field.title,
                        Value = fieldValue != null ? fieldValue.field_value : string.Empty,
                        Controller = field.controller,
                        Action = field.action
                    });
                }
            }

            return result;
        }