當前位置: 首頁>>代碼示例>>C#>>正文


C# Mapping.MappingManager類代碼示例

本文整理匯總了C#中SolrNet.Mapping.MappingManager的典型用法代碼示例。如果您正苦於以下問題:C# MappingManager類的具體用法?C# MappingManager怎麽用?C# MappingManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MappingManager類屬於SolrNet.Mapping命名空間,在下文中一共展示了MappingManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AddAndGet

 public void AddAndGet()
 {
     var mgr = new MappingManager();
     mgr.Add(typeof (Entity).GetProperty("Id"), "id");
     var fields = mgr.GetFields(typeof (Entity));
     Assert.AreEqual(1, fields.Count);
 }
開發者ID:nicholaspei,項目名稱:SoleCloudNet,代碼行數:7,代碼來源:MappingManagerTests.cs

示例2: MakeMapper

 private static MappingManager MakeMapper(Type t)
 {
     // See https://github.com/mausch/SolrNet/blob/master/Documentation/Overriding-mapper.md
     var mapper = new MappingManager();
     foreach (var prop in t.GetProperties())
     {
         foreach (Attribute attribute in prop.GetCustomAttributes(true))
         {
             if (attribute is FieldAttribute)
             {
                 var fa = attribute as FieldAttribute;
                 string fieldName = string.IsNullOrWhiteSpace(fa.FieldName) ? prop.Name : fa.FieldName;
                 mapper.Add(prop, fieldName, fa.Boost);
             }
             else if (attribute is SolrFieldAttribute)
             {
                 var fa = attribute as SolrFieldAttribute;
                 string fieldName = string.IsNullOrWhiteSpace(fa.FieldName) ? prop.Name : fa.FieldName;
                 mapper.Add(prop, fieldName, fa.Boost);
             }
             if (attribute is UniqueKeyAttribute)
             {
                 var uka = attribute as UniqueKeyAttribute;
                 mapper.SetUniqueKey(prop);
             }
             if (attribute is SolrUniqueKeyAttribute)
             {
                 var uka = attribute as SolrUniqueKeyAttribute;
                 mapper.SetUniqueKey(prop);
             }
         }
     }
     return mapper;
 }
開發者ID:Crownpeak,項目名稱:Search-Results-Examples,代碼行數:34,代碼來源:Utils.cs

示例3: SetupSolr

        private static void SetupSolr() {
            var connection = new SolrConnection(_httpSolrTest);
            Startup.InitContainer();

            Startup.Container.Remove<IReadOnlyMappingManager>();

            var mapper = new MappingManager();
            Mappings(mapper);
            Startup.Container.Register<IReadOnlyMappingManager>(c => mapper);

            Startup.Container.Remove<ISolrDocumentPropertyVisitor>();
            var propertyVisitor = new DefaultDocumentVisitor(mapper, Startup.Container.GetInstance<ISolrFieldParser>());
            Startup.Container.Register<ISolrDocumentPropertyVisitor>(c => propertyVisitor);

            Startup.Init<Child>(connection);
            Startup.Init<Parent>(connection);
            Startup.Init<Dictionary<string,object>>(connection);
            Startup.Container.RemoveAll<ISolrDocumentResponseParser<Dictionary<string, object>>>();
            Startup.Container.Register<ISolrDocumentResponseParser<Dictionary<string, object>>>(c => new SolrDictionaryDocumentResponseParser(c.GetInstance<ISolrFieldParser>()));

            var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Child>>();

            solr.Delete(SolrQuery.All);
            solr.Commit();
        }
開發者ID:FilipVV,項目名稱:SolrNet,代碼行數:25,代碼來源:IntegrationTests2.cs

示例4: MappingTypesAreCompatibleWithSolrTypesRule_with_nonexistant_rule

 public void MappingTypesAreCompatibleWithSolrTypesRule_with_nonexistant_rule()
 {
     var rule = new MappingTypesAreCompatibleWithSolrTypesRule(new[] {new StringSolrFieldTypeChecker()});
     var mappingManager = new MappingManager();
     mappingManager.Add(typeof (SchemaMappingTestDocument).GetProperty("Name"));
     var validations = rule.Validate(typeof (SchemaMappingTestDocument), new SolrSchema(), mappingManager).ToList();
 }
