public void Alias() { var coreName = "core-new"; var headerParser = new HeaderResponseParser<string>(); var solrCoreAdmin = new SolrCoreAdmin(new SolrConnection(solrUrl), headerParser); var aliasResponseHeader = solrCoreAdmin.Alias(coreName, "corefoo"); Assert.AreEqual(aliasResponseHeader.Status, 0); }
public void ParseResponseHeader() { var parser = new HeaderResponseParser <TestDocument>(); var xml = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.response.xml"); var docNode = xml.XPathSelectElement("response/lst[@name='responseHeader']"); var header = parser.ParseHeader(docNode); Assert.AreEqual(1, header.Status); Assert.AreEqual(15, header.QTime); Assert.AreEqual(2, header.Params.Count); Assert.AreEqual("id:123456", header.Params["q"]); Assert.AreEqual("2.2", header.Params["version"]); }
public void CreateSwapCore() { var coreName = "core-swap"; var headerParser = new HeaderResponseParser<string>(); var solrCoreAdmin = new SolrCoreAdmin(new SolrConnection(solrUrl), headerParser); var createResponseHeader = solrCoreAdmin.Create(coreName, instanceDir); Assert.AreEqual(createResponseHeader.Status, 0); var results = solrCoreAdmin.Status(coreName); Assert.IsNotEmpty(results); Assert.IsNotEmpty(results[0].Name); Assert.AreEqual(coreName, results[0].Name); }
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 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()); }
private void PrepareCollections(string[] collectionNames) { const string solrUrl = "http://localhost:8983/solr"; //var headerParser = ServiceLocator.Current.GetInstance<ISolrHeaderResponseParser>(); var headerParser = new HeaderResponseParser(); ISolrCollectionsAdmin solrCollectionsAdmin = new SolrCollectionsAdmin(new SolrConnection(solrUrl), headerParser); var collections = solrCollectionsAdmin.ListCollections(); foreach (var collectionName in collectionNames) { if (!collections.Contains(collectionName)) { solrCollectionsAdmin.CreateCollection(collectionName, numShards: 1); } } }
public void Create() { var coreName = "core-new"; var headerParser = new HeaderResponseParser<string>(); var solrCoreAdmin = new SolrCoreAdmin(new SolrConnection(solrUrl), headerParser); try { var createResponseHeader = solrCoreAdmin.Create(coreName, null, null, null, null); } catch (ArgumentException) { // Should get an Exception here because instance directory was not specified. var createResponseHeader = solrCoreAdmin.Create(coreName, instanceDir); Assert.AreEqual(createResponseHeader.Status, 0); } var results = solrCoreAdmin.Status(coreName); Assert.IsNotEmpty(results); Assert.IsNotEmpty(results[0].Name); Assert.AreEqual(coreName, results[0].Name); }
public static AuthAdminSolrServer <T> CreateSolrServer(string connectionString, string coreIndex, IndexType indexType = IndexType.Solr) { var connection = BuildConnection.CreateSolrConnection(connectionString + coreIndex, indexType); var docSerializer = new SolrDocumentSerializer <T>(new AttributesMappingManager(), new DefaultFieldSerializer()); var headerResponseParser = new HeaderResponseParser <T>(); var solrFieldSerializer = new DefaultFieldSerializer(); var mapper = new AttributesMappingManager(); var dparser = new SolrDocumentResponseParser <T>(mapper, new DefaultDocumentVisitor(mapper, new DefaultFieldParser()), new SolrDocumentActivator <T>()); var parser = new DefaultResponseParser <T>(dparser); var querySerializer = new DefaultQuerySerializer(solrFieldSerializer); var facetQuerySerializer = new DefaultFacetQuerySerializer(querySerializer, new DefaultFieldSerializer()); var executer = new SolrQueryExecuter <T>(parser, connection, querySerializer, facetQuerySerializer, null); var basesolr = new SolrBasicServer <T>(connection, executer, docSerializer, null, headerResponseParser, null, null, null); return(new AuthAdminSolrServer <T>(basesolr, null, null)); }
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(); }
public void Unload() { var headerParser = new HeaderResponseParser<string>(); var solrCoreAdmin = new SolrCoreAdmin(new SolrConnection(solrUrl), headerParser); var swapUnloadResponseHeader = solrCoreAdmin.Unload("core-swap", true); Assert.AreEqual(swapUnloadResponseHeader.Status, 0); var newUnloadResponseHeader = solrCoreAdmin.Unload("core-new", true); Assert.AreEqual(newUnloadResponseHeader.Status, 0); }
public void SwapCores() { var headerParser = new HeaderResponseParser<string>(); var solrCoreAdmin = new SolrCoreAdmin(new SolrConnection(solrUrl), headerParser); var swapResponseHeader = solrCoreAdmin.Swap("core-new", "core-swap"); Assert.AreEqual(swapResponseHeader.Status, 0); }
public void ReloadCore() { var coreName = "core-new"; var headerParser = new HeaderResponseParser<string>(); var solrCoreAdmin = new SolrCoreAdmin(new SolrConnection(solrUrl), headerParser); var reloadResponseHeader = solrCoreAdmin.Reload(coreName); Assert.AreEqual(reloadResponseHeader.Status, 0); }