@@ -54,6 +54,7 @@ class SolrClientConfig:
5454 core : str
5555 user : Optional [SolrUser ] = None
5656 timeout : int = 600
57+ major_version : str = "9"
5758 configset : str = "_default"
5859
5960 @classmethod
@@ -63,6 +64,7 @@ def from_env(cls) -> SolrClientConfig:
6364 core = os .environ .get ("SOLR_CORE" , "renku-search" )
6465 username = os .environ .get ("SOLR_USER" )
6566 password = os .environ .get ("SOLR_PASSWORD" )
67+ maj_version = os .environ .get ("SOLR_MAJOR_VERSION" , "9" )
6668
6769 tstr = os .environ .get ("SOLR_REQUEST_TIMEOUT" , "600" )
6870 try :
@@ -72,7 +74,7 @@ def from_env(cls) -> SolrClientConfig:
7274 timeout = 600
7375
7476 user = SolrUser (username = username , password = str (password )) if username is not None else None
75- return cls (url , core , user , timeout )
77+ return cls (url , core , user , timeout , maj_version )
7678
7779 def __str__ (self ) -> str :
7880 return (
@@ -792,10 +794,23 @@ async def core_status(self, core_name: str | None) -> dict[str, Any] | None:
792794 # if the core doesn't exist, solr returns 200 with an empty body
793795 return data if data .get ("name" ) == self .config .core else None
794796
797+ async def create_collection (self , coll_name : str | None ) -> None :
798+ """Create a collection with the given name or the name from the config object."""
799+ coll = coll_name or self .config .core
800+ data = {"name" : coll , "numShards" : 1 }
801+ resp = await self .delegate .post ("/api/collections" , json = data )
802+ if not resp .is_success :
803+ raise SolrClientCreateCoreException (coll , resp )
804+ else :
805+ return None
806+
795807 async def create (self , core_name : str | None ) -> None :
796808 """Create a core with the given `core_name` or the name provided in the config object."""
797809 core = core_name or self .config .core
798- data = {"create" : {"name" : core , "configSet" : self .config .configset }}
810+ data : dict [str , Any ] = {"create" : {"name" : core , "configSet" : self .config .configset }}
811+ if self .config .major_version == "10" :
812+ await self .create_collection (core )
813+ data = {"name" : core }
799814 resp = await self .delegate .post ("/api/cores" , json = data )
800815 if not resp .is_success :
801816 raise SolrClientCreateCoreException (core , resp )
0 commit comments