SolrConnection
provide the pysolr.Solr
1 client on every call to the get
method. The connection is not being closed when exsiting the "with"
statment.
Example
you_core_lib.yaml
core_lib:
data:
solr:
always_commit: true
url:
host: ${oc.env:SOLR_HOST}
port: ${oc.env:SOLR_PORT}
path: solr
file: your_core
your_core_lib.py
from core_lib.core_lib import CoreLib
from core_lib.connection.solr_connection_registry import SolrConnectionRegistry
class YourCoreLib(CoreLib):
def __init__(self, conf: DictConfig):
CoreLib.__init__(self)
self.config = conf.core_lib
solr_conn = SolrConnectionRegistry(self.config.core_lib.data.solr)
self.search = SearchDataAccess(solr_conn)
search_data_access.py
class SearchDataAccess(DataAccess):
def __init__(self, connection: SolrConnectionRegistry):
self._solr = connection
def search(self, term: str):
with self._solr.get() as session:
query = {'rows': 20}
term_search = '*'
for ch in term:
term_search = term_search + ch + '*'
filter_queries = [
f'name:{term_search}'
]
query['fq'] = filter_queries
return session.search("*:*", **query)
@NotFoundErrorHandler()
def get(self, user_id: int):
with self._solr.get() as session:
query = {'fq': ['user_id:{}'.format(user_id)], 'rows': 1}
result = session.search("*:*", **query)
if result.docs:
return dict(result.docs[0])
def delete(self, user_id: int):
with self._solr.get() as session:
session.delete(user_id=user_id)
SolrConnectionRegistry
core_lib.connection.solr_connection_registry.SolrConnectionRegistry [source]
SolrAlchemyConnectionRegistry
provides a fresh SolrAlchemyConnection
connection in the get()
method.
Functions
__init__()
core_lib.connection.solr_connection_registry.SolrConnectionRegistry.__init__() [source]
Responsible for creating a pysolr.Solr
client from DictConfig
def __init__(self, config: DictConfig):
Arguments
config
(DictConfig)
: Solr section config fromCore-Lib's
config.
get()
core_lib.connection.solr_connection_registry.SolrConnectionRegistry.get() [source]
Returns a fresh SolrConnection
instance.
def get(self, *args, **kwargs) -> SolrConnection:
Arguments
*args, **kwargs
: The args and kwargs of the function.
Returns
(SolrConnection)
: Returns the SolrConnection
instance.
client()
core_lib.connection.solr_connection_registry.SolrConnectionRegistry.client() [source]
Returns the client.
def client(self) -> Solr:
Returns
(Solr)
: Returns the pysolr.Solr
client.
SolrConnection
core_lib.connection.solr_connection.SolrConnection [source]
This class gets the pysolr.Solr
client on initialization.
class SolrConnection(Connection):
def __init__(self, solr_client):
self._solr_client = solr_client
Arguments
solr_client
: Thepysolr.Solr
client is provided using theSolrConnectionRegistry
.