Skip to content

Commit

Permalink
PYCBC-804, PYCBC-655: Complete the FTS interface for SDK3
Browse files Browse the repository at this point in the history
Motivation
----------
We need to migrate the SDK2 search functionality to SDK3,
so it runs from the cluster.

Changes
-------
Added sdk-testcases,
TODO - download these from git, but maybe pinned to a given revision.
Refactored to SDK3, encapsulating the Params class, now
only for internal use and called _Params.

Results
-------
All new and old tests pass.

Change-Id: I6feba3daab84e611f992af90506ed607665af22d
Reviewed-on: http://review.couchbase.org/c/couchbase-python-client/+/120468
Tested-by: Ellis Breen <ellis.breen@couchbase.com>
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: David Kelly <davidmichaelkelly@gmail.com>
  • Loading branch information
davidkelly authored and griels committed Apr 7, 2020
1 parent ef37d58 commit b36c711
Show file tree
Hide file tree
Showing 53 changed files with 26,940 additions and 1,021 deletions.
2 changes: 1 addition & 1 deletion couchbase/asynchronous/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from couchbase_core.asynchronous.analytics import AsyncAnalyticsRequest
from couchbase_core.asynchronous.n1ql import AsyncN1QLRequest
from couchbase_core.asynchronous.view import AsyncViewBase
from couchbase_core.asynchronous.fulltext import AsyncSearchRequest
from couchbase.asynchronous.search import AsyncSearchRequest
from couchbase_core.asynchronous.rowsbase import AsyncRowsBase


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
This file contains the F.T.S. implementation for Async
"""

from couchbase_core.fulltext import SearchRequest
from .rowsbase import AsyncRowsBase
from couchbase.search import SearchRequest
from couchbase_core.asynchronous.rowsbase import AsyncRowsBase


class AsyncSearchRequest(AsyncRowsBase, SearchRequest):
Expand Down
30 changes: 21 additions & 9 deletions couchbase/cluster.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import asyncio

from typing import *
from couchbase.management.admin import Admin


import couchbase.search as SEARCH
from couchbase_core.mutation_state import MutationState
from couchbase_core.asynchronous import AsyncClientFactory
from couchbase.management.queries import QueryIndexManager
Expand All @@ -10,8 +12,9 @@
from couchbase.analytics import AnalyticsOptions
from .management.users import UserManager
from .management.buckets import BucketManager
from couchbase.diagnostics import DiagnosticsResult
from couchbase.fulltext import SearchResult, SearchOptions
from couchbase.management.admin import Admin
from couchbase.diagnostics import DiagnosticsResult, EndPointDiagnostics
from couchbase.search import SearchResult, SearchOptions
from .analytics import AnalyticsResult
from .n1ql import QueryResult
from couchbase_core.n1ql import N1QLQuery
Expand Down Expand Up @@ -403,27 +406,36 @@ def analytics_query(self, # type: Cluster

def search_query(self,
index, # type: str
query, # type: couchbase_core.Query
query, # type: search.SearchQuery
*options, # type: SearchOptions
**kwargs
):
# type: (...) -> SearchResult
"""
Executes a Search or F.T.S. query against the remote cluster and returns a SearchResult implementation with the results of the query.
.. code-block:: python
it = cb.search('name', ft.MatchQuery('nosql'), SearchOptions(limit=10))
for hit in it:
print(hit)
:param str index: Name of the index to use for this query.
:param couchbase_core.Query query: the fluent search API to construct a query for F.T.S.
:param couchbas.search.SearchQuery: the fluent search API to construct a query for F.T.S.
:param QueryOptions options: the options to pass to the cluster with the query.
:param Any kwargs: Overrides corresponding value in options.
:return: An SearchResult object with the results of the query or error message if the query failed on the server.
:return: A SearchResult object with the results of the query or error message if the query failed on the server.
Any exceptions raised by the underlying platform - HTTP_TIMEOUT for example.
:except ServiceNotFoundException - service does not exist or cannot be located.
"""
self._check_for_shutdown()
final_args=forward_args(kwargs, *options)
final_args['itercls']=final_args.get('itercls',SearchResult)
return self._operate_on_cluster(CoreClient.search, SearchException, index, query, **final_args )

def do_search(dest):
search_params = SearchOptions.gen_search_params_cls(index, query, *options, **kwargs)
return search_params.itercls(search_params.body, dest, **search_params.iterargs)

return self._operate_on_cluster(do_search, SearchException)

_root_diag_data = {'id', 'version', 'sdk'}

Expand Down
103 changes: 0 additions & 103 deletions couchbase/fulltext.py

This file was deleted.

31 changes: 31 additions & 0 deletions couchbase/iterables/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from typing import Union, Iterable, Any

from couchbase_core import StopAsyncIteration

IterableQuery = Iterable[Any]


class IterableWrapper(object):
def __init__(self,
parent # type: IterableQuery
):
self.done = False
self.buffered_rows = []
self.parent = parent # type: IterableQuery

def metadata(self):
# type: (...) -> JSON
return self.parent.meta

def __iter__(self):
for row in self.buffered_rows:
yield row
parent_iter = iter(self.parent)
while not self.done:
try:
next_item = next(parent_iter)
self.buffered_rows.append(next_item)
yield next_item
except (StopAsyncIteration, StopIteration) as e:
self.done = True
break
Loading

0 comments on commit b36c711

Please sign in to comment.