Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support using indexes for lucene searches on e.g cloudant #219

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
npm-debug.log
test/fixtures/README.md
test/fixtures/not-found.txt
test/fixtures/not-found.txt
.idea
11 changes: 7 additions & 4 deletions lib/cradle/database/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ Database.prototype.save = function (/* [id], [rev], doc | [doc, ...] */) {
Database.prototype._save = function (id, rev, doc, callback) {
var options = this.connection.options;
var document = {}, that = this;

// Bulk Insert
if (Array.isArray(doc)) {
document.docs = doc;
Expand All @@ -113,9 +112,13 @@ Database.prototype._save = function (id, rev, doc, callback) {
// PUT a single document, with an id (Create or Update)
if (id) {
// Design document
if (/^_design\/(\w|%|\-)+$/.test(id) && !('views' in doc)) {
document.language = "javascript";
document.views = doc;
if (/^_design\/(\w|%|\-)+$/.test(id) && !('views' in doc) ) {
if( !doc.indexes ){
document.language = "javascript";
document.views = doc;
} else {
document.indexes = doc.indexes
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to harp on this, but the whitespace here is wrong. Cradle mostly follows my StyleGuide except that it uses 4-space soft indents (instead of 2-space soft indents).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh Ii have the habit of using ide reformatting. Will fix

} else {
document = doc;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cradle",
"version": "0.6.6",
"version": "0.6.7",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't bump versions in a pull-request. You're making a decision for the author that might be incorrect.

"description": "the high-level, caching, CouchDB library",
"url": "http://cloudhead.io/cradle",
"keywords": ["couchdb", "database", "couch"],
Expand Down
16 changes: 16 additions & 0 deletions test/database-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ function shouldQueryCouch(name) {
},
"creates a new document (201)": macros.status(201)
},
"with indexes as root node" : {
topic: function (db) {
db.save('_design/search_couch_lucene', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this view defined? It should be seeded before querying. I don't know much about Lucene + CouchDB

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean search_view ? that is misleading from my part.It is the name og the exact search index

indexes: {
search_view:{
index: function(doc){index('default', doc.name);
}
}
}
}, this.callback);
},
"creates a new document (201)": macros.status(201),
"returns the revision": function (res) {
assert.ok(res.rev);
}
},
"with a '_design' id": {
topic: function (db) {
db.save('_design/horses', {
Expand Down