Exemplo n.º 1
0
        public static async Task Main()
        {
            // Get our settings
            string serviceName = GetVariable("Search Service Name: ", "SEARCH_SERVICE");
            string indexName   = GetVariable("Search Index Name: ", "SEARCH_INDEX");
            string apiKey      = GetVariable("Search Api Key: ", "SEARCH_APIKEY");

            Console.WriteLine();

            // Create the client to search an index
            CognitiveSearchClient search = new CognitiveSearchClient(serviceName, new CognitiveSearchCredential(apiKey));
            IndexClient           index  = search.GetIndexClient(indexName);

            // Start a REPL
            for (;;)
            {
                // Get the query
                Console.Write("Query: ");
                string query = Console.ReadLine();
                if (string.IsNullOrEmpty(query))
                {
                    break;
                }

                try
                {
                    // Try searching
                    SearchDocumentsResult response = await index.SearchAsync(query);

                    Console.WriteLine($"{response.Results.Count} results!");
                    Console.WriteLine();

                    // Print the result
                    int count = 0;
                    foreach (SearchResult result in response.Results)
                    {
                        Console.WriteLine($"Result #{count++} (score={result.Score}):");
                        foreach (KeyValuePair <string, object> field in (IDictionary <string, object>)result)
                        {
                            string value = field.Value?.ToString() ?? "";
                            if (value.Length > 70)
                            {
                                value = value.Substring(0, 70) + "...";
                            }
                            Console.WriteLine($"    {field.Key}: {value}");
                        }
                        Console.WriteLine();
                    }
                }
                catch (RequestFailedException ex)
                {
                    Console.WriteLine($"You're bad at searching: ${ex}");
                }

                Console.WriteLine();
            }

            Console.WriteLine("Goodbye!");
        }
Exemplo n.º 2
0
        public async Task <IApiResponse <IEnumerable <IndexOperationResult> > > IndexBulk(string indexName, IEnumerable <AzureDocument> documents = null)
        {
            var operations = from d in documents
                             select new IndexOperation(IndexOperationType.Upload, AzureDocument.KeyFieldName, d.Id.ToString())
            {
                Properties = d
            };

            var result = await IndexClient.PopulateAsync(indexName, operations.ToArray()).ConfigureAwait(false);

            return(result);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            BlobClient     blobClient  = new BlobClient(Configuration["Azure:Storage:Blob:ContainerName"], Configuration["Azure:Storage:Blob:ConnectionString"]);
            IndexClient    indexClient = new IndexClient(Configuration["Azure:Search:ServiceName"], Configuration["Azure:Search:IndexName"], Configuration["Azure:Search:IndexerName"], Configuration["Azure:Search:AdminApiKey"]);
            DiffCalculator diffService = new DiffCalculator();

            DocumentsService documentsService = new DocumentsService(blobClient, indexClient, diffService);

            services.AddSingleton <DocumentsService>(documentsService);

            InformationService informationService = new InformationService(Configuration.GetSection("Azure"));

            services.AddSingleton <InformationService>(informationService);

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
Exemplo n.º 4
0
        public async Task <IApiResponse> DeleteIndex(string indexName)
        {
            var response = await IndexClient.DeleteIndexAsync(indexName).ConfigureAwait(false);

            return(response);
        }
Exemplo n.º 5
0
        public async Task <IApiResponse <Index> > UpdateIndex(Index index)
        {
            var result = await IndexClient.UpdateIndexAsync(index).ConfigureAwait(false);

            return(result);
        }
Exemplo n.º 6
0
        public async Task <Index> GetIndex(string scope)
        {
            var index = await IndexClient.GetIndexAsync(scope).ConfigureAwait(false);

            return(index.Body);
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
#if NO_AUTH
            // not using SefariaClient
#else
            var client = new SefariaClient();
            Console.WriteLine(client.ToString());
#endif

            while (true)
            {
                Console.Write("> ");
                string input = Console.ReadLine();
                if (input != null)
                {
                    if (input.Equals("quit"))
                    {
                        break;
                    }

                    if (input.Equals("titles"))
                    {
#if NO_AUTH
                        var index = IndexClient.GetTitles();
#else
                        var index = client.Index.GetTitles();
#endif
                        foreach (var title in index.Books)
                        {
                            Console.WriteLine(title);
                        }
                        continue;
                    }

                    if (input.Equals("contents"))
                    {
#if NO_AUTH
                        var indices = IndexClient.GetContents();
#else
                        var indices = client.Index.GetContents();
#endif
                        //todo print out index
                        Console.WriteLine(indices.ToString());
                        continue;
                    }

                    // todo output specific indices (e.g. genesis)
                }

                try
                {
#if NO_AUTH
                    var text  = TextClient.GetText(input, false, false);
                    var links = LinksClient.GetLinks(input);
#else
                    var text  = client.Texts.GetText(input);
                    var links = client.Links.GetLinks(input);
#endif
                    if (text.Error != null)
                    {
                        Console.WriteLine(text.Error);
                    }
                    else
                    {
                        // texts
                        for (int i = 0; i < text.TextList.Count; i++)
                        {
                            Console.WriteLine(text.TextList[i]);
                            Debug.WriteLine(text.HebrewTextList[i]);
                        }

                        // links
                        foreach (var link in links)
                        {
                            Console.WriteLine(link.Ref);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }
 public DocumentsService(BlobClient blobClient, IndexClient indexClient, DiffCalculator diffCalculator)
 {
     this.blobClient     = blobClient;
     this.indexClient    = indexClient;
     this.diffCalculator = diffCalculator;
 }