linkml_store.api.stores.solr.solr_collection module
- class SolrCollection(name, parent=None, metadata=None, **kwargs)[source]
Bases:
Collection
- search(query, where=None, index_name=None, limit=None, **kwargs)[source]
Search the collection using a text-based index index.
Example:
>>> from linkml_store import Client >>> from linkml_store.utils.format_utils import load_objects >>> client = Client() >>> db = client.attach_database("duckdb") >>> collection = db.create_collection("Country") >>> objs = load_objects("tests/input/countries/countries.jsonl") >>> collection.insert(objs)
Now let’s index, using the simple trigram-based index
>>> index = get_indexer("simple") >>> _ = collection.attach_indexer(index)
Now let’s find all objects:
>>> qr = collection.search("France") >>> score, top_obj = qr.ranked_rows[0] >>> assert score > 0.1 >>> top_obj["code"] 'FR'
- Parameters:
query (
str
)where (
Optional
[Any
])index_name (
Optional
[str
])limit (
Optional
[int
])kwargs
- Return type:
QueryResult
- Returns:
- query(query, **kwargs)[source]
Run a query against the collection.
First let’s load a collection:
>>> from linkml_store import Client >>> from linkml_store.utils.format_utils import load_objects >>> client = Client() >>> db = client.attach_database("duckdb") >>> collection = db.create_collection("Country") >>> objs = load_objects("tests/input/countries/countries.jsonl") >>> collection.insert(objs)
Now let’s run a query:
TODO
- Parameters:
query (
Query
)kwargs
- Return type:
QueryResult
- Returns:
- query_facets(where=None, facet_columns=None, facet_limit=100, **kwargs)[source]
Run a query to get facet counts for one or more columns.
This function takes a database connection, a Query object, and a list of column names. It generates and executes a facet count query for each specified column and returns the results as a dictionary where the keys are the column names and the values are pandas DataFrames containing the facet counts.
The facet count query is generated by modifying the original query’s WHERE clause to exclude conditions directly related to the facet column. This allows for counting the occurrences of each unique value in the facet column while still applying the other filtering conditions.
- Parameters:
con – A DuckDB database connection.
query – A Query object representing the base query.
facet_columns (
Optional
[List
[str
]]) – A list of column names to get facet counts for.facet_limit
- Return type:
Dict
[str
,Dict
[str
,int
]]- Returns:
A dictionary where keys are column names and values are tuples containing the facet counts for each unique value in the respective column.