cloudant / python-cloudant

A Python library for Cloudant and CouchDB
Apache License 2.0
163 stars 55 forks source link

Unable to find attribute add_search_index for Design Document #212

Closed ayushidalmia closed 8 years ago

ayushidalmia commented 8 years ago

I do the following:

from cloudant import cloudant
import json
from cloudant.result import Result,ResultByKey
import random
from cloudant.design_document import DesignDocument

with open('credentials.json') as f:
    cred  = json.load(f)

with cloudant(str(cred['credentials']['username']),str(cred['credentials']['password']),url=str(cred['credentials']['url'])) as client:

    my_database = client['my_database']

ddoc = DesignDocument(my_database,"_design/DDOC/_view/INDEX")
ddoc.add_view("newView","function(doc) {if(doc.filename) {emit(doc._id, doc.filename);}}")
print ddoc.list_views()
search_index = ('function (doc) {\n  index("default", doc._id); '
                        'if (doc._id) {index("name", doc.filename, '
                        '{"store": true}); }\n}')   
ddoc.add_search_index("freesearch", add_search_index, analyzer=None)

I get the error:

Traceback (most recent call last):
  File "views.py", line **, in <module>
    ddoc.add_search_index("freesearch", search_index, analyzer=None)
AttributeError: 'DesignDocument' object has no attribute 'add_search_index'

It prints the ddoc.list_views nicely.

My Python version is 2.7 and python cloudant version is (2.0.3)

After I upgraded to version 2.1.0, I get the following error:

Traceback (most recent call last):
  File "views.py", line **, in <module>
    ddoc.add_search_index("freesearch", add_search_index, analyzer=None)
NameError: name 'add_search_index' is not defined
rhyshort commented 8 years ago

Hi, add_search_index is part of the 2.1.0 release, please update to 2.1.0 if you wish to use this function.

ayushidalmia commented 8 years ago

@rhyshort , I upgraded. Now it is giving me a name error. Please suggest a solution or open the issue.

ayushidalmia commented 8 years ago

Sorry. My bad. It works. There was some type in the add_search_index command.

rhyshort commented 8 years ago

Great, glad you've got it working.