Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Not compatible with CloudSearch API version 2013-01-01 #29

Open
ygee07 opened this issue Apr 20, 2014 · 13 comments
Open

Not compatible with CloudSearch API version 2013-01-01 #29

ygee07 opened this issue Apr 20, 2014 · 13 comments

Comments

@ygee07
Copy link

ygee07 commented Apr 20, 2014

Do you plan to support the newer API? This one seems to only support the 2011 API version.

@seban
Copy link

seban commented Apr 22, 2014

It is quite critical question I think. Is there any chance to support newer API version?

@itstommymorgan
Copy link
Owner

@Greyder @seban is there something in particular in the newer version of the API that you're looking for? Or is this just interest in keeping it current.

@seban
Copy link

seban commented Apr 23, 2014

I just want (must) to use the current version. My current app has requirements to use 2013-01-01 api version.

@drewda
Copy link

drewda commented Apr 29, 2014

Here's a temporary fix that you can use in the meantime, before Asari is updated. Add the following to any models that are indexed on CloudSearch:

@@asari_instance.api_version = '2013-01-01'

Seems like this new version of the CloudSearch API is backwards compatible, so it's just a matter of specifying the new version in the API's endpoint URLs.

@ygee07
Copy link
Author

ygee07 commented Apr 29, 2014

@wellbredgrapefruit it is an interest in keeping it current since there are a lot of enhancements, even in the console of CloudSearch, which the older API won't get benefit from. And the API has been released more than a year ago, so it's not actually very new now, it should already be the standard.

@drewda thanks for the temporary fix, but we'll not be using asari for now, since we need highlighting, and from what I know, there's no highlighting in the 2011 API.

@lgleasain
Copy link
Collaborator

It will be a good idea to support the new version of the API. With that being said there are some bigger itches that we are scratching on the indexing side before getting over to that. We would also welcome pull requests if you would like to help us to add some of this in.

@nickmalcolm
Copy link

+1

Using the old api version to access a new CloudSearch instance (which automatically has api version 2013-01-01) seems to return a 403 Forbidden. Could just be me doing it wrong though...

In addition, the return-fields is now just return, so trying to specify that gives Asari::SearchException: 400: Bad Request.

@lgleasain
Copy link
Collaborator

Ok, if you are willing to live on the edge and use the 1.0 branch we now have some support in for it. The ActiveAsari pieces now only work with 2013-01-01 and you can set Asari to use the new api by setting the CLOUDSEARCH_API_VERSION environment variable to 2013-01-01 . The forbidden error happens if you try to access the wrong version of the api (IE: you have set up the domain on the 2013-01-01 and try to access it with the 2011-02-01). I haven't had time to document this yet and some other pieces may still be missing, so please let me know if we are missing anything. This is also settable directly on a Asari object if you are using it that way.

@ygee07
Copy link
Author

ygee07 commented Aug 12, 2014

Hi, I tried using the 1.0 branch and I am getting this after using the asari_find method:

undefined method 'to_i' for ["10", {"title"=>"This is a title"}]:Array

Here's the stack trace:

/Users/Ygee/.rvm/gems/ruby-2.1.1/bundler/gems/asari-ff260e52324b/lib/asari/active_record.rb:181:in `block in asari_find'
/Users/Ygee/.rvm/gems/ruby-2.1.1/bundler/gems/asari-ff260e52324b/lib/asari/collection.rb:80:in `each'
/Users/Ygee/.rvm/gems/ruby-2.1.1/bundler/gems/asari-ff260e52324b/lib/asari/collection.rb:80:in `map'
/Users/Ygee/.rvm/gems/ruby-2.1.1/bundler/gems/asari-ff260e52324b/lib/asari/collection.rb:80:in `method_missing'
/Users/Ygee/.rvm/gems/ruby-2.1.1/bundler/gems/asari-ff260e52324b/lib/asari/active_record.rb:181:in `asari_find'
app/controllers/legal_forms_controller.rb:65:in `search'

@lexor90
Copy link

lexor90 commented Sep 1, 2014

Hi, any solution for the 400: BadRequest issue? I've tried by setting the env var to use the 2013 API (using the default also on branch 1.0 resulted in a 403 Forbidden) and now I'm getting the 400 errcode.

Thanks for your work,
Alex.

@lexor90
Copy link

lexor90 commented Sep 1, 2014

Ok I figured out what's the more specific message to this and it seems I'm missing something within the service configuration as it says

Field "name" does not exist in domain configuration (near operation with index 1; document_id 548231)

I'm going to investigate if this issue is related to the gem or not at all.
I will reply as soon as possible.

@lexor90
Copy link

lexor90 commented Sep 1, 2014

Yup, indeed I was missing a index field :))
Thank you for this gem.

@lexor90
Copy link

lexor90 commented Sep 4, 2014

Hi, trying to get the ActiveAsari class working with the 1.0 branch and 2013-01-01 api version I'm getting the following error:

NoMethodError: undefined method `to_i' for #<Array:0x007fd36b850778>

So by debugging the returned data I have something like ["id", data] for each record inside the array.
I don't know how previous api version worked but it is clear that the asari_findmethod is calling to_i on the array instead of the first element.

A quick patch made it work for me, appended the patch. I'd like to contribute by submitting the patch but I'm getting Double received unexpected message :api_version with (no args) running specs.

diff --git a/db/test.sqlite3 b/db/test.sqlite3
index 68cd4e8..b9884db 100644
Binary files a/db/test.sqlite3 and b/db/test.sqlite3 differ
diff --git a/lib/asari/active_record.rb b/lib/asari/active_record.rb
index 06e6cb8..bda954b 100644
--- a/lib/asari/active_record.rb
+++ b/lib/asari/active_record.rb
@@ -178,7 +178,12 @@ class Asari
       #   communicating with the CloudSearch server.
       def asari_find(term, options = {})
         records = self.asari_instance.search(term, options)
-        ids = records.map { |id| id.to_i }
+        if self.asari_instance.api_version == '2013-01-01'
+          ids = records.map { |record| record[0].to_i }
+        else
+          ids = records.map { |id| id.to_i }
+        end

         records.replace(Array(self.where("id in (?)", ids)))
       end

If you could help fixing specs I'll submit a pull request.
Thank you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants