Reputation:
I am developing an web application on GWT Framework (JAVA). I am using CouchDB(NoSQL Database) for storing user profile, user question and answers. I am new in NoSQL Database so i need to implement full text search in my application.
Example : " What is Java ?"
Desired Result : It could be found all the question which have all three words What, is, Java .
So there is any idea how to achieve this result in couchdb.
Upvotes: 2
Views: 1518
Reputation: 11
You can implement it using CouchDB List Functions.
I have a document where I need to search for keywords in name and description field. So, I created a view which will emit doc id as key and doc.name,doc._id,doc.description as value.
Now I created a List function which will use Javascript match function and give me the matching list of doc ids.
Sample Query: http://localhost:5984/dashboard/_design/testSearch/_list/results/ByName?searchQuery=What is Java
{
"_id": "_design/testSearch",
"lists": {
"results": "function(head, req) { var query= new RegExp(req.query.searchQuery,'i'); var arr=new Array(); var key; var row; while(row = getRow()) { if(row.value[0].match(query) || row.value[2].match(query)) { arr.push([row.value[0].toUpperCase(),row.value[1]]); key = row.key;}} arr.sort(); send('{\"'+key+'\":\"'+arr+'\"}');}"
},
"views": {
"ByName": {
"map": "function (doc) {\n if((doc.isdeleted==\"false\" || doc.isdeleted==false) && doc.userid && doc.name){\n emit(doc._id,[doc.name,doc._id,doc.description]);\n }\n}"
}
},
"language": "javascript"
}
Upvotes: 1
Reputation: 16050
Use couchdb lucene The integration with couchdb is straightforward and it would be perfect for your use case. Couch-db lucene supports the entire query syntanx of lucene. For your problem the + could be used.
The "+" or required operator requires that the term after the "+" symbol exist somewhere in a the field of a single document.
Here is a sample query
http://localhost:5984/_fti/local/database/_design/design_name/index_name?q=+"What is java"
Upvotes: 2