Search code examples
lucenefull-text-searchcouchdbcloudant

Enable Full Text Search in Apache CouchDB


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.


Solution

  • 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