Exemple #1
0
    def _client_search(self):
        try:
            from sonic import SearchClient, IngestClient
        except ImportError:
            j.builder.runtimes.python.pip_package_install("sonic-client")
            from sonic import SearchClient, IngestClient

        if not self._cached_client_search:
            self._cached_client_search = SearchClient(host=self.host, port=self.port, password=self.password)
            self._cached_client_search.connect()
        return self._cached_client_search
class SonicClient(JSConfigClient):
    """
    Sonic server client
    
    usage example:-
    
    data = { 
         'post:1': "this is some test text hello", 
         'post:2': 'this is a hello world post', 
         'post:3': "hello how is it going?", 
         'post:4': "for the love of god?", 
         'post:5': "for the love lorde?", 
     } 
     client = j.clients.sonic.get('main', host="127.0.0.1", port=1491, password='******') 
     for articleid, content in data.items(): 
         client.push("forum", "posts", articleid, content) 
     print(client.query("forum", "posts", "love")) 

    # ['post:5', 'post:4']

    print(client.suggest("forum", "posts", "lo"))                                
    # ['lorde', 'love']



    """

    _SCHEMATEXT = """
        @url =  jumpscale.sonic.client
        name* = "" (S)
        host = "127.0.0.1" (S)
        port = 1491 (I)
        password = "" (S)
        """

    def _init(self):
        self._cached_client_search = None
        self._cached_client_ingest = None

        self.push = self._client_ingest.push
        self.pop = self._client_ingest.pop
        self.count = self._client_ingest.count
        self.flush = self._client_ingest.flush
        self.flush_collection = self._client_ingest.flush_collection
        self.flush_bucket = self._client_ingest.flush_bucket
        self.flush_object = self._client_ingest.flush_object

        self.query = self._client_search.query
        self.suggest = self._client_search.suggest

    @property
    def _client_search(self):
        try:
            from sonic import SearchClient, IngestClient
        except ImportError:
            j.builders.runtimes.python.pip_package_install("sonic-client")
            from sonic import SearchClient, IngestClient

        if not self._cached_client_search:
            self._cached_client_search = SearchClient(host=self.host,
                                                      port=self.port,
                                                      password=self.password)
            self._cached_client_search.connect()
        return self._cached_client_search

    @property
    def _client_ingest(self):
        try:
            from sonic import SearchClient, IngestClient
        except ImportError:
            j.builders.runtimes.python.pip_package_install("sonic-client")
            from sonic import SearchClient, IngestClient

        if not self._cached_client_ingest:
            self._cached_client_ingest = IngestClient(host=self.host,
                                                      port=self.port,
                                                      password=self.password)
            self._cached_client_ingest.connect()
        return self._cached_client_ingest
Exemple #3
0
def search(text: str) -> List[str]:
    with SearchClient(SEARCH_BACKEND_HOST_NAME, SEARCH_BACKEND_PORT, SEARCH_BACKEND_PASSWORD) as querycl:
        snap_ids = querycl.query(SONIC_COLLECTION, SONIC_BUCKET, text)
    return snap_ids
Exemple #4
0
def search(query):
    with SearchClient("127.0.0.1", 1491, "SecretPassword") as querycl:
        return querycl.query("files", "spekter", query)
Exemple #5
0
 def client_search(self):
     if not self.cached_client_search:
         self.cached_client_search = SearchClient(host=self.host, port=self.port, password=self.password)
     return self.cached_client_search
Exemple #6
0
from app.api import app
from config import Config
from flask_mail import Mail
from google.cloud import firestore
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from sonic import SearchClient


delete_field = firestore.DELETE_FIELD
db = firestore.Client()
desc = firestore.Query.DESCENDING
querycl = SearchClient("35.220.150.81", 1491, "YanG981227")
mail = Mail(app)


def create_token(user_id):
    s = Serializer(Config.SECRET_KEY,
                   expires_in=Config.TOKEN_EXPIRATION)
    token = s.dumps({"id": user_id}).decode('ascii')
    return token


def verify_token(token):
    s = Serializer(Config.SECRET_KEY)
    try:
        data = s.loads(token)
    except Exception:
        return None
    return data["id"]