Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/search/azure-search-documents/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Reorganized `SearchServiceClient` into `SearchIndexClient` & `SearchIndexerClient` #11507
- Split searchindex.json and searchservice.json models and operations into separate namespaces #11508
- Renamed `edm` to `SearchFieldDataType` #11511
Comment thread
xiangyan99 marked this conversation as resolved.
- Now Search Synonym Map creation/update returns a model #11514

## 1.0.0b3 (2020-05-04)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
from ._search_index_client import SearchIndexClient # pylint: disable=unused-import
from ._search_indexer_client import SearchIndexerClient # pylint: disable=unused-import

from . import edm # pylint: disable=unused-import
from . import _edm as SearchFieldDataType # pylint: disable=unused-import
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# --------------------------------------------------------------------------
from typing import TYPE_CHECKING

from .edm import Collection, ComplexType
from ._edm import Collection, ComplexType
from ._generated.models import SearchField

if TYPE_CHECKING:
Expand All @@ -21,14 +21,15 @@ def SimpleField(**kw):
:param name: Required. The name of the field, which must be unique within the fields collection
of the index or parent field.
:type name: str
:param type: Required. The data type of the field. Possible values include: edm.String,
edm.Int32, edm.Int64, edm.Double, edm.Boolean, edm.DateTimeOffset,
edm.GeographyPoint, edm.ComplexType, from `azure.search.documents.edm`.
:param type: Required. The data type of the field. Possible values include: SearchFieldDataType.String,
SearchFieldDataType.Int32, SearchFieldDataType.Int64, SearchFieldDataType.Double, SearchFieldDataType.Boolean,
SearchFieldDataType.DateTimeOffset, SearchFieldDataType.GeographyPoint, SearchFieldDataType.ComplexType,
from `azure.search.documents.SearchFieldDataType`.
:type type: str
:param key: A value indicating whether the field uniquely identifies documents in the index.
Exactly one top-level field in each index must be chosen as the key field and it must be of
type Edm.String. Key fields can be used to look up documents directly and update or delete
specific documents. Default is False
type SearchFieldDataType.String. Key fields can be used to look up documents directly and
update or delete specific documents. Default is False
:type key: bool
:param hidden: A value indicating whether the field can be returned in a search result.
You can enable this option if you want to use a field (for example, margin) as a filter,
Expand All @@ -39,10 +40,10 @@ def SimpleField(**kw):
:type retrievable: bool
:param filterable: A value indicating whether to enable the field to be referenced in $filter
queries. filterable differs from searchable in how strings are handled. Fields of type
Edm.String or Collection(Edm.String) that are filterable do not undergo word-breaking, so
comparisons are for exact matches only. For example, if you set such a field f to "sunny day",
$filter=f eq 'sunny' will find no matches, but $filter=f eq 'sunny day' will. This property
must be null for complex fields. Default is False
SearchFieldDataType.String or Collection(SearchFieldDataType.String) that are filterable do
not undergo word-breaking, so comparisons are for exact matches only. For example, if you
set such a field f to "sunny day", $filter=f eq 'sunny' will find no matches, but
$filter=f eq 'sunny day' will. This property must be null for complex fields. Default is False
:type filterable: bool
:param sortable: A value indicating whether to enable the field to be referenced in $orderby
expressions. By default Azure Cognitive Search sorts results by score, but in many experiences
Expand All @@ -56,8 +57,8 @@ def SimpleField(**kw):
:param facetable: A value indicating whether to enable the field to be referenced in facet
queries. Typically used in a presentation of search results that includes hit count by category
(for example, search for digital cameras and see hits by brand, by megapixels, by price, and so
on). Fields of type edm.GeographyPoint or Collection(edm.GeographyPoint) cannot be facetable.
Default is False.
on). Fields of type SearchFieldDataType.GeographyPoint or
Collection(SearchFieldDataType.GeographyPoint) cannot be facetable. Default is False.
:type facetable: bool
"""
result = {"name": kw.get("name"), "type": kw.get("type")} # type: Dict[str, Any]
Expand All @@ -77,12 +78,12 @@ def SearchableField(**kw):
:param name: Required. The name of the field, which must be unique within the fields collection
of the index or parent field.
:type name: str
:param type: Required. The data type of the field. Possible values include: edm.String
and Collection(edm.String), from `azure.search.documents.edm`.
:param type: Required. The data type of the field. Possible values include: SearchFieldDataType.String
and Collection(SearchFieldDataType.String), from `azure.search.documents.SearchFieldDataType`.
:type type: str
:param key: A value indicating whether the field uniquely identifies documents in the index.
Exactly one top-level field in each index must be chosen as the key field and it must be of
type Edm.String. Key fields can be used to look up documents directly and update or delete
type SearchFieldDataType.String. Key fields can be used to look up documents directly and update or delete
specific documents. Default is False
:type key: bool
:param hidden: A value indicating whether the field can be returned in a search result.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
ComplexField,
SearchableField,
SimpleField,
edm,
SearchFieldDataType,
)
from .._internal._generated.models import (
AnalyzeRequest,
Expand Down Expand Up @@ -210,5 +210,5 @@
"UniqueTokenFilter",
"WebApiSkill",
"WordDelimiterTokenFilter",
"edm",
"SearchFieldDataType",
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,29 @@
key = os.getenv("AZURE_SEARCH_API_KEY")

from azure.core.credentials import AzureKeyCredential
from azure.search.documents import ComplexField, SearchServiceClient, CorsOptions, Index, ScoringProfile, edm, SimpleField, SearchableField
from azure.search.documents import (
ComplexField,
SearchServiceClient,
CorsOptions,
Index,
ScoringProfile,
SearchFieldDataType,
SimpleField,
SearchableField,
)

client = SearchServiceClient(service_endpoint, AzureKeyCredential(key)).get_indexes_client()

def create_index():
# [START create_index]
name = "hotels"
fields = [
SimpleField(name="hotelId", type=edm.String, key=True),
SimpleField(name="baseRate", type=edm.Double),
SearchableField(name="description", type=edm.String),
SimpleField(name="hotelId", type=SearchFieldDataType.String, key=True),
SimpleField(name="baseRate", type=SearchFieldDataType.Double),
SearchableField(name="description", type=SearchFieldDataType.String),
ComplexField(name="address", fields=[
SimpleField(name="streetAddress", type=edm.String),
SimpleField(name="city", type=edm.String),
SimpleField(name="streetAddress", type=SearchFieldDataType.String),
SimpleField(name="city", type=SearchFieldDataType.String),
])
]
cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60)
Expand All @@ -62,14 +71,14 @@ def update_index():
# [START update_index]
name = "hotels"
fields = [
SimpleField(name="hotelId", type=edm.String, key=True),
SimpleField(name="baseRate", type=edm.Double),
SearchableField(name="description", type=edm.String),
SearchableField(name="hotelName", type=edm.String),
SimpleField(name="hotelId", type=SearchFieldDataType.String, key=True),
SimpleField(name="baseRate", type=SearchFieldDataType.Double),
SearchableField(name="description", type=SearchFieldDataType.String),
SearchableField(name="hotelName", type=SearchFieldDataType.String),
ComplexField(name="address", fields=[
SimpleField(name="streetAddress", type=edm.String),
SimpleField(name="city", type=edm.String),
SimpleField(name="state", type=edm.String),
SimpleField(name="streetAddress", type=SearchFieldDataType.String),
SimpleField(name="city", type=SearchFieldDataType.String),
SimpleField(name="state", type=SearchFieldDataType.String),
])
]
cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
SearchIndexer,
SynonymMap,
SimpleField,
edm
SearchFieldDataType
)
from azure.search.documents.indexes.aio import SearchIndexClient, SearchIndexerClient

Expand Down Expand Up @@ -160,8 +160,8 @@ async def test_delete_indexes_if_unchanged(self, api_key, endpoint, index_name,
async def test_create_index(self, api_key, endpoint, index_name, **kwargs):
name = "hotels"
fields = fields = [
SimpleField(name="hotelId", type=edm.String, key=True),
SimpleField(name="baseRate", type=edm.Double)
SimpleField(name="hotelId", type=SearchFieldDataType.String, key=True),
SimpleField(name="baseRate", type=SearchFieldDataType.Double)
]

scoring_profile = ScoringProfile(
Expand All @@ -187,8 +187,8 @@ async def test_create_index(self, api_key, endpoint, index_name, **kwargs):
async def test_create_or_update_index(self, api_key, endpoint, index_name, **kwargs):
name = "hotels"
fields = fields = [
SimpleField(name="hotelId", type=edm.String, key=True),
SimpleField(name="baseRate", type=edm.Double)
SimpleField(name="hotelId", type=SearchFieldDataType.String, key=True),
SimpleField(name="baseRate", type=SearchFieldDataType.Double)
]

cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60)
Expand Down
32 changes: 16 additions & 16 deletions sdk/search/azure-search-documents/tests/test_index_field_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
# Licensed under the MIT License.
# ------------------------------------

from azure.search.documents.indexes.models import ComplexField, SearchableField, SimpleField, edm
from azure.search.documents.indexes.models import ComplexField, SearchableField, SimpleField, SearchFieldDataType

def test_edm_contents():
assert edm.String == "Edm.String"
assert edm.Int32 == "Edm.Int32"
assert edm.Int64 == "Edm.Int64"
assert edm.Double == "Edm.Double"
assert edm.Boolean == "Edm.Boolean"
assert edm.DateTimeOffset == "Edm.DateTimeOffset"
assert edm.GeographyPoint == "Edm.GeographyPoint"
assert edm.ComplexType == "Edm.ComplexType"
assert edm.Collection("foo") == "Collection(foo)"
assert SearchFieldDataType.String == "Edm.String"
assert SearchFieldDataType.Int32 == "Edm.Int32"
assert SearchFieldDataType.Int64 == "Edm.Int64"
assert SearchFieldDataType.Double == "Edm.Double"
assert SearchFieldDataType.Boolean == "Edm.Boolean"
assert SearchFieldDataType.DateTimeOffset == "Edm.DateTimeOffset"
assert SearchFieldDataType.GeographyPoint == "Edm.GeographyPoint"
assert SearchFieldDataType.ComplexType == "Edm.ComplexType"
assert SearchFieldDataType.Collection("foo") == "Collection(foo)"

class TestComplexField(object):
def test_single(self):
fld = ComplexField(name="foo", fields=[])
assert fld.name == "foo"
assert fld.type == edm.ComplexType
assert fld.type == SearchFieldDataType.ComplexType

assert fld.sortable is None
assert fld.facetable is None
Expand All @@ -34,7 +34,7 @@ def test_single(self):
def test_collection(self):
fld = ComplexField(name="foo", fields=[], collection=True)
assert fld.name == "foo"
assert fld.type == edm.Collection(edm.ComplexType)
assert fld.type == SearchFieldDataType.Collection(SearchFieldDataType.ComplexType)

assert fld.sortable is None
assert fld.facetable is None
Expand All @@ -47,9 +47,9 @@ def test_collection(self):

class TestSimplexField(object):
def test_defaults(self):
fld = SimpleField(name="foo", type=edm.Double)
fld = SimpleField(name="foo", type=SearchFieldDataType.Double)
assert fld.name == "foo"
assert fld.type == edm.Double
assert fld.type == SearchFieldDataType.Double
assert fld.retrievable == True
assert fld.sortable == False
assert fld.facetable == False
Expand All @@ -63,9 +63,9 @@ def test_defaults(self):

class TestSearchableField(object):
def test_defaults(self):
fld = SearchableField(name="foo", type=edm.Collection(edm.String))
fld = SearchableField(name="foo", type=SearchFieldDataType.Collection(SearchFieldDataType.String))
assert fld.name == "foo"
assert fld.type == edm.Collection(edm.String)
assert fld.type == SearchFieldDataType.Collection(SearchFieldDataType.String)
assert fld.retrievable == True
assert fld.sortable == False
assert fld.facetable == False
Expand Down
10 changes: 5 additions & 5 deletions sdk/search/azure-search-documents/tests/test_service_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
SearchIndexerDataContainer,
SynonymMap,
SimpleField,
edm
SearchFieldDataType
)
from azure.search.documents.indexes import SearchIndexClient, SearchIndexerClient

Expand Down Expand Up @@ -144,8 +144,8 @@ def test_delete_indexes_if_unchanged(self, api_key, endpoint, index_name, **kwar
def test_create_index(self, api_key, endpoint, index_name, **kwargs):
name = "hotels"
fields = [
SimpleField(name="hotelId", type=edm.String, key=True),
SimpleField(name="baseRate", type=edm.Double)
SimpleField(name="hotelId", type=SearchFieldDataType.String, key=True),
SimpleField(name="baseRate", type=SearchFieldDataType.Double)
]
scoring_profile = ScoringProfile(
name="MyProfile"
Expand All @@ -170,8 +170,8 @@ def test_create_index(self, api_key, endpoint, index_name, **kwargs):
def test_create_or_update_index(self, api_key, endpoint, index_name, **kwargs):
name = "hotels"
fields = [
SimpleField(name="hotelId", type=edm.String, key=True),
SimpleField(name="baseRate", type=edm.Double)
SimpleField(name="hotelId", type=SearchFieldDataType.String, key=True),
SimpleField(name="baseRate", type=SearchFieldDataType.Double)
]
cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60)
scoring_profiles = []
Expand Down