示例#1
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);
        }
示例#2
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());
        }
示例#3
0
        public void SolrDIHStatusParsing()
        {
            var           DIHStatusParser = new SolrDIHStatusParser();
            var           xml             = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.solrDIHStatusBasic.xml");
            SolrDIHStatus dihStatusDoc    = DIHStatusParser.Parse(xml);

            Assert.AreEqual(1, dihStatusDoc.TotalRequestToDataSource);
            Assert.AreEqual(DateTime.Parse("2010-12-09 00:00:00"), dihStatusDoc.Committed);
            Assert.AreEqual(DateTime.Parse("2010-12-09 00:00:00"), dihStatusDoc.FullDumpStarted);
            Assert.AreEqual("", dihStatusDoc.ImportResponse);
            Assert.AreEqual(DateTime.Parse("2010-12-09 00:00:00"), dihStatusDoc.Optimized);
            Assert.AreEqual(DIHStatus.IDLE, dihStatusDoc.Status);
            Assert.AreEqual("Indexing completed. Added/Updated: 764648 documents. Deleted 0 documents.", dihStatusDoc.Summary.Trim());
            Assert.AreEqual(new TimeSpan(), dihStatusDoc.TimeElapsed);
            Assert.AreEqual(new TimeSpan(0, 0, 9, 48, 65), dihStatusDoc.TimeTaken);
            Assert.AreEqual(735352, dihStatusDoc.TotalDocumentsFailed);
            Assert.AreEqual(764648, dihStatusDoc.TotalDocumentsProcessed);
            Assert.AreEqual(0, dihStatusDoc.TotalDocumentsSkipped);
            Assert.AreEqual(1500000, dihStatusDoc.TotalRowsFetched);
        }
        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();
        }