Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add engine/elastic/elasric.py file with ElasticEngine realization
- Loading branch information
Showing
27 changed files
with
10,629 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .elastic import ElasticEngine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from typing import List, Dict, Any | ||
|
||
from elasticsearch import Elasticsearch | ||
|
||
|
||
class ElasticEngine: | ||
es: Elasticsearch | ||
doc_type: str = "sentence" | ||
|
||
def __init__(self, host: str, **kwargs): | ||
self.es = Elasticsearch(host=host, **kwargs) | ||
|
||
def add_index(self, name: str, number_of_shards: int = 1, number_of_replicas: int = 2): | ||
self.es.indices.create(index=name, body={ | ||
"settings": { | ||
"index": { | ||
"number_of_shards": number_of_shards, | ||
"number_of_replicas": number_of_replicas, | ||
"analysis": { | ||
"analyzer": { | ||
"t9_analyzer": { | ||
"type": "custom", | ||
"tokenizer": "standard", | ||
"filter": [ | ||
"lowercase", | ||
"custom_edge_ngram" | ||
] | ||
} | ||
}, | ||
"filter": { | ||
"custom_edge_ngram": { | ||
"type": "edge_ngram", | ||
"min_gram": 2, | ||
"max_gram": 10 | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"mappings": { | ||
self.doc_type: { | ||
"properties": { | ||
"text": { | ||
"type": "text", | ||
"analyzer": "t9_analyzer", | ||
"search_analyzer": "standard" | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
|
||
def add_doc(self, index_name: str, text: str): | ||
self.es.index(index=index_name, doc_type=self.doc_type, body={ | ||
'text': text | ||
}) | ||
|
||
def get(self, index_name: str, phrase: str, count: int = 10) -> List[str]: | ||
return [ | ||
doc['_source']['text'] | ||
for doc in self.es.search( | ||
index=index_name, | ||
doc_type=self.doc_type, | ||
body={ | ||
"query": { | ||
"match_phrase": { | ||
"text": phrase | ||
} | ||
}, | ||
"size": count | ||
})['hits']['hits'] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .ngrams_text_generator import NgrammTextGenerator | ||
from .utils import PostgresStorage |
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
markov/legacy/chain_storage.py → engine/markov/legacy/chain_storage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
markov/legacy/encoder_storage.py → engine/markov/legacy/encoder_storage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
markov/legacy/habr_storage.py → engine/markov/legacy/habr_storage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.