public void RegisterRoutes(IMapRoute mapRouteManager) { // /desktopmodules/OpenContent/api/{controller}/{action} mapRouteManager.MapHttpRoute( moduleFolderName: "OpenContent", routeName: "default", url: "{controller}/{action}", namespaces: new[] { "Satrabel.OpenContent.Components", "Satrabel.OpenContent.Components.JpList", "Satrabel.OpenContent.Components.Rss", "Satrabel.OpenContent.Components.Rest.Swagger", "Satrabel.OpenContent.Components.Export", } ); // /desktopmodules/OpenContent/api/{controller}/v1/{entity}/{id}/{memberAction} mapRouteManager.MapHttpRoute( moduleFolderName: "OpenContent", routeName: "rest", url: "{controller}/v1/{entity}/{id}/{memberAction}", defaults: new { id = RouteParameter.Optional, memberAction = RouteParameter.Optional }, namespaces: new[] { "Satrabel.OpenContent.Components.Rest" } ); mapRouteManager.MapHttpRoute( moduleFolderName: "OpenContent", routeName: "restv2", url: "{controller}/v2/{entity}/{id}/{memberAction}", defaults: new { id = RouteParameter.Optional, memberAction = RouteParameter.Optional }, namespaces: new[] { "Satrabel.OpenContent.Components.Rest.V2" } ); DataSourceManager.RegisterDataSources(); FileIndexerManager.RegisterFileIndexers(); }
/// <summary> /// Adds the given JToken to the specified Document. /// </summary> /// <param name="doc"> /// The Document to add to. /// </param> /// <param name="prefix"> /// The prefix to use for field names. /// </param> /// <param name="token"> /// The JToken to add. /// </param> /// <param name="fieldconfig"></param> private static void Add(Document doc, string prefix, JToken token, FieldConfig fieldconfig) { if (token is JObject) { AddProperties(doc, prefix, token as JObject, fieldconfig); } else if (token is JArray) { var itemsConfig = fieldconfig?.Items; if (fieldconfig != null && fieldconfig.Index && itemsConfig == null) { throw new Exception($"Error indexing Array field {prefix}. No 'Items' section defined in index.json. Please fix your index.json."); } AddArray(doc, prefix, token as JArray, itemsConfig); } else if (token is JValue) { JValue value = token as JValue; bool index = false; bool sort = false; if (fieldconfig != null) { index = fieldconfig.Index; sort = fieldconfig.Sort; } switch (value.Type) //todo: simple date gets detected as string { case JTokenType.Boolean: if (index || sort) { doc.Add(new NumericField(prefix, Field.Store.NO, true).SetIntValue((bool)value.Value ? 1 : 0)); } break; case JTokenType.Date: if (index || sort) { doc.Add(new NumericField(prefix, Field.Store.NO, true).SetLongValue(((DateTime)value.Value).Ticks)); //doc.Add(new Field(prefix, DateTools.DateToString((DateTime)value.Value, DateTools.Resolution.SECOND), Field.Store.NO, Field.Index.NOT_ANALYZED)); /* * if (field != null ){ * if (field.IndexType == "datetime") * { * doc.Add(new Field(prefix, DateTools.DateToString((DateTime)value.Value, DateTools.Resolution.SECOND), Field.Store.NO, Field.Index.NOT_ANALYZED)); * } * else if (field.IndexType == "date") * { * doc.Add(new Field(prefix, DateTools.DateToString((DateTime)value.Value, DateTools.Resolution.DAY), Field.Store.NO, Field.Index.NOT_ANALYZED)); * } * else if (field.IndexType == "time") * { * doc.Add(new Field(prefix, DateTools.DateToString((DateTime)value.Value, DateTools.Resolution.SECOND).Substring(8), Field.Store.NO, Field.Index.NOT_ANALYZED)); * } * } * else * { * doc.Add(new Field(prefix, DateTools.DateToString((DateTime)value.Value, DateTools.Resolution.SECOND), Field.Store.NO, Field.Index.NOT_ANALYZED)); * } */ } break; case JTokenType.Float: if (index || sort) { if (value.Value is float) { doc.Add(new NumericField(prefix, Field.Store.NO, true).SetFloatValue((float)value.Value)); } else { doc.Add(new NumericField(prefix, Field.Store.NO, true).SetFloatValue((float)Convert.ToDouble(value.Value))); //doc.Add(new NumericField(prefix, Field.Store.NO, true).SetDoubleValue(Convert.ToDouble(value.Value))); } } break; case JTokenType.Guid: if (index || sort) { doc.Add(new Field(prefix, value.Value.ToString(), Field.Store.NO, Field.Index.NOT_ANALYZED)); } break; case JTokenType.Integer: if (index || sort) { doc.Add(new NumericField(prefix, Field.Store.NO, true).SetFloatValue((float)Convert.ToInt64(value.Value))); //doc.Add(new NumericField(prefix, Field.Store.NO, true).SetLongValue(Convert.ToInt64(value.Value))); } break; case JTokenType.Null: break; case JTokenType.String: if (fieldconfig != null && fieldconfig.IndexType == "key") { doc.Add(new Field(prefix, QueryParser.Escape(value.Value.ToString()), Field.Store.NO, Field.Index.NOT_ANALYZED)); } else if (fieldconfig != null && fieldconfig.IndexType == "html") { if (index) { doc.Add(new Field(prefix, CleanHtml(value.Value.ToString(), true), Field.Store.NO, Field.Index.ANALYZED)); } if (sort) { doc.Add(new Field("@" + prefix, CleanHtml(Truncate(value.Value.ToString(), 100), true), Field.Store.NO, Field.Index.NOT_ANALYZED)); } } else if (fieldconfig != null && fieldconfig.IndexType == "file") { var val = value.Value.ToString(); if (!string.IsNullOrEmpty(val)) { var fileIndexer = FileIndexerManager.GetFileIndexer(val); if (fileIndexer != null) { var content = fileIndexer.GetContent(val); if (index) { doc.Add(new Field(prefix, content, Field.Store.NO, Field.Index.ANALYZED)); } if (sort) { doc.Add(new Field("@" + prefix, Truncate(content, 100), Field.Store.NO, Field.Index.NOT_ANALYZED)); } } } } else { if (index) { doc.Add(new Field(prefix, value.Value.ToString(), Field.Store.NO, Field.Index.ANALYZED)); } if (sort) { doc.Add(new Field("@" + prefix, Truncate(value.Value.ToString(), 100), Field.Store.NO, Field.Index.NOT_ANALYZED)); } } break; case JTokenType.TimeSpan: if (index || sort) { doc.Add(new NumericField(prefix, Field.Store.NO, true).SetLongValue(((TimeSpan)value.Value).Ticks)); } break; case JTokenType.Uri: if (index || sort) { doc.Add(new Field(prefix, value.Value.ToString(), Field.Store.NO, Field.Index.ANALYZED)); } break; default: Debug.Fail("Unsupported JValue type: " + value.Type); break; } } else { Debug.Fail("Unsupported JToken: " + token); } }