Пример #1
0
class TsqlQueryEvaluator(object):
    """The main class for preparing and evaluating TigerSearch queries.
    
    A façade class that pulls together the parser and the query builder.
    """
    
    class Context(object):
        """The evaluator context.
        
        Each query evaluator has one context, which is used during query
        preparation.
        """

        def __init__(self, db, db_provider, corpus_info):
            self.db = db
            self.db_provider = db_provider
            self._nodesearcher = None
            self.allow_parallel = True
            self.corpus_info = corpus_info
        
        def _use_parallel(self):
            return self.db_provider.can_reconnect() and use_parallel_processing and self.allow_parallel
        
        def get_result_builder_class(self, has_constraints):
            return ParallelResultBuilder if self._use_parallel() and has_constraints \
                   else ResultBuilder

        @property
        def nodesearcher(self):
            if self._nodesearcher is None:
                self._nodesearcher = NodeSearcher(self.db)
            return self._nodesearcher
                
        
    def __init__(self, db, db_provider, corpus_info):
        self._context = TsqlQueryEvaluator.Context(db, db_provider, corpus_info)
        self._parser = TsqlParser()
        self._query_factory = QueryFactory(self._context)

    def new_builder(self):
        """Returns a new query builder.
        
        Query builders can be used to define a TIGERSearch query programmatically rather
        than having to create a query string.
        """
        return QueryBuilder(self._query_factory)
    
    def set_allow_parallel(self, value):
        """Allow or prohibit use of parallelized processing for the query evaluator."""
        self._context.allow_parallel = value
        
    def prepare_query(self, query_str):
        """Creates a query object from a TIGER query string."""
        return self._query_factory.from_ast(
            self._parser.parse_query(query_str))
    
    def evaluate(self, query_str):
        """Immediately evaluates a TIGER query query."""
        return self.prepare_query(query_str).evaluate()
Пример #2
0
class TsqlQueryEvaluator(object):
    """The main class for preparing and evaluating TigerSearch queries.
    
    A façade class that pulls together the parser and the query builder.
    """
    class Context(object):
        """The evaluator context.
        
        Each query evaluator has one context, which is used during query
        preparation.
        """
        def __init__(self, db, db_provider, corpus_info):
            self.db = db
            self.db_provider = db_provider
            self._nodesearcher = None
            self.allow_parallel = True
            self.corpus_info = corpus_info

        def _use_parallel(self):
            return self.db_provider.can_reconnect(
            ) and use_parallel_processing and self.allow_parallel

        def get_result_builder_class(self, has_constraints):
            return ParallelResultBuilder if self._use_parallel() and has_constraints \
                   else ResultBuilder

        @property
        def nodesearcher(self):
            if self._nodesearcher is None:
                self._nodesearcher = NodeSearcher(self.db)
            return self._nodesearcher

    def __init__(self, db, db_provider, corpus_info):
        self._context = TsqlQueryEvaluator.Context(db, db_provider,
                                                   corpus_info)
        self._parser = TsqlParser()
        self._query_factory = QueryFactory(self._context)

    def new_builder(self):
        """Returns a new query builder.
        
        Query builders can be used to define a TIGERSearch query programmatically rather
        than having to create a query string.
        """
        return QueryBuilder(self._query_factory)

    def set_allow_parallel(self, value):
        """Allow or prohibit use of parallelized processing for the query evaluator."""
        self._context.allow_parallel = value

    def prepare_query(self, query_str):
        """Creates a query object from a TIGER query string."""
        return self._query_factory.from_ast(
            self._parser.parse_query(query_str))

    def evaluate(self, query_str):
        """Immediately evaluates a TIGER query query."""
        return self.prepare_query(query_str).evaluate()
Пример #3
0
 def __init__(self, db, db_provider, corpus_info):
     self._context = TsqlQueryEvaluator.Context(db, db_provider,
                                                corpus_info)
     self._parser = TsqlParser()
     self._query_factory = QueryFactory(self._context)
Пример #4
0
 def __init__(self, db, db_provider, corpus_info):
     self._context = TsqlQueryEvaluator.Context(db, db_provider, corpus_info)
     self._parser = TsqlParser()
     self._query_factory = QueryFactory(self._context)