项目作者: amrfaissal

项目描述 :
🔍 Ruby Client for Microsoft Azure Search
高级语言: Ruby
项目地址: git://github.com/amrfaissal/azuresearch-ruby-client.git
创建时间: 2017-05-24T11:31:44Z
项目社区:https://github.com/amrfaissal/azuresearch-ruby-client

开源协议:MIT License

下载


Ruby Client for Microsoft Azure Search

Build Status

Description

This library brings Microsoft Azure Search to your Ruby/RoR application. It allows you to execute most common API requests against Azure Search.

Requirements

  • Ruby 2.0 or later.
  • API key.

Installation

Add this line to your application’s Gemfile:

  1. gem 'azure_search'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install azure_search

Documentation

View the reference documentation.

Usage

The first thing to do is to create a SearchIndexClient. You typically create one client for your application.

Here’s a complete example of creating a client, creating an index, adding documents, executing a search…etc.

  1. require 'azure_search'
  2. include AzureSearch
  3. client = SearchIndexClient.new("service-name", "index-name", "generated-api-key")
  4. # Delete the index if it exists (Only for testing purposes)
  5. client.delete unless !client.exists
  6. # Index definition
  7. index_def = {
  8. :name => "carshop",
  9. :fields => [
  10. IndexField.new("id", "Edm.String").searchable(true).key(true),
  11. IndexField.new("year", "Edm.String").searchable(true).retrievable(true),
  12. IndexField.new("make", "Edm.String").searchable(true).retrievable(true),
  13. IndexField.new("trim", "Edm.String").searchable(true).retrievable(true)
  14. ]
  15. }
  16. # Create the index with supplied index definition
  17. client.create(index_def)
  18. # Perform a batch insert of documents
  19. ops = [
  20. IndexBatchOperation.upload({"id"=>1, "year"=>"2017", "make"=>"Audi", "model"=>"A3", "trim"=>"1.8 TFSI Premium 2dr Sedan"}),
  21. IndexBatchOperation.upload({"id"=>2, "year"=>"2017", "make"=>"Audi", "model"=>"A3", "trim"=>"2.0 TDI Premium 4dr Sedan"}),
  22. IndexBatchOperation.upload({"id"=>3, "year"=>"2016", "make"=>"Audi", "model"=>"A4", "trim"=>"2.0 TDI Premium 4dr Sedan"}),
  23. IndexBatchOperation.upload({"id"=>4, "year"=>"2016", "make"=>"Bentley", "model"=>"Mulsanne", "trim"=>"4dr Sedan"}),
  24. IndexBatchOperation.upload({"id"=>5, "year"=>"2016", "make"=>"Dodge", "model"=>"Dart", "trim"=>"Aero 4dr Sedan"})
  25. ]
  26. client.batch_insert(ops, chunk_size=3)
  27. # Perform a simple search for cars that are not of Audi make.
  28. search_opts = IndexSearchOptions.new
  29. .include_count(true)
  30. .search_mode("all")
  31. .search_fields("make,trim")
  32. response = client.search("-audi", search_opts)
  33. puts response
  34. # Lookup the document with ID "1"
  35. document = client.lookup("1")
  36. puts document

Contributing

Bug reports, Pull requests and Stars are always welcome. For bugs and feature requests, please create an issue.

Donate

  • Donate
  • Bitcoin: 1EdwqtXhojU4LGhTwBLT1JpTb1d71oA89o

License

The gem is available as open source under the terms of the MIT License.