From 64daf4fc1eb0de6c1e88ec9823b61d88135c861e Mon Sep 17 00:00:00 2001 From: Mike Moore Date: Mon, 16 Nov 2015 10:23:40 -0700 Subject: [PATCH 1/5] Add search acceptance tests --- acceptance/search/search_test.rb | 186 +++++++++++++++++++++++++++++++ acceptance/search_helper.rb | 87 +++++++++++++++ rakelib/test.rake | 45 ++++++++ 3 files changed, 318 insertions(+) create mode 100644 acceptance/search/search_test.rb create mode 100644 acceptance/search_helper.rb diff --git a/acceptance/search/search_test.rb b/acceptance/search/search_test.rb new file mode 100644 index 000000000000..9c0dad48ceb3 --- /dev/null +++ b/acceptance/search/search_test.rb @@ -0,0 +1,186 @@ +# Copyright 2015 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require "search_helper" +require "gcloud/search" + +# This test is a ruby version of gcloud-node's search test. + +describe "Search", :search do + let(:index) { search.index "#{prefix}-main-index", skip_lookup: true } + let(:chris_where_doc) do + doc = index.document "chris-where" + doc["question"].add "Where did Chris go?" + doc["answer"].add "to the mountains" + doc["tags"].add "chris" + doc["tags"].add "gcloud" + doc["tags"].add "ruby" + doc + end + let(:chris_what_doc) do + doc = index.document "chris-what" + doc["question"].add "What did Chris do?" + doc["answer"].add "hunting" + doc["tags"].add "chris" + doc["tags"].add "gcloud" + doc["tags"].add "ruby" + doc + end + let(:mike_where_doc) do + doc = index.document "mike-where" + doc["question"].add "Where did Mike go?" + doc["answer"].add "comic book store" + doc["tags"].add "mike" + doc["tags"].add "gcloud" + doc["tags"].add "ruby" + doc + end + let(:mike_what_doc) do + doc = index.document "mike-what" + doc["question"].add "What did Mike do?" + doc["answer"].add "bought some comics" + doc["tags"].add "mike" + doc["tags"].add "gcloud" + doc["tags"].add "ruby" + doc + end + + before do + if index.find(chris_where_doc.doc_id).nil? + index.save chris_where_doc + index.save chris_what_doc + index.save mike_where_doc + index.save mike_what_doc + end + end + + it "creates and deletes a document in a new index" do + new_index = search.index "#{prefix}-new-index", skip_lookup: true + new_doc = new_index.document "new-document" + new_doc["hello"].add "world" + new_index.documents.count.must_equal 0 + new_index.save new_doc + new_index.documents.count.must_equal 1 + new_index.remove new_doc + new_index.documents.count.must_equal 0 + end + + it "should get the indexes" do + search.indexes.count.must_be :>, 0 + search.indexes.all.count.must_be :>, 0 + end + + it "should get all documents" do + index.documents.count.must_be :>, 0 + index.documents.all.count.must_be :>, 0 + end + + it "searches" do + search_results = index.search "mountains" + search_results.count.must_equal 1 + search_results.first.doc_id.must_equal chris_where_doc.doc_id + search_results.first["title"].must_be :empty? + search_results.first["questions"].must_be :empty? + search_results.first["tags"].must_be :empty? + search_results.first["rank"].must_be :empty? + search_results.first["score"].must_be :empty? + + search_results = index.search "where", return_fields: ["question"] + search_results.count.must_equal 2 + search_results.map(&:doc_id).must_include chris_where_doc.doc_id + search_results.map(&:doc_id).must_include mike_where_doc.doc_id + search_results.each do |sr| + sr["question"].wont_be :empty? + sr["answer"].must_be :empty? + sr["tags"].must_be :empty? + sr["rank"].must_be :empty? + sr["score"].must_be :empty? + end + + search_results = index.search "chris", return_fields: ["question", "answer"] + search_results.count.must_equal 2 + search_results.map(&:doc_id).must_include chris_where_doc.doc_id + search_results.map(&:doc_id).must_include chris_what_doc.doc_id + search_results.each do |sr| + sr["question"].wont_be :empty? + sr["answer"].wont_be :empty? + sr["tags"].must_be :empty? + sr["rank"].must_be :empty? + sr["score"].must_be :empty? + end + + search_results = index.search "mike", return_fields: "*" + search_results.count.must_equal 2 + search_results.map(&:doc_id).must_include mike_where_doc.doc_id + search_results.map(&:doc_id).must_include mike_what_doc.doc_id + search_results.each do |sr| + sr["question"].wont_be :empty? + sr["answer"].wont_be :empty? + sr["tags"].wont_be :empty? + sr["rank"].must_be :empty? + sr["score"].must_be :empty? + end + + search_results = index.search "mike", return_fields: "*", order: "question, answer" + search_results.count.must_equal 2 + search_results.map(&:doc_id).must_include mike_where_doc.doc_id + search_results.map(&:doc_id).must_include mike_what_doc.doc_id + search_results.each do |sr| + sr["question"].wont_be :empty? + sr["answer"].wont_be :empty? + sr["tags"].wont_be :empty? + sr["rank"].must_be :empty? + sr["score"].must_be :empty? + end + + search_results = index.search "mike", return_fields: ["*", "rank", "score"], scorer: "generic", order: "score desc" + search_results.count.must_equal 2 + search_results.map(&:doc_id).must_include mike_where_doc.doc_id + search_results.map(&:doc_id).must_include mike_what_doc.doc_id + search_results.each do |sr| + sr["question"].wont_be :empty? + sr["answer"].wont_be :empty? + sr["tags"].wont_be :empty? + sr["rank"].wont_be :empty? + sr["score"].wont_be :empty? + end + + search_results = index.search "ruby", return_fields: ["tags", "rank", "score"], scorer: "generic" + search_results.count.must_equal 4 + search_results.map(&:doc_id).must_include chris_where_doc.doc_id + search_results.map(&:doc_id).must_include chris_what_doc.doc_id + search_results.map(&:doc_id).must_include mike_where_doc.doc_id + search_results.map(&:doc_id).must_include mike_what_doc.doc_id + search_results.each do |sr| + sr["question"].must_be :empty? + sr["answer"].must_be :empty? + sr["tags"].wont_be :empty? + sr["rank"].wont_be :empty? + sr["score"].wont_be :empty? + end + + search_results = index.search "where", return_fields: ["question_snippet", "answer"], expressions: {name: "question_snippet", expression: "snippet(\"where\", question)"} + search_results.count.must_equal 2 + search_results.map(&:doc_id).must_include chris_where_doc.doc_id + search_results.map(&:doc_id).must_include mike_where_doc.doc_id + search_results.each do |sr| + sr["question"].must_be :empty? + sr["question_snippet"].wont_be :empty? + sr["answer"].wont_be :empty? + sr["tags"].must_be :empty? + sr["rank"].must_be :empty? + sr["score"].must_be :empty? + end + end +end diff --git a/acceptance/search_helper.rb b/acceptance/search_helper.rb new file mode 100644 index 000000000000..577d7e9104da --- /dev/null +++ b/acceptance/search_helper.rb @@ -0,0 +1,87 @@ +# Copyright 2015 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require "helper" +require "gcloud/search" + +Gcloud::Backoff.retries = 10 + +# Create shared search object so we don't create new for each test +$search = Gcloud.search + +# create prefix for names of datasets and tables +require "time" +require "securerandom" +t = Time.now.utc.iso8601.gsub ":", "_" +$prefix = "gcloud_ruby_acceptance_#{t}_#{SecureRandom.hex(4)}".downcase.gsub "-", "_" + +module Acceptance + ## + # Test class for running against a search instance. + # Ensures that there is an active connection for the tests to use. + # + # This class can be used with the spec DSL. + # To do so, add :search to describe: + # + # describe "My search Test", :search do + # it "does a thing" do + # your.code.must_be :thing? + # end + # end + class SearchTest < Minitest::Test + attr_accessor :search + attr_accessor :prefix + + ## + # Setup project based on available ENV variables + def setup + @search = $search + @prefix = $prefix + + refute_nil @search, "You do not have an active search to run the tests." + refute_nil @prefix, "You do not have an search prefix to name the datasets and tables with." + + super + end + + # Add spec DSL + extend Minitest::Spec::DSL + + # Register this spec type for when :search is used. + register_spec_type(self) do |desc, *addl| + addl.include? :search + end + end + + def self.run_one_method klass, method_name, reporter + result = nil + (1..3).each do |try| + result = Minitest.run_one_method(klass, method_name) + break if (result.passed? || result.skipped?) + puts "Retrying #{klass}##{method_name} (#{try})" + end + reporter.record result + end +end + +def clean_up_search_indexes + puts "Cleaning up search indexes and documents after tests." + $search.indexes(prefix: $prefix).map { |i| i.delete force: true } +rescue => e + puts "Error while cleaning up search indexes and documents after tests.\n\n#{e}" +end + +Minitest.after_run do + clean_up_search_indexes +end diff --git a/rakelib/test.rake b/rakelib/test.rake index c302a300fb16..9689028b6ac0 100644 --- a/rakelib/test.rake +++ b/rakelib/test.rake @@ -328,11 +328,56 @@ namespace :test do end end + desc "Runs the search acceptance tests." + task :search, :project, :keyfile do |t, args| + project = args[:project] + project ||= ENV["GCLOUD_TEST_PROJECT"] || ENV["SEARCH_TEST_PROJECT"] || "helical-zone-771" + # keyfile = args[:keyfile] + # keyfile ||= ENV["GCLOUD_TEST_KEYFILE"] || ENV["SEARCH_TEST_KEYFILE"] + # if project.nil? || keyfile.nil? + # fail "You must provide a project and keyfile. e.g. rake test:acceptance:search:cleanup[test123, /path/to/keyfile.json] or PUBSUB_TEST_PROJECT=test123 PUBSUB_TEST_KEYFILE=/path/to/keyfile.json rake test:acceptance:search:cleanup" + # end + # always overwrite when running tests + ENV["SEARCH_PROJECT"] = project + # ENV["SEARCH_KEYFILE"] = keyfile + + $LOAD_PATH.unshift "lib", "test", "acceptance" + Dir.glob("acceptance/search/**/*_test.rb").each { |file| require_relative "../#{file}"} + end + + namespace :search do + desc "Removes *ALL* SEARCH zones and records. Use with caution." + task :cleanup do |t, args| + project = args[:project] + project ||= ENV["GCLOUD_TEST_PROJECT"] || ENV["SEARCH_TEST_PROJECT"] || "helical-zone-771" + # keyfile = args[:keyfile] + # keyfile ||= ENV["GCLOUD_TEST_KEYFILE"] || ENV["SEARCH_TEST_KEYFILE"] + # if project.nil? || keyfile.nil? + # fail "You must provide a project and keyfile. e.g. rake test:acceptance:search:cleanup[test123, /path/to/keyfile.json] or PUBSUB_TEST_PROJECT=test123 PUBSUB_TEST_KEYFILE=/path/to/keyfile.json rake test:acceptance:search:cleanup" + # end + # always overwrite when running tests + ENV["SEARCH_PROJECT"] = project + # ENV["SEARCH_KEYFILE"] = keyfile + + $LOAD_PATH.unshift "lib" + require "gcloud/search" + puts "Cleaning up SEARCH indexes and documents" + Gcloud.search.indexes.each do |index| + begin + index.delete force: true + rescue Gcloud::Search::ApiError => e + puts e.message + end + end + end + end + desc "Removes *ALL* acceptance test data. Use with caution." task :cleanup do Rake::Task["test:acceptance:bigquery:cleanup"].invoke Rake::Task["test:acceptance:dns:cleanup"].invoke Rake::Task["test:acceptance:pubsub:cleanup"].invoke + Rake::Task["test:acceptance:search:cleanup"].invoke Rake::Task["test:acceptance:storage:cleanup"].invoke end end From 737fce6967b594fe3ce9ec49458750650c0da050 Mon Sep 17 00:00:00 2001 From: Mike Moore Date: Thu, 10 Dec 2015 17:17:24 -0700 Subject: [PATCH 2/5] Rename Search fields option Match the naming from the example code. --- acceptance/search/search_test.rb | 14 +++++++------- lib/gcloud/search.rb | 2 +- lib/gcloud/search/connection.rb | 2 +- lib/gcloud/search/document.rb | 2 +- lib/gcloud/search/index.rb | 31 +++++++++++++++---------------- test/gcloud/search/index_test.rb | 8 ++++---- 6 files changed, 29 insertions(+), 30 deletions(-) diff --git a/acceptance/search/search_test.rb b/acceptance/search/search_test.rb index 9c0dad48ceb3..17b0b1412481 100644 --- a/acceptance/search/search_test.rb +++ b/acceptance/search/search_test.rb @@ -96,7 +96,7 @@ search_results.first["rank"].must_be :empty? search_results.first["score"].must_be :empty? - search_results = index.search "where", return_fields: ["question"] + search_results = index.search "where", fields: ["question"] search_results.count.must_equal 2 search_results.map(&:doc_id).must_include chris_where_doc.doc_id search_results.map(&:doc_id).must_include mike_where_doc.doc_id @@ -108,7 +108,7 @@ sr["score"].must_be :empty? end - search_results = index.search "chris", return_fields: ["question", "answer"] + search_results = index.search "chris", fields: ["question", "answer"] search_results.count.must_equal 2 search_results.map(&:doc_id).must_include chris_where_doc.doc_id search_results.map(&:doc_id).must_include chris_what_doc.doc_id @@ -120,7 +120,7 @@ sr["score"].must_be :empty? end - search_results = index.search "mike", return_fields: "*" + search_results = index.search "mike", fields: "*" search_results.count.must_equal 2 search_results.map(&:doc_id).must_include mike_where_doc.doc_id search_results.map(&:doc_id).must_include mike_what_doc.doc_id @@ -132,7 +132,7 @@ sr["score"].must_be :empty? end - search_results = index.search "mike", return_fields: "*", order: "question, answer" + search_results = index.search "mike", fields: "*", order: "question, answer" search_results.count.must_equal 2 search_results.map(&:doc_id).must_include mike_where_doc.doc_id search_results.map(&:doc_id).must_include mike_what_doc.doc_id @@ -144,7 +144,7 @@ sr["score"].must_be :empty? end - search_results = index.search "mike", return_fields: ["*", "rank", "score"], scorer: "generic", order: "score desc" + search_results = index.search "mike", fields: ["*", "rank", "score"], scorer: "generic", order: "score desc" search_results.count.must_equal 2 search_results.map(&:doc_id).must_include mike_where_doc.doc_id search_results.map(&:doc_id).must_include mike_what_doc.doc_id @@ -156,7 +156,7 @@ sr["score"].wont_be :empty? end - search_results = index.search "ruby", return_fields: ["tags", "rank", "score"], scorer: "generic" + search_results = index.search "ruby", fields: ["tags", "rank", "score"], scorer: "generic" search_results.count.must_equal 4 search_results.map(&:doc_id).must_include chris_where_doc.doc_id search_results.map(&:doc_id).must_include chris_what_doc.doc_id @@ -170,7 +170,7 @@ sr["score"].wont_be :empty? end - search_results = index.search "where", return_fields: ["question_snippet", "answer"], expressions: {name: "question_snippet", expression: "snippet(\"where\", question)"} + search_results = index.search "where", fields: ["question_snippet", "answer"], expressions: {name: "question_snippet", expression: "snippet(\"where\", question)"} search_results.count.must_equal 2 search_results.map(&:doc_id).must_include chris_where_doc.doc_id search_results.map(&:doc_id).must_include mike_where_doc.doc_id diff --git a/lib/gcloud/search.rb b/lib/gcloud/search.rb index 9f234f93440a..55e98cb06adf 100644 --- a/lib/gcloud/search.rb +++ b/lib/gcloud/search.rb @@ -258,7 +258,7 @@ def self.search project = nil, keyfile = nil, options = {} # expressions = [{ name: "total_price", expression: "(price + tax)" }] # results = index.search "cotton T-shirt", # expressions: expressions, - # fields: [name, total_price, highlight] + # fields: ["name", "total_price", "highlight"] # # Just as in documents, Result data is accessible via Fields methods: # diff --git a/lib/gcloud/search/connection.rb b/lib/gcloud/search/connection.rb index 4a477cd0cf35..e53d32fad72c 100644 --- a/lib/gcloud/search/connection.rb +++ b/lib/gcloud/search/connection.rb @@ -136,7 +136,7 @@ def search_request index_id, query, options = {} orderBy: options[:order], pageSize: options[:max], pageToken: options[:token], - returnFields: options[:return_fields], + returnFields: options[:fields], scorerSize: options[:scorer_size], scorer: options[:scorer] }.delete_if { |_, v| v.nil? } diff --git a/lib/gcloud/search/document.rb b/lib/gcloud/search/document.rb index b839e7c69914..01872756ca4a 100644 --- a/lib/gcloud/search/document.rb +++ b/lib/gcloud/search/document.rb @@ -88,7 +88,7 @@ def rank # not specified or set to 0), it is set at the time the document is # created to the number of seconds since January 1, 2011. The rank can be # used in Index#search options +expressions+, +order+, and - # +return_fields+, where it is referenced as +_rank+. + # +fields+, where it is referenced as +_rank+. def rank= new_rank @raw["rank"] = new_rank end diff --git a/lib/gcloud/search/index.rb b/lib/gcloud/search/index.rb index de9cc5a1f147..e4cb0fc339a3 100644 --- a/lib/gcloud/search/index.rb +++ b/lib/gcloud/search/index.rb @@ -200,7 +200,7 @@ def find doc_id # documents. By default (when it is not specified or set to 0), it is # set at the time the document is saved to the number of seconds since # January 1, 2011. The rank can be used in the +expressions+, +order+, - # and +return_fields+ options in #search, where it should referenced as + # and +fields+ options in #search, where it should referenced as # +_rank+. (+Integer+) # # === Returns @@ -444,18 +444,17 @@ def self.from_raw raw, conn #:nodoc: # +options+:: # An optional Hash for controlling additional behavior. (+Hash+) # options[:expressions]:: - # Customized expressions used in +order+ or +return_fields+. The - # expression can contain fields in Document, the built-in fields ( - # +_rank+, the document +rank+, and +_score+ if scoring is enabled) and - # fields defined in +expressions+. Each field expression is represented - # in a json object with +name+ and +expression+ fields. The expression - # value can be a combination of supported functions encoded in the - # string. Expressions involving number fields can use the arithmetical - # operators (+, -, *, /) and the built-in numeric functions (+max+, - # +min+, +pow+, +count+, +log+, +abs+). Expressions involving geopoint - # fields can use the geopoint and distance functions. Expressions for - # text and html fields can use the +snippet+ function. - # (+String+) + # Customized expressions used in +order+ or +fields+. The expression can + # contain fields in Document, the built-in fields ( +_rank+, the + # document +rank+, and +_score+ if scoring is enabled) and fields + # defined in +expressions+. Each field expression is represented in a + # json object with +name+ and +expression+ fields. The expression value + # can be a combination of supported functions encoded in the string. + # Expressions involving number fields can use the arithmetical operators + # (+, -, *, /) and the built-in numeric functions (+max+, +min+, +pow+, + # +count+, +log+, +abs+). Expressions involving geopoint fields can use + # the geopoint and distance functions. Expressions for text and html + # fields can use the +snippet+ function. (+String+) # options[:matched_count_accuracy]:: # Minimum accuracy requirement for Result::List#matched_count. If # specified, +matched_count+ will be accurate to at least that number. @@ -479,11 +478,11 @@ def self.from_raw raw, conn #:nodoc: # is 0. If not specified, the search results are automatically sorted by # descending +_rank+. Sorting by ascending +_rank+ is not allowed. # (+String+) - # options[:return_fields]:: + # options[:fields]:: # The fields to return in the Search::Result objects. These can be # fields from Document, the built-in fields +_rank+ and +_score+, and # fields defined in expressions. The default is to return all fields. - # (+String+) + # (+String+ or +Array+ of +String+) # options[:scorer]:: # The scoring function to invoke on a search result for this query. If # scorer is not set, scoring is disabled and +_score+ is 0 for all @@ -563,7 +562,7 @@ def self.from_raw raw, conn #:nodoc: # expressions = [{ name: "total_price", expression: "(price + tax)" }] # results = index.search "cotton T-shirt", # expressions: expressions, - # fields: [name, total_price, highlight] + # fields: ["name", "total_price", "highlight"] # # Just as in documents, Result data is accessible via Fields methods: # diff --git a/test/gcloud/search/index_test.rb b/test/gcloud/search/index_test.rb index 92bc0839e972..c3daa29fc100 100644 --- a/test/gcloud/search/index_test.rb +++ b/test/gcloud/search/index_test.rb @@ -433,14 +433,14 @@ results.size.must_equal 3 end - it "searches with return_fields set" do - return_fields = ["sku", "description"] + it "searches with fields set" do + fields = ["sku", "description"] mock_connection.get "/v1/projects/#{project}/indexes/#{index.index_id}/search" do |env| - env.params["returnFields"].must_equal return_fields + env.params["returnFields"].must_equal fields [200, {"Content-Type"=>"application/json"}, search_results_json(3)] end - results = index.search query, return_fields: return_fields + results = index.search query, fields: fields results.size.must_equal 3 end From 50ba9762c19d66b719e40b97a5dd109fbb5ed5bf Mon Sep 17 00:00:00 2001 From: Mike Moore Date: Thu, 10 Dec 2015 17:21:58 -0700 Subject: [PATCH 3/5] Fix search order examples --- lib/gcloud/search.rb | 2 +- lib/gcloud/search/index.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/gcloud/search.rb b/lib/gcloud/search.rb index 55e98cb06adf..d57ae8836fc5 100644 --- a/lib/gcloud/search.rb +++ b/lib/gcloud/search.rb @@ -243,7 +243,7 @@ def self.search project = nil, keyfile = nil, options = {} # search = gcloud.search # index = search.index "books" # - # results = index.search "dark stormy" , order: ["published", "-avg_review"] + # results = index.search "dark stormy", order: "published, avg_review desc" # documents = index.search query # API call # # You can add computed fields with the +expressions+ option, and limit the diff --git a/lib/gcloud/search/index.rb b/lib/gcloud/search/index.rb index e4cb0fc339a3..9289680bcf5f 100644 --- a/lib/gcloud/search/index.rb +++ b/lib/gcloud/search/index.rb @@ -547,7 +547,7 @@ def self.from_raw raw, conn #:nodoc: # search = gcloud.search # index = search.index "books" # - # results = index.search "dark stormy" , order: ["published", "-avg_review"] + # results = index.search "dark stormy", order: "published, avg_review desc" # documents = index.search query # API call # # You can add computed fields with the +expressions+ option, and limit the From f65fb59071c409479fbc1dad93860b14c8ead0ff Mon Sep 17 00:00:00 2001 From: Mike Moore Date: Thu, 10 Dec 2015 17:22:53 -0700 Subject: [PATCH 4/5] Fix search expressions documentation --- lib/gcloud/search/index.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gcloud/search/index.rb b/lib/gcloud/search/index.rb index 9289680bcf5f..c774db64a201 100644 --- a/lib/gcloud/search/index.rb +++ b/lib/gcloud/search/index.rb @@ -454,7 +454,7 @@ def self.from_raw raw, conn #:nodoc: # (+, -, *, /) and the built-in numeric functions (+max+, +min+, +pow+, # +count+, +log+, +abs+). Expressions involving geopoint fields can use # the geopoint and distance functions. Expressions for text and html - # fields can use the +snippet+ function. (+String+) + # fields can use the +snippet+ function. (+Hash+ or +Array+ of +Hash+) # options[:matched_count_accuracy]:: # Minimum accuracy requirement for Result::List#matched_count. If # specified, +matched_count+ will be accurate to at least that number. From 3f130be4b94e06dee9a87107599ebb5aedc47aeb Mon Sep 17 00:00:00 2001 From: Mike Moore Date: Thu, 10 Dec 2015 17:25:57 -0700 Subject: [PATCH 5/5] Fix search rank and score The search documentation has underscores, but that causes errors. Remove the underscored since that is how Cloud Search works. --- lib/gcloud/search/document.rb | 2 +- lib/gcloud/search/index.rb | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/gcloud/search/document.rb b/lib/gcloud/search/document.rb index 01872756ca4a..bee50933d015 100644 --- a/lib/gcloud/search/document.rb +++ b/lib/gcloud/search/document.rb @@ -88,7 +88,7 @@ def rank # not specified or set to 0), it is set at the time the document is # created to the number of seconds since January 1, 2011. The rank can be # used in Index#search options +expressions+, +order+, and - # +fields+, where it is referenced as +_rank+. + # +fields+, where it is referenced as +rank+. def rank= new_rank @raw["rank"] = new_rank end diff --git a/lib/gcloud/search/index.rb b/lib/gcloud/search/index.rb index c774db64a201..16e4686a75f0 100644 --- a/lib/gcloud/search/index.rb +++ b/lib/gcloud/search/index.rb @@ -201,7 +201,7 @@ def find doc_id # set at the time the document is saved to the number of seconds since # January 1, 2011. The rank can be used in the +expressions+, +order+, # and +fields+ options in #search, where it should referenced as - # +_rank+. (+Integer+) + # +rank+. (+Integer+) # # === Returns # @@ -445,8 +445,8 @@ def self.from_raw raw, conn #:nodoc: # An optional Hash for controlling additional behavior. (+Hash+) # options[:expressions]:: # Customized expressions used in +order+ or +fields+. The expression can - # contain fields in Document, the built-in fields ( +_rank+, the - # document +rank+, and +_score+ if scoring is enabled) and fields + # contain fields in Document, the built-in fields ( +rank+, the + # document +rank+, and +score+ if scoring is enabled) and fields # defined in +expressions+. Each field expression is represented in a # json object with +name+ and +expression+ fields. The expression value # can be a combination of supported functions encoded in the string. @@ -469,23 +469,23 @@ def self.from_raw raw, conn #:nodoc: # (+Integer+) # options[:order]:: # A comma-separated list of fields for sorting on the search result, - # including fields from Document, the built-in fields (+_rank+ and - # +_score+), and fields defined in expressions. The default sorting + # including fields from Document, the built-in fields (+rank+ and + # +score+), and fields defined in expressions. The default sorting # order is ascending. To specify descending order for a field, a suffix # " desc" should be appended to the field name. For # example: orderBy="foo desc,bar". The default value for # text sort is the empty string, and the default value for numeric sort # is 0. If not specified, the search results are automatically sorted by - # descending +_rank+. Sorting by ascending +_rank+ is not allowed. + # descending +rank+. Sorting by ascending +rank+ is not allowed. # (+String+) # options[:fields]:: # The fields to return in the Search::Result objects. These can be - # fields from Document, the built-in fields +_rank+ and +_score+, and + # fields from Document, the built-in fields +rank+ and +score+, and # fields defined in expressions. The default is to return all fields. # (+String+ or +Array+ of +String+) # options[:scorer]:: # The scoring function to invoke on a search result for this query. If - # scorer is not set, scoring is disabled and +_score+ is 0 for all + # scorer is not set, scoring is disabled and +score+ is 0 for all # documents in the search result. To enable document relevancy score # based on term frequency, set +scorer+ to +:generic+. # (+String+ or +Symbol+)