示例#1
0
        public void DefaultFieldParser_EnumAsString()
        {
            var p   = new DefaultFieldParser();
            var xml = new XDocument();

            xml.Add(new XElement("str", "One"));
            var r = p.Parse(xml.Root, typeof(Numbers));

            Assert.IsInstanceOfType(typeof(Numbers), r);
        }
示例#2
0
        public void ParseLocation()
        {
            var doc = new XDocument();

            doc.Add(new XElement("str", "31.2,-44.2"));
            var p = new DefaultFieldParser();
            var l = p.Parse(doc.Root, typeof(Location));

            Assert.IsInstanceOf <Location>(l);
        }
示例#3
0
        public void SupportGuid()
        {
            var p   = new DefaultFieldParser();
            var g   = Guid.NewGuid();
            var xml = new XDocument();

            xml.Add(new XElement("str", g.ToString()));
            var r  = p.Parse(xml.Root, typeof(Guid));
            var pg = (Guid)r;

            Assert.AreEqual(g, pg);
        }
        public void Parse()
        {
            var mapper      = new AttributesMappingManager();
            var fieldParser = new DefaultFieldParser();
            var docVisitor  = new DefaultDocumentVisitor(mapper, fieldParser);
            var docParser   = new SolrDocumentResponseParser <Product>(mapper, docVisitor, new SolrDocumentActivator <Product>());
            var p           = new MoreLikeThisHandlerMatchResponseParser <Product>(docParser);
            var mltResults  = new SolrMoreLikeThisHandlerResults <Product>();
            var xml         = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.responseWithMLTHandlerMatch.xml");

            p.Parse(xml, mltResults);
            Assert.IsNotNull(mltResults.Match);
        }
示例#5
0
        public void ParseNullableInt()
        {
            var doc = new XDocument();

            doc.Add(new XElement("int", "31"));
            var p = new DefaultFieldParser();
            var i = p.Parse(doc.Root, typeof(int?));

            Assert.IsInstanceOf <int?>(i);
            var ii = (int?)i;

            Assert.IsTrue(ii.HasValue);
            Assert.AreEqual(31, ii.Value);
        }
示例#6
0
文件: SolrNet.cs 项目: vladen/SolrNet
        public static ISolrBasicOperations <T> GetBasicServer <T>(ISolrConnection connection)
        {
            ISolrFieldParser             fieldParser = new DefaultFieldParser();
            IReadOnlyMappingManager      mapper      = new MemoizingMappingManager(new AttributesMappingManager());
            ISolrDocumentPropertyVisitor visitor     = new DefaultDocumentVisitor(mapper, fieldParser);

            ISolrDocumentResponseParser <T> parser;

            if (typeof(T) == typeof(Dictionary <string, object>))
            {
                parser = (ISolrDocumentResponseParser <T>) new SolrDictionaryDocumentResponseParser(fieldParser);
            }
            else
            {
                parser = new SolrDocumentResponseParser <T>(mapper, visitor, new SolrDocumentActivator <T>());
            }

            ISolrAbstractResponseParser <T> resultParser = new DefaultResponseParser <T>(parser);

            ISolrFieldSerializer fieldSerializer = new DefaultFieldSerializer();

            ;
            ISolrQuerySerializer      querySerializer      = new DefaultQuerySerializer(fieldSerializer);
            ISolrFacetQuerySerializer facetQuerySerializer = new DefaultFacetQuerySerializer(querySerializer, fieldSerializer);
            // validate why only this?
            ISolrMoreLikeThisHandlerQueryResultsParser <T> mlthResultParser = new SolrMoreLikeThisHandlerQueryResultsParser <T>(new[] { resultParser });

            ISolrQueryExecuter <T> executor = new SolrQueryExecuter <T>(resultParser, connection, querySerializer, facetQuerySerializer, mlthResultParser);

            ISolrDocumentSerializer <T> documentSerializer;

            if (typeof(T) == typeof(Dictionary <string, object>))
            {
                documentSerializer = (ISolrDocumentSerializer <T>) new SolrDictionarySerializer(fieldSerializer);
            }
            else
            {
                documentSerializer = new SolrDocumentSerializer <T>(mapper, fieldSerializer);
            }

            ISolrSchemaParser          schemaParser          = new SolrSchemaParser();
            ISolrHeaderResponseParser  headerParser          = new HeaderResponseParser <T>();
            ISolrDIHStatusParser       dihStatusParser       = new SolrDIHStatusParser();
            ISolrExtractResponseParser extractResponseParser = new ExtractResponseParser(headerParser);

            ISolrBasicOperations <T> basicServer = new SolrBasicServer <T>(connection, executor, documentSerializer, schemaParser, headerParser, querySerializer, dihStatusParser, extractResponseParser);

            return(basicServer);
        }
示例#7
0
        public void ParseNullableInt()
        {
            var doc = new XDocument();

            doc.Add(new XElement("int", "31"));
            var p = new DefaultFieldParser();
            var i = p.Parse(doc.Root, typeof(int?));

            Assert.IsAssignableFrom(typeof(int?), i);
            Assert.IsType(typeof(int), i);
            var ii = (int?)i;

            Assert.True(ii.HasValue);
            Assert.Equal(31, ii.Value);
        }
示例#8
0
        public static void InitContainer()
        {
            ServiceLocator.SetLocatorProvider(() => Container);
            Container.Clear();
            var mapper = new MemoizingMappingManager(new AttributesMappingManager());

            Container.Register <IReadOnlyMappingManager>(c => mapper);

            var fieldParser = new DefaultFieldParser();

            Container.Register <ISolrFieldParser>(c => fieldParser);

            var fieldSerializer = new DefaultFieldSerializer();

            Container.Register <ISolrFieldSerializer>(c => fieldSerializer);

            Container.Register <ISolrQuerySerializer>(c => new DefaultQuerySerializer(c.GetInstance <ISolrFieldSerializer>()));
            Container.Register <ISolrFacetQuerySerializer>(c => new DefaultFacetQuerySerializer(c.GetInstance <ISolrQuerySerializer>(), c.GetInstance <ISolrFieldSerializer>()));

            Container.Register <ISolrDocumentPropertyVisitor>(c => new DefaultDocumentVisitor(c.GetInstance <IReadOnlyMappingManager>(), c.GetInstance <ISolrFieldParser>()));

            //var cache = new HttpRuntimeCache();
            //Container.Register<ISolrCache>(c => cache);

            var solrSchemaParser = new SolrSchemaParser();

            Container.Register <ISolrSchemaParser>(c => solrSchemaParser);

            var solrDIHStatusParser = new SolrDIHStatusParser();

            Container.Register <ISolrDIHStatusParser>(c => solrDIHStatusParser);

            var headerParser = new HeaderResponseParser <string>();

            Container.Register <ISolrHeaderResponseParser>(c => headerParser);

            var extractResponseParser = new ExtractResponseParser(headerParser);

            Container.Register <ISolrExtractResponseParser>(c => extractResponseParser);

            Container.Register <IValidationRule>(typeof(MappedPropertiesIsInSolrSchemaRule).FullName, c => new MappedPropertiesIsInSolrSchemaRule());
            Container.Register <IValidationRule>(typeof(RequiredFieldsAreMappedRule).FullName, c => new RequiredFieldsAreMappedRule());
            Container.Register <IValidationRule>(typeof(UniqueKeyMatchesMappingRule).FullName, c => new UniqueKeyMatchesMappingRule());
            Container.Register <IValidationRule>(typeof(MultivaluedMappedToCollectionRule).FullName, c => new MultivaluedMappedToCollectionRule());
            Container.Register <IMappingValidator>(c => new MappingValidator(c.GetInstance <IReadOnlyMappingManager>(), c.GetAllInstances <IValidationRule>().ToArray()));

            Container.Register <ISolrStatusResponseParser>(c => new SolrStatusResponseParser());
        }
        public DefaultSolrLocator()
        {
            MappingManager          = new MemoizingMappingManager(new AttributesMappingManager());
            FieldParser             = new DefaultFieldParser();
            DocumentPropertyVisitor = new DefaultDocumentVisitor(MappingManager, FieldParser);

            if (typeof(T) == typeof(Dictionary <string, object>))
            {
                DocumentResponseParser =
                    (ISolrDocumentResponseParser <T>) new SolrDictionaryDocumentResponseParser(FieldParser);
            }
            else
            {
                DocumentResponseParser = new SolrDocumentResponseParser <T>(MappingManager, DocumentPropertyVisitor,
                                                                            new SolrDocumentActivator <T>());
            }

            ResponseParser        = new DefaultResponseParser <T>(DocumentResponseParser);
            SchemaParser          = new SolrSchemaParser();
            HeaderParser          = new HeaderResponseParser <string>();
            DihStatusParser       = new SolrDIHStatusParser();
            ExtractResponseParser = new ExtractResponseParser(HeaderParser);
            FieldSerializer       = new DefaultFieldSerializer();

            QuerySerializer      = new DefaultQuerySerializer(FieldSerializer);
            FacetQuerySerializer = new DefaultFacetQuerySerializer(QuerySerializer, FieldSerializer);
            MlthResultParser     = new SolrMoreLikeThisHandlerQueryResultsParser <T>(new[] { ResponseParser });
            StatusResponseParser = new SolrStatusResponseParser();

            if (typeof(T) == typeof(Dictionary <string, object>))
            {
                DocumentSerializer = (ISolrDocumentSerializer <T>) new SolrDictionarySerializer(FieldSerializer);
            }
            else
            {
                DocumentSerializer = new SolrDocumentSerializer <T>(MappingManager, FieldSerializer);
            }

            HttpCache = new NullCache();
        }
示例#10
0
        public void CanHandleType(Type t)
        {
            var p = new DefaultFieldParser();

            Assert.IsTrue(p.CanHandleType(t));
        }
示例#11
0
        public void CanHandleSolrTypes(string solrType)
        {
            var p = new DefaultFieldParser();

            Assert.IsTrue(p.CanHandleSolrType(solrType));
        }