Skip to content

Commit

Permalink
Merge pull request #4 from Dewberry/sliding-window
Browse files Browse the repository at this point in the history
comment out meilisearch import
  • Loading branch information
slawler authored Feb 13, 2023
2 parents 4540d11 + 6486bd0 commit 65136ba
Showing 1 changed file with 90 additions and 89 deletions.
179 changes: 90 additions & 89 deletions storms/utils/ms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from dataclasses_json import dataclass_json
from datetime import datetime, date
from json import dumps
from meilisearch import Client

# from meilisearch import Client
from typing import List
from storms.transpose import Transpose

Expand Down Expand Up @@ -82,94 +83,94 @@ def write_to(self, file_path: str):
f.write(dumps(self.to_dict()))


def list_indexs(client: Client) -> List[str]:
"""
Lists name of all indexes on the client
Parameters
----------
client: meilisearch.Client
meilisearch Client
Return
------
List[str]
"""
return [r.get("uid") for r in client.get_raw_indexes().get("results")]


def upload_docs(client: Client, index: str, docs: List[StormDocument]):
"""
Uploads a list of documents to a meilisearch index.
Parameters
----------
client: meilisearch.Client
meilisearch Client
index: str
index name
primary_key: str
name of index's primary key (default "uid")
docs: List[StormDocument]
list of documents to add to index
"""
client.index(index).add_documents([doc.to_dict() for doc in docs])


def upload_doc(client: Client, index: str, doc: StormDocument):
"""
Uploads a single document to a meilisearch index.
Parameters
----------
client: meilisearch.Client
meilisearch Client
index: str
index name
primary_key: str
name of index's primary key (default "uid")
docs: StormDocument
document to add to index
"""
client.index(index).add_documents([doc.to_dict()])


def build_index(
client: Client,
index: str,
primary_key: str = "uid",
filterable_attributes: List[str] = None,
sortable_attributes: List[str] = None,
):
"""
Builds a meilisearch index if not already existing.
Parameters
----------
client: meilisearch.Client
meilisearch Client
index: str
index name
primary_key: str
name of index's primary key (default "uid")
filterable_attributes: List[str]
names of filterable attributes
sortable_attributes: List[str]
names of sortable attributes
"""
if not [r.get("uid") for r in client.get_raw_indexes().get("results") if r.get("uid") == index]:
client.create_index(index, {"primaryKey": primary_key})

if filterable_attributes:
if filterable_attributes:
client.index(index).update_filterable_attributes(filterable_attributes)

if sortable_attributes:
if sortable_attributes:
client.index(index).update_sortable_attributes(sortable_attributes)

# LOOK INTO DISTINCT ATTRIBUTE
# LOOK INTO RANKING RULES
# def list_indexs(client: Client) -> List[str]:
# """
# Lists name of all indexes on the client

# Parameters
# ----------
# client: meilisearch.Client
# meilisearch Client

# Return
# ------
# List[str]
# """
# return [r.get("uid") for r in client.get_raw_indexes().get("results")]


# def upload_docs(client: Client, index: str, docs: List[StormDocument]):
# """
# Uploads a list of documents to a meilisearch index.

# Parameters
# ----------
# client: meilisearch.Client
# meilisearch Client
# index: str
# index name
# primary_key: str
# name of index's primary key (default "uid")
# docs: List[StormDocument]
# list of documents to add to index
# """
# client.index(index).add_documents([doc.to_dict() for doc in docs])


# def upload_doc(client: Client, index: str, doc: StormDocument):
# """
# Uploads a single document to a meilisearch index.

# Parameters
# ----------
# client: meilisearch.Client
# meilisearch Client
# index: str
# index name
# primary_key: str
# name of index's primary key (default "uid")
# docs: StormDocument
# document to add to index
# """
# client.index(index).add_documents([doc.to_dict()])


# def build_index(
# client: Client,
# index: str,
# primary_key: str = "uid",
# filterable_attributes: List[str] = None,
# sortable_attributes: List[str] = None,
# ):
# """
# Builds a meilisearch index if not already existing.

# Parameters
# ----------
# client: meilisearch.Client
# meilisearch Client
# index: str
# index name
# primary_key: str
# name of index's primary key (default "uid")
# filterable_attributes: List[str]
# names of filterable attributes
# sortable_attributes: List[str]
# names of sortable attributes
# """
# if not [r.get("uid") for r in client.get_raw_indexes().get("results") if r.get("uid") == index]:
# client.create_index(index, {"primaryKey": primary_key})

# if filterable_attributes:
# if filterable_attributes:
# client.index(index).update_filterable_attributes(filterable_attributes)

# if sortable_attributes:
# if sortable_attributes:
# client.index(index).update_sortable_attributes(sortable_attributes)

# # LOOK INTO DISTINCT ATTRIBUTE
# # LOOK INTO RANKING RULES


def _format_datetime(event_start: datetime) -> _StormDocumentDateTime:
Expand Down

0 comments on commit 65136ba

Please sign in to comment.