Skip to content

Commit 52dab68

Browse files
authored
Merge pull request #49 from teners/add-stopwords
Add stopwords to the client
2 parents 5e13ff1 + 6d7c77f commit 52dab68

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

src/typesense/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from .configuration import Configuration
88
from .api_call import ApiCall
99
from .analytics import Analytics
10+
from .stopwords import Stopwords
1011

1112
class Client(object):
1213
def __init__(self, config_dict):
@@ -19,3 +20,4 @@ def __init__(self, config_dict):
1920
self.analytics = Analytics(self.api_call)
2021
self.operations = Operations(self.api_call)
2122
self.debug = Debug(self.api_call)
23+
self.stopwords = Stopwords(self.api_call)

src/typesense/stopwords.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from .stopwords_set import StopwordsSet
2+
3+
4+
class Stopwords(object):
5+
RESOURCE_PATH = '/stopwords'
6+
7+
def __init__(self, api_call):
8+
self.api_call = api_call
9+
self.stopwords_sets = {}
10+
11+
def __getitem__(self, stopwords_set_id):
12+
if stopwords_set_id not in self.stopwords_sets:
13+
self.stopwords_sets[stopwords_set_id] = StopwordsSet(self.api_call, stopwords_set_id)
14+
15+
return self.stopwords_sets.get(stopwords_set_id)
16+
17+
def upsert(self, stopwords_set_id, stopwords_set):
18+
return self.api_call.put('{}/{}'.format(Stopwords.RESOURCE_PATH, stopwords_set_id), stopwords_set)
19+
20+
def retrieve(self):
21+
return self.api_call.get('{0}'.format(Stopwords.RESOURCE_PATH))

src/typesense/stopwords_set.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class StopwordsSet(object):
2+
def __init__(self, api_call, stopwords_set_id):
3+
self.stopwords_set_id = stopwords_set_id
4+
self.api_call = api_call
5+
6+
def _endpoint_path(self):
7+
from .stopwords import Stopwords
8+
return u"{0}/{1}".format(Stopwords.RESOURCE_PATH, self.stopwords_set_id)
9+
10+
def retrieve(self):
11+
return self.api_call.get(self._endpoint_path())
12+
13+
def delete(self):
14+
return self.api_call.delete(self._endpoint_path())

0 commit comments

Comments
 (0)