Exemplo n.º 1
0
        public void ParseMlthMatch()
        {
            var innerParser = new MoreLikeThisHandlerMatchResponseParser <TestDocWithGuid>(GetDocumentParser <TestDocWithGuid>());
            var parser      = new SolrMoreLikeThisHandlerQueryResultsParser <TestDocWithGuid>(new[] { innerParser });
            var response    = EmbeddedResource.GetEmbeddedString(GetType(), "Resources.responseWithInterestingTermsDetails.xml");
            var results     = parser.Parse(response);

            Assert.IsNotNull(results);
            Assert.IsNotNull(results.Match);
            Assert.AreEqual(new Guid("224fbdc1-12df-4520-9fbe-dd91f916eba1"), results.Match.Key);
        }
Exemplo n.º 2
0
        public void ParseInterestingTermsDetails()
        {
            var innerParser = new InterestingTermsResponseParser <Product>();
            var parser      = new SolrMoreLikeThisHandlerQueryResultsParser <Product>(new[] { innerParser });
            var response    = EmbeddedResource.GetEmbeddedString(GetType(), "Resources.responseWithInterestingTermsDetails.xml");
            var results     = parser.Parse(response);

            Assert.IsNotNull(results);
            Assert.IsNotNull(results.InterestingTerms);
            Assert.AreEqual(4, results.InterestingTerms.Count);
            Assert.AreEqual("content:three", results.InterestingTerms[2].Key);
            Assert.AreEqual(3.3f, results.InterestingTerms[2].Value);
        }
Exemplo n.º 3
0
        public void ParseInterestingTermsList()
        {
            var innerParser = new InterestingTermsResponseParser <Product>();
            var parser      = new SolrMoreLikeThisHandlerQueryResultsParser <Product>(new[] { innerParser });
            var response    = EmbeddedResource.GetEmbeddedString(GetType(), "Resources.responseWithInterestingTermsList.xml");
            var results     = parser.Parse(response);

            Assert.NotNull(results);
            Assert.NotNull(results.InterestingTerms);
            Assert.Equal(4, results.InterestingTerms.Count);
            Assert.Equal("three", results.InterestingTerms[2].Key);
            Assert.True(results.InterestingTerms.All(t => t.Value == 0.0f));
        }
Exemplo n.º 4
0
        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);
        }
        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();
        }