0
votes

I have followed the blog entry here to enable full text search https://developer.ibm.com/dwblog/2015/text-search-apache-couchdb/#.Vly24SCrQbV

I have everything correctly set up, and have also tried with other peoples docker images.

How do you set up a search? What documents are needed.

I have created a database called cats with one document

{
  "_id": "6f35d75b476517e2fc0b3eb12c000e72",
  "_rev": "1-c9a6b4734c83287499e8bbd6d1339050",
  "name": "tibbles"
}

And a design/view

{
  "_id": "_design/cat_look",
  "_rev": "1-aae457e6edf5e4a3f69357e5a2160fcc",
  "views": {
    "kitty_name": {
     "map": "function (doc) {\n  index(\"kittyName\", doc.name, {\"store\": true});\n}"
     }
   },
  "language": "javascript"
}

If I go to http://localhost:15984/cats/_design/cat_look/_search/kitty_name?q="*"

I get

{"error":"not_found","reason":"kitty_name not found."}

Thanks for any help on this, I am very lost.

2

2 Answers

0
votes

A Lucene search index is set up differently to how a Map Reduce view is done. In your code, it looks like you've tried to use a Map Reduce view. For Lucene, first you need to set up an index:

{
    "_id": "_design/Cat_look",
    "indexes": {
        "kitty_name": {
            "index": "function(doc){ ... }"
        }
    }
}

Consult Cloudant's docs on the subject: https://console.bluemix.net/docs/services/Cloudant/api/search.html#search

0
votes

Thanks for your help, you are right I set up the Lucene search index incorrectly. Here is the code to get a simple example working for anyone else lost.

If you have docker setup

docker run -d -p 15984:15984 ncheaz/couchdb:search

to get couchdb search on local port 15984

The document to search

{
  "_id": "6f35d75b476517e2fc0b3eb12c000e72",
  "_rev": "1-c9a6b4734c83287499e8bbd6d1339050",
  "name": "tibbles"
}

The Search Index. Create a new document, not a new view.

{
  "_id": "_design/cat_look",
  "_rev": "2-23f6ab0606a603cbef04653d167585d4",
  "views": {},
  "language": "javascript",
  "indexes": {
    "kitty_name": {
      "analyzer": "simple",
      "index": "function (doc) {if (doc.name) {index(\"name\", doc.name, {\"store\":true});  }}"
    }
  }
}

The url to search for the cats name is

http://localhost:15984/cats/_design/cat_look/_search/kitty_name?q=name:tibbl*

note that kitty_name is the name of the _search and name is the index name.

I recommend anyone struggling to get this working to create a free trial account on IBM Cloudant as the documentation directly relates to their product and it is a lot easier to follow.