Ejemplo n.º 1
0
        private async Task CreateIndexAsync(
            CancellationToken ct)
        {
            var index = AzureIndexDefinition.Create(searchClient.IndexName);

            await indexClient.CreateOrUpdateIndexAsync(index, true, true, ct);
        }
Ejemplo n.º 2
0
        private static void UpsertTextEntry(UpsertIndexEntry upsert, IList <IndexDocumentsAction <SearchDocument> > batch)
        {
            var geoField  = string.Empty;
            var geoObject = (object)null;

            if (upsert.GeoObjects != null)
            {
                foreach (var(key, value) in upsert.GeoObjects)
                {
                    if (value is Point point)
                    {
                        geoField  = key;
                        geoObject = new
                        {
                            type        = "Point",
                            coordinates = new[]
                            {
                                point.Coordinates.Longitude,
                                point.Coordinates.Latitude
                            }
                        };
                        break;
                    }
                }
            }

            if (upsert.Texts != null || geoObject != null)
            {
                var document = new SearchDocument
                {
                    ["docId"]          = upsert.DocId.ToBase64(),
                    ["appId"]          = upsert.AppId.Id.ToString(),
                    ["appName"]        = upsert.AppId.Name,
                    ["contentId"]      = upsert.ContentId.ToString(),
                    ["schemaId"]       = upsert.SchemaId.Id.ToString(),
                    ["schemaName"]     = upsert.SchemaId.Name,
                    ["serveAll"]       = upsert.ServeAll,
                    ["servePublished"] = upsert.ServePublished,
                    ["geoField"]       = geoField,
                    ["geoObject"]      = geoObject
                };

                foreach (var(key, value) in upsert.Texts)
                {
                    var text = value;

                    var languageCode = AzureIndexDefinition.GetFieldName(key);

                    if (document.TryGetValue(languageCode, out var existing))
                    {
                        text = $"{existing} {value}";
                    }

                    document[languageCode] = text;
                }

                batch.Add(IndexDocumentsAction.MergeOrUpload(document));
            }
        }