開發者ID:holytshirt,項目名稱:SolrNet,代碼行數:7,代碼來源:MappingTypesAreCompatibleWithSolrTypesRuleTests.cs

示例5: Add_duplicate_property_overwrites

 public void Add_duplicate_property_overwrites() {
     var mgr = new MappingManager();
     mgr.Add(typeof (Entity).GetProperty("Id"), "id");
     mgr.Add(typeof (Entity).GetProperty("Id"), "id2");
     var fields = mgr.GetFields(typeof (Entity));
     Assert.AreEqual(1, fields.Count);
     Assert.AreEqual("id2", fields.First().Value.FieldName);
 }
開發者ID:FilipVV,項目名稱:SolrNet,代碼行數:8,代碼來源:MappingManagerTests.cs

示例6: ValidatingRuleSetReturnsValidationResults

        public void ValidatingRuleSetReturnsValidationResults() {
            var mappingManager = new MappingManager();
            var mappingValidationManager = new MappingValidator(mappingManager, new[] {new DummyValidationRuleError()});

            var validationResults = mappingValidationManager.EnumerateValidationResults(typeof(SchemaMappingTestDocument), new SolrSchema()).ToList();

            Assert.AreEqual(1, validationResults.Count);
        }
開發者ID:FilipVV,項目名稱:SolrNet,代碼行數:8,代碼來源:MappingValidatorTests.cs

示例7: Add_property_only

 public void Add_property_only() {
     var mgr = new MappingManager();
     var property = typeof (Entity).GetProperty("Id");
     mgr.Add(property);
     var fields = mgr.GetFields(typeof (Entity));
     Assert.AreEqual(1, fields.Count);
     Assert.AreEqual("Id", fields.First().Value.FieldName);
 }
開發者ID:FilipVV,項目名稱:SolrNet,代碼行數:8,代碼來源:MappingManagerTests.cs

示例8: MappedPropertiesIsInSolrSchemaRule_ignores_score

 public void MappedPropertiesIsInSolrSchemaRule_ignores_score()
 {
     var rule = new MappedPropertiesIsInSolrSchemaRule();
     var mapper = new MappingManager();
     mapper.Add(typeof (SchemaMappingTestDocument).GetProperty("Score"), "score");
     var results = rule.Validate(typeof (SchemaMappingTestDocument), new SolrSchema(), mapper).ToList();
     Assert.IsNotNull(results);
     Assert.AreEqual(0, results.Count);
 }
開發者ID:nicholaspei,項目名稱:SoleCloudNet,代碼行數:9,代碼來源:MappedPropertiesIsInSolrSchemaRuleTests.cs

示例9: UniqueKey_Set_and_get

        public void UniqueKey_Set_and_get() {
            var mgr = new MappingManager();
            var property = typeof (Entity).GetProperty("Id");
            mgr.Add(property, "id");
            mgr.SetUniqueKey(property);
            var key = mgr.GetUniqueKey(typeof (Entity));

            Assert.AreEqual(property, key.Property);
            Assert.AreEqual("id", key.FieldName);
        }
開發者ID:FilipVV,項目名稱:SolrNet,代碼行數:10,代碼來源:MappingManagerTests.cs

示例10: SwappingMappingManager2

 public void SwappingMappingManager2() {
     var mapper = new MappingManager();
     Startup.Container.Clear();
     Startup.InitContainer();
     Startup.Container.RemoveAll<IReadOnlyMappingManager>();
     Startup.Container.Register<IReadOnlyMappingManager>(c => mapper);
     ServiceLocator.SetLocatorProvider(() => Startup.Container);
     Startup.Init<Document>("http://localhost");
     var mapperFromFactory = ServiceLocator.Current.GetInstance<IReadOnlyMappingManager>();
     Assert.AreSame(mapper, mapperFromFactory);
 }
開發者ID:Jo1nes,項目名稱:SolrNet,代碼行數:11,代碼來源:IntegrationTests.cs

示例11: DictionaryFields_are_ignored

 public void DictionaryFields_are_ignored()
 {
     var rule = new MappedPropertiesIsInSolrSchemaRule();
     var mapper = new MappingManager();
     mapper.Add(typeof(SchemaMappingTestDocument).GetProperty("DynamicMapped"), "ma_*");
     var schema = new SolrSchema();
     var fieldType = new SolrFieldType("string", "solr.StrField");
     schema.SolrFields.Add(new SolrField("ma_uaua", fieldType));
     var results = rule.Validate(typeof(SchemaMappingTestDocument), new SolrSchema(), mapper).ToList();
     Assert.AreEqual(0, results.Count);
 }
開發者ID:nicholaspei,項目名稱:SoleCloudNet,代碼行數:11,代碼來源:MappedPropertiesIsInSolrSchemaRuleTests.cs

示例12: StringMappedToStringShouldNotReturnError

        public void StringMappedToStringShouldNotReturnError() {
            var mappingTypesCompatibleRule = new MappingTypesAreCompatibleWithSolrTypesRule(new[] {new StringSolrFieldTypeChecker()});

            var mgr = new MappingManager();
            var schemaManager = new MappingValidator(mgr, new[] {mappingTypesCompatibleRule});

            var schemaXmlDocument = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.solrSchemaMappingTypes.xml");
            var solrSchemaParser = new SolrSchemaParser();
            var schema = solrSchemaParser.Parse(schemaXmlDocument);

            var validationResults = schemaManager.EnumerateValidationResults(typeof (SchemaMappingTestDocument), schema).ToList();
            Assert.AreEqual(0, validationResults.Count);
        }
開發者ID:FilipVV,項目名稱:SolrNet,代碼行數:13,代碼來源:MappingTypesAreCompatibleWithSolrTypesRuleTests.cs

示例13: MultivaluedSolrFieldMappedToCollectionShouldNotReturnError

        public void MultivaluedSolrFieldMappedToCollectionShouldNotReturnError() {
            var mgr = new MappingManager();
            mgr.Add(typeof (SchemaMappingTestDocument).GetProperty("NameCollection"), "name");

            var schemaManager = new MappingValidator(mgr, new[] {new MultivaluedMappedToCollectionRule()});

            var schemaXmlDocument = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.solrSchemaMultiValuedName.xml");
            var solrSchemaParser = new SolrSchemaParser();
            var schema = solrSchemaParser.Parse(schemaXmlDocument);

            var validationResults = schemaManager.EnumerateValidationResults(typeof (SchemaMappingTestDocument), schema).ToList();
            Assert.AreEqual(0, validationResults.Count);
        }
開發者ID:Jo1nes,項目名稱:SolrNet,代碼行數:13,代碼來源:MultivaluedMappedToCollectionRuleTests.cs

示例14: SchemaNull_MappingNotNull_generates_error

 public void SchemaNull_MappingNotNull_generates_error() {
     var rule = new UniqueKeyMatchesMappingRule();
     var mapper = new MappingManager();
     var idProperty = typeof (SchemaMappingTestDocument).GetProperty("ID");
     mapper.Add(idProperty);
     mapper.SetUniqueKey(idProperty);
     var validations = rule.Validate(typeof (SchemaMappingTestDocument), new SolrSchema(), mapper).ToList();
     Assert.IsNotNull(validations);
     Assert.AreEqual(1, validations.Count);
     foreach (var v in validations)
         Console.WriteLine("{0}: {1}", v.GetType(), v.Message);
     Assert.IsInstanceOfType<ValidationError>(validations[0]);
 }
開發者ID:Jo1nes,項目名稱:SolrNet,代碼行數:13,代碼來源:UniqueKeyMatchesMappingRuleTests.cs

示例15: MatchingUniqueKeyMappingShouldNotReturnError

        public void MatchingUniqueKeyMappingShouldNotReturnError() {
            var mgr = new MappingManager();
            mgr.Add(typeof (SchemaMappingTestDocument).GetProperty("ID"), "id");
            mgr.SetUniqueKey(typeof (SchemaMappingTestDocument).GetProperty("ID"));

            var schemaManager = new MappingValidator(mgr, new[] {new UniqueKeyMatchesMappingRule()});

            var schemaXmlDocument = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.solrSchemaBasic.xml");
            var solrSchemaParser = new SolrSchemaParser();
            var schema = solrSchemaParser.Parse(schemaXmlDocument);

            var validationResults = schemaManager.EnumerateValidationResults(typeof (SchemaMappingTestDocument), schema).ToList();
            Assert.AreEqual(0, validationResults.Count);
        }
開發者ID:Jo1nes,項目名稱:SolrNet,代碼行數:14,代碼來源:UniqueKeyMatchesMappingRuleTests.cs


注:本文中的SolrNet.Mapping.MappingManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。