Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bw2data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"prepare_lca_inputs",
"ProcessedDataStore",
"projects",
"Searcher",
# "Searcher",
"set_data_dir",
"Weighting",
"weightings",
Expand Down Expand Up @@ -71,7 +71,7 @@
from bw2data.utils import get_activity, get_node
from bw2data.data_store import DataStore, ProcessedDataStore
from bw2data.method import Method
from bw2data.search import Searcher, IndexManager
# from bw2data.search import Searcher, IndexManager
from bw2data.weighting_normalization import Weighting, Normalization
from bw2data.backends import convert_backend, get_id, Node, Edge
from bw2data.compat import prepare_lca_inputs, Mapping, get_multilca_data_objs
Expand Down
40 changes: 23 additions & 17 deletions bw2data/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
)
from bw2data.logs import stdout_feedback_logger
from bw2data.query import Query
from bw2data.search import IndexManager, Searcher
# from bw2data.search import IndexManager, Searcher
from bw2data.signals import on_database_reset, on_database_write
from bw2data.utils import as_uncertainty_dict, get_geocollection, get_node, set_correct_process_type

Expand Down Expand Up @@ -732,20 +732,24 @@ def new_node(self, code: str = None, **kwargs):
return obj

def make_searchable(self, reset: bool = False, signal: bool = True):
if self.name not in databases:
raise UnknownObject("This database is not yet registered")
if self._searchable and not reset:
stdout_feedback_logger.info("This database is already searchable")
return
databases[self.name]["searchable"] = True
databases.flush(signal=signal)
IndexManager(self.filename).create()
IndexManager(self.filename).add_datasets(self)
return

# if self.name not in databases:
# raise UnknownObject("This database is not yet registered")
# if self._searchable and not reset:
# stdout_feedback_logger.info("This database is already searchable")
# return
# databases[self.name]["searchable"] = True
# databases.flush(signal=signal)
# IndexManager(self.filename).create()
# IndexManager(self.filename).add_datasets(self)

def make_unsearchable(self, signal: bool = True):
databases[self.name]["searchable"] = False
databases.flush(signal=signal)
IndexManager(self.filename).delete_database()
return

# databases[self.name]["searchable"] = False
# databases.flush(signal=signal)
# IndexManager(self.filename).delete_database()

def delete(
self, keep_params: bool = False, warn: bool = True, vacuum: bool = True, signal: bool = True
Expand Down Expand Up @@ -785,7 +789,7 @@ def purge(dct: dict) -> dict:

ActivityDataset.delete().where(ActivityDataset.database == self.name).execute()
ExchangeDataset.delete().where(ExchangeDataset.output_database == self.name).execute()
IndexManager(self.filename).delete_database()
# IndexManager(self.filename).delete_database()

if not keep_params:
from bw2data.parameters import (
Expand Down Expand Up @@ -1003,9 +1007,11 @@ def search(self, string, **kwargs):
* ``proxy``: Return ``Activity`` proxies instead of dictionary index Models. Default is ``True``.

Returns a list of ``Activity`` datasets."""
with Searcher(self.filename) as s:
results = s.search(string=string, **kwargs)
return results
raise NotImplementedError

# with Searcher(self.filename) as s:
# results = s.search(string=string, **kwargs)
# return results

def set_geocollections(self):
"""Set ``geocollections`` attribute for databases which don't currently have it."""
Expand Down
20 changes: 10 additions & 10 deletions bw2data/backends/proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from bw2data.errors import ValidityError
from bw2data.logs import stdout_feedback_logger
from bw2data.proxies import ActivityProxyBase, ExchangeProxyBase
from bw2data.search import IndexManager
# from bw2data.search import IndexManager
from bw2data.signals import on_activity_code_change, on_activity_database_change


Expand Down Expand Up @@ -281,7 +281,7 @@ def purge(obj: Activity, dct: dict) -> dict:
).execute()
except ActivityParameter.DoesNotExist:
pass
IndexManager(Database(self["database"]).filename).delete_dataset(self._data)
# IndexManager(Database(self["database"]).filename).delete_dataset(self._data)
self.exchanges().delete(allow_in_sourced_project=True)
self.upstream().delete(allow_in_sourced_project=True)

Expand Down Expand Up @@ -352,8 +352,8 @@ def save(self, signal: bool = True, data_already_set: bool = False, force_insert
if self.get("location") and self["location"] not in geomapping:
geomapping.add([self["location"]])

if databases[self["database"]].get("searchable", True):
IndexManager(Database(self["database"]).filename).update_dataset(self._data)
# if databases[self["database"]].get("searchable", True):
# IndexManager(Database(self["database"]).filename).update_dataset(self._data)

def _change_code(self, new_code: str, signal: bool = True):
if self["code"] == new_code:
Expand Down Expand Up @@ -383,11 +383,11 @@ def _change_code(self, new_code: str, signal: bool = True):
).execute()

if databases[self["database"]].get("searchable"):
from bw2data import Database
# from bw2data import Database

IndexManager(Database(self["database"]).filename).delete_dataset(self)
# IndexManager(Database(self["database"]).filename).delete_dataset(self)
self._data["code"] = new_code
IndexManager(Database(self["database"]).filename).add_datasets([self])
# IndexManager(Database(self["database"]).filename).add_datasets([self])
else:
self._data["code"] = new_code

Expand Down Expand Up @@ -420,11 +420,11 @@ def _change_database(self, new_database: str, signal: bool = True):
).execute()

if databases[self["database"]].get("searchable"):
from bw2data import Database
# from bw2data import Database

IndexManager(Database(self["database"]).filename).delete_dataset(self)
# IndexManager(Database(self["database"]).filename).delete_dataset(self)
self._data["database"] = new_database
IndexManager(Database(self["database"]).filename).add_datasets([self])
# IndexManager(Database(self["database"]).filename).add_datasets([self])
else:
self._data["database"] = new_database

Expand Down
2 changes: 0 additions & 2 deletions bw2data/search/__init__.py

This file was deleted.

125 changes: 0 additions & 125 deletions bw2data/search/indices.py

This file was deleted.

16 changes: 0 additions & 16 deletions bw2data/search/schema.py

This file was deleted.

88 changes: 0 additions & 88 deletions bw2data/search/search.py

This file was deleted.

5 changes: 0 additions & 5 deletions tests/database_querying.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ def test_len_respects_filters(self):
self.db.filters = {"product": "widget"}
self.assertEqual(len(self.db), 2)

def test_make_searchable_unknown_object(self):
db = DatabaseChooser("mysterious")
with self.assertRaises(UnknownObject):
db.make_searchable()

def test_convert_same_backend(self):
database = DatabaseChooser("a database")
database.write(
Expand Down
Loading