Skip to content

Commit

Permalink
checking if index exist already
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Loembe committed Jun 10, 2024
1 parent 7afe90d commit 91514fc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions python/nistoar/midas/dbio/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ def connect(self):
self._mngocli.get_database = self._mngocli.get_default_database

self._native = self._mngocli.get_database()
# Create the index
#coll.create_index([("$**", "text")],
# {"default_language": "dummy", "weights": {"title": 1, "keyword": 2}})



def disconnect(self):
"""
Expand Down Expand Up @@ -229,7 +226,10 @@ def adv_select_records(self, filter: dict,
filter["$and"].append(constraints)
try:
coll = self.native[self._projcoll]
coll.create_index([("$**", "text")],weights= {"name": 2, "data.keywords": 3})
index_info = coll.list_indexes()
index_exists = any(idx['name'] == 'name_text_data.keywords_text' for idx in index_info)
if not index_exists:
coll.create_index([("$**", "text")],weights= {"name": 2, "data.keywords": 3})
for rec in coll.find(filter, {'_id': False}):
yield base.ProjectRecord(self._projcoll, rec, self)

Expand Down

0 comments on commit 91514fc

Please sign in to comment.