Example #1
0
    def __init__(self, config=None, parent=None, **kwargs):
        '''
        The ``config`` init parameter specifies a module that configures
        this biothing.  For more information see `config module`_ documentation.
        '''
        super(BiothingESWebSettings, self).__init__(config, parent, **kwargs)

        # elasticsearch connections
        self._connections = Connections()

        connection_settings = {
            "hosts": self.ES_HOST,
            "timeout": self.ES_CLIENT_TIMEOUT
        }
        connection_settings.update(transport_class=BiothingsTransport)
        self._connections.create_connection(alias='sync',
                                            **connection_settings)
        connection_settings.update(transport_class=BiothingsAsyncTransport)
        if self.ES_SNIFF:
            connection_settings.update(sniffer_timeout=60)
            connection_settings.update(sniff_on_start=True)
            connection_settings.update(sniff_on_connection_fail=True)
        self._connections.create_connection(alias='async',
                                            **connection_settings)

        # cached index mappings
        self.source_metadata = defaultdict(dict)
        self.source_properties = defaultdict(dict)

        # populate field notes if exist
        try:
            inf = open(self.AVAILABLE_FIELDS_NOTES_PATH, 'r')
            self._fields_notes = json.load(inf)
            inf.close()
        except Exception:
            self._fields_notes = {}

        # user query data
        self.userquery = ESUserQuery(self.USERQUERY_DIR)

        # query pipelines
        self.query_builder = self.load_class(self.ES_QUERY_BUILDER)(self)
        self.query_backend = self.load_class(self.ES_QUERY_BACKEND)(self)
        self.result_transform = self.load_class(self.ES_RESULT_TRANSFORM)(self)

        # initialize payload for standalone tracking batch
        self.tracking_payload = []

        self.ES_INDICES = dict(self.ES_INDICES)  # TODO
        self.ES_INDICES[self.ES_DOC_TYPE] = self.ES_INDEX
        self.BIOTHING_TYPES = list(self.ES_INDICES.keys())

        IOLoop.current().add_callback(self._initialize)
Example #2
0
    def __init__(self, settings):

        self.settings = settings
        self._connections = Connections()

        connection_settings = {
            "hosts": self.settings.ES_HOST,
            "timeout": self.settings.ES_CLIENT_TIMEOUT
        }
        connection_settings.update(transport_class=BiothingsTransport)
        self._connections.create_connection(alias='sync',
                                            **connection_settings)
        connection_settings.update(transport_class=BiothingsAsyncTransport)
        if self.settings.ES_SNIFF:
            connection_settings.update(sniffer_timeout=60)
            connection_settings.update(sniff_on_start=True)
            connection_settings.update(sniff_on_connection_fail=True)
        self._connections.create_connection(alias='async',
                                            **connection_settings)
Example #3
0
    def __init__(self, config='biothings.web.settings.default'):
        '''
        The ``config`` init parameter specifies a module that configures
        this biothing.  For more information see `config module`_ documentation.
        '''
        super(BiothingESWebSettings, self).__init__(config)

        # temp. move import there to hide async dep unless used
        from elasticsearch_async.transport import AsyncTransport
        from elasticsearch_dsl.connections import Connections

        # elasticsearch connections
        self._connections = Connections()

        connection_settings = {
            "hosts": self.ES_HOST,
            "timeout": self.ES_CLIENT_TIMEOUT,
            "max_retries":
            1,  # maximum number of retries before an exception is propagated
            "timeout_cutoff":
            1,  # number of consecutive failures after which the timeout doesn’t increase
            "selector_class": KnownLiveSelecter
        }
        self._connections.create_connection(alias='sync',
                                            **connection_settings)
        connection_settings.update(transport_class=AsyncTransport)
        self._connections.create_connection(alias='async',
                                            **connection_settings)

        # project metadata under index mappings
        self._source_metadata = {}

        # populate field notes if exist
        try:
            inf = open(self.AVAILABLE_FIELDS_NOTES_PATH, 'r')
            self._fields_notes = json.load(inf)
            inf.close()
        except Exception:
            self._fields_notes = {}

        # initialize payload for standalone tracking batch
        self.tracking_payload = []
Example #4
0
from tableschema import Table

from mcod.histories.models import History
from mcod.lib import storages
from mcod.lib.managers import DeletedManager, SoftDeletableManager
from mcod.lib.model_mixins import CounterMixin, IndexableMixin
from mcod.lib.model_utils import TimeStampedModel, SoftDeletableModel
from mcod.lib.search.storage import ElasticsearchStorage
from mcod.lib.utils import download_file, analyze_resource_file, content_type_from_file_format
from mcod.resources.tasks import get_resource_from_url, process_resource_file, process_file_data

rfp = logging.getLogger('resource_file_processing')

User = get_user_model()

es_connections = Connections()
es_connections.configure(**settings.ELASTICSEARCH_DSL)

STATUS_CHOICES = [('published', _('Published')), ('draft', _('Draft'))]

OPENNESS_SCORE = {
    _type: os
    for _, _type, _, os in settings.SUPPORTED_CONTENT_TYPES
}


class ResourceDataValidationError(Exception):
    pass


def supported_formats_choices():
import jieba
from django.forms import model_to_dict
from django.http import HttpResponse
# Create your views here.
from django.views import View
from django.views.decorators.csrf import csrf_exempt

from elasticsearch_dsl.connections import Connections
from pip._vendor import requests

from DjangoSearch.settings import ELASTICSEARCH_INDEX
from search import pagination, models
from search.functions import XMLHandler, random_search_key, random_recommend, jieba_participle, search_body, spiderview
from search.models import ArticleType, User

connection = Connections()
client = connection.create_connection(hosts=['127.0.0.1'], timeout=20)


class RandomRecommendView(View):

    def get(self,request):
        """
        :param request: 随机推荐函数.
        :return:随机推荐的10条数据
        """
        uid = request.GET.get("uid","null")

        try:
            if uid != "null":
                print("此时用户状态是:[已登录]")