Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code refactoring 4 #11800

Merged
merged 18 commits into from
Jun 5, 2020
Merged

code refactoring 4 #11800

merged 18 commits into from
Jun 5, 2020

Conversation

xiangyan99
Copy link
Member

xiangyan99 and others added 2 commits June 3, 2020 19:36
xiangyan99 and others added 2 commits June 3, 2020 19:43
* [HDInsight] Fix hdi test failure (#11806)

* Initial generation Synapse autorest v5

* Fix empty model generation

* Fix Test Failure:
Skip 3 test case: test_create_with_adlsgen1, test_create_with_additional_storage, test_oms_on_running_cluster
Rename test_http_extend to test_gateway_setting for http settings is
replaced with gateway settings

Co-authored-by: Laurent Mazuel <laurent.mazuel@gmail.com>
Co-authored-by: Zhenyu Zhou <zhezhou@microsoft.com>

* disable some by design bandit warnings (#11495)

* disable some by design bandit warnings

* Packaging update of azure-mgmt-datalake-analytics

Co-authored-by: Azure SDK Bot <aspysdk2@microsoft.com>

* Increment package version after release of azure_core (#11795)

* Use subject claim as home_account_id when no client_info (#11639)

* Refactor ClientCertificateCredential to use AadClient (#11719)

* Refactor ClientSecretCredential to use AadClient (#11718)

* [Cosmos] Fixed incorrect ID type error (#11798)

* Fixed incorrect ID type error

* Fix pylint

* [text analytics] Update readme (#11796)

* try something (#11797)

* Search refactoring 3 (#11804)

* create_or_update takes object

* rename is_hidden to hidden

* fix types

* updates

Co-authored-by: aim-for-better <zhenyu.zhou@microsoft.com>
Co-authored-by: Laurent Mazuel <laurent.mazuel@gmail.com>
Co-authored-by: Zhenyu Zhou <zhezhou@microsoft.com>
Co-authored-by: Azure SDK Bot <aspysdk2@microsoft.com>
Co-authored-by: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com>
Co-authored-by: Charles Lowell <chlowe@microsoft.com>
Co-authored-by: annatisch <antisch@microsoft.com>
Co-authored-by: iscai-msft <43154838+iscai-msft@users.noreply.github.com>
Co-authored-by: Krista Pratico <krpratic@microsoft.com>
heaths
heaths previously approved these changes Jun 5, 2020
Copy link
Member

@heaths heaths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A model still needs renaming (see comments), but I'll sign off to keep you unblocked.

@@ -235,7 +235,7 @@ def create_or_update_index(

@distributed_trace
def analyze_text(self, index_name, analyze_request, **kwargs):
# type: (str, AnalyzeRequest, **Any) -> AnalyzeResult
# type: (str, AnalyzeTextRequest, **Any) -> AnalyzeResult
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be AnalyzeTextOptions now, or was that going to come in a separate PR? See #11830.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already fixed. :)

@xiangyan99
Copy link
Member Author

/azp run python - search - ci

1 similar comment
@xiangyan99
Copy link
Member Author

/azp run python - search - ci

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@xiangyan99
Copy link
Member Author

/azp run python - search - ci

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@xiangyan99 xiangyan99 requested review from heaths and tg-msft June 5, 2020 05:04
tg-msft
tg-msft previously approved these changes Jun 5, 2020
Copy link
Member

@tg-msft tg-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks good with my limited understanding of our Python best practices. 😄

Comment on lines +140 to +174
include_total_result_count = kwargs.pop("include_total_result_count", None)
facets = kwargs.pop("facets", None)
filter_arg = kwargs.pop("filter", None)
highlight_fields = kwargs.pop("highlight_fields", None)
highlight_post_tag = kwargs.pop("highlight_post_tag", None)
highlight_pre_tag = kwargs.pop("highlight_pre_tag", None)
minimum_coverage = kwargs.pop("minimum_coverage", None)
order_by = kwargs.pop("order_by", None)
query_type = kwargs.pop("query_type", None)
scoring_parameters = kwargs.pop("scoring_parameters", None)
scoring_profile = kwargs.pop("scoring_profile", None)
search_fields = kwargs.pop("search_fields", None)
search_mode = kwargs.pop("search_mode", None)
select = kwargs.pop("select", None)
skip = kwargs.pop("skip", None)
top = kwargs.pop("top", None)
query = SearchQuery(
search_text=search_text,
include_total_result_count=include_total_result_count,
facets=facets,
filter=filter_arg,
highlight_fields=highlight_fields,
highlight_post_tag=highlight_post_tag,
highlight_pre_tag=highlight_pre_tag,
minimum_coverage=minimum_coverage,
order_by=order_by,
query_type=query_type,
scoring_parameters=scoring_parameters,
scoring_profile=scoring_profile,
search_fields=search_fields,
search_mode=search_mode,
select=select,
skip=skip,
top=top
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - Is it worth moving this logic onto the SearchQuery class so you don't have to update both the sync/async clients whenever we add a new parameter? I'm not sure how the Python folks typically handle these situations. (Also, we can just file a work item rather for Preview 5 rather than try to fix it today.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SearchQuery and AutocompleteQuery, SuggestQuery share one ctor. If we put all of pop operation there, I am afraid it will be messed up.

):
super(AnalyzeTextOptions, self).__init__(**kwargs)
self.text = kwargs['text']
self.analyzer_name = kwargs.get('analyzer_name', None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my own understanding - why get here vs pop in search when taking apart kwargs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference is pop will remove the argument from kwargs. In init method, kwargs will not be used in anywhere else so there is no difference. But in e.g. search method, if I don't pop them, those arguments will be passed into transport which will cause problems.

async with search_client:
results = await search_client.search(query=query)
results = await search_client.search(search_text="WiFi", facets=["Category"], top=0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very nice.

Comment on lines 79 to 80
client = SearchIndexClient(endpoint="<service endpoint>"
credential=credential)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
client = SearchIndexClient(endpoint="<service endpoint>"
credential=credential)
client = SearchIndexClient(endpoint="<service endpoint>",
credential=credential)

@@ -64,18 +65,33 @@ client = SearchClient(endpoint="<service endpoint>",
credential=credential)
```

#### Create a SearchServiceClient
#### Create a SearchIndexClient

Once you have the values of the Cognitive Search Service [service endpoint](https://docs.microsoft.com/en-us/azure/search/search-create-service-portal#get-a-key-and-url-endpoint)
and [api key](https://docs.microsoft.com/en-us/azure/search/search-security-api-keys) you can create the Search Service client:
Copy link
Contributor

@rakshith91 rakshith91 Jun 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and [api key](https://docs.microsoft.com/en-us/azure/search/search-security-api-keys) you can create the Search Service client:
and [api key](https://docs.microsoft.com/en-us/azure/search/search-security-api-keys) you can create the Search Index client:

#### Create a SearchIndexerClient

Once you have the values of the Cognitive Search Service [service endpoint](https://docs.microsoft.com/en-us/azure/search/search-create-service-portal#get-a-key-and-url-endpoint)
and [api key](https://docs.microsoft.com/en-us/azure/search/search-security-api-keys) you can create the Search Service client:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and [api key](https://docs.microsoft.com/en-us/azure/search/search-security-api-keys) you can create the Search Service client:
and [api key](https://docs.microsoft.com/en-us/azure/search/search-security-api-keys) you can create the Search Indexer client:


credential = AzureKeyCredential("<api key>")

client = SearchIndexerClient(endpoint="<service endpoint>"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
client = SearchIndexerClient(endpoint="<service endpoint>"
client = SearchIndexerClient(endpoint="<service endpoint>",

"""Search the Azure search index for documents.

:param query: An query for searching the index
:type documents: str or SearchQuery
:param str search_text: A full-text search query expression; Use "*" or omit this parameter to
Copy link
Contributor

@rakshith91 rakshith91 Jun 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by omit this parameter - do you mean search_text is optional? If not, is it by design to not make it optional and use '*' as default value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants