You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Robert Newson <rn...@apache.org> on 2012/05/16 23:27:41 UTC
Re: couch-lucene hwo to refernce elements in a complex document?
This just means couchdb-lucene has encountered a document that doesn't
have a "headers" element. In general you should add guard clauses
anyway;
function(doc) {
if (doc.headers && doc.headers.core && doc.headers.core.user) {
var res = new Document();
res.add( doc.headers.core.user );
return res;
}
return null;
}
On 16 May 2012 21:38, Mike Kimber <mk...@kana.com> wrote:
> I have couch-lucene working when I index a top level element in my documents. However when I try and reference a sub element as I would with a couchdb view no results are returned. A extract from my document is:
>
> {
> "_id": "00023157-c1f8-4e39-ab9a-d56726739b8d",
> "_rev": "1-45cd4f7506ccede344d682904556be4b",
> "type": "maven-build-profile",
> "schema": "TODO-idOfSchemaDocument",
> "headers": {
> "started": 1328795714442,
> "core": {
> "user": "buildadm",
> "ip": "127.0.0.1",
> "executionId": "a607c818-c568-40a9-adbc-0844e6bf9a02"
> }
> }
> }
>
> The following works
>
> {
> "_id": "_design/lucene",
> "_rev": "19-1c7be47e52f8a65e9bb387e8c3251dd4",
> "language": "javascript",
> "fulltext": {
> "by_type": {
> "index": "function(doc) { var res = new Document(); res.add( doc. type); return res; }"
> }
> }
> }
>
> curl http://127.0.0.1:5999/_fti/local/build-profiles-raw-mk/_design/lucene/by_type?q= maven-build-profile
>
> The following does not:
>
> {
> "_id": "_design/lucene",
> "_rev": "19-1c7be47e52f8a65e9bb387e8c3251dd4",
> "language": "javascript",
> "fulltext": {
> "by_user": {
> "index": "function(doc) { var res = new Document(); res.add( doc.headers.core.user ); return res; }"
> }
> }
> }
>
>
> curl http://127.0.0.1:5999/_fti/local/build-profiles-raw-mk/_design/lucene/by_user?q=buildadm
>
> Log file wise it provides:
>
> 2012-05-16 21:33:01,980 WARN [build-profiles-raw-mk] _design/buildstats caused TypeError: Cannot read property "core" from undefined
> 2012-05-16 21:33:01,980 WARN [build-profiles-raw-mk] _design/buildstatsdetail caused TypeError: Cannot read property "core" from undefined
> 2012-05-16 21:33:02,062 WARN [build-profiles-raw-mk] _design/profiling caused TypeError: Cannot read property "core" from undefined
> 2012-05-16 21:33:02,063 WARN [build-profiles-raw-mk] _design/lucene caused TypeError: Cannot read property "core" from undefined
> 2012-05-16 21:33:17,039 INFO [build-profiles-raw-mk] View[name=_design/lucene/by_user, digest=482tp0k1h6vhiw1cs5humyido] now at update_seq 106
>
> I'm sure there is an easy answer to this, but to a javascript/couchdb newbie i'm confused as to why I can use doc.headers.core.user can be used in my couch map. But not in the above couch-lucene index.
>
> Thanks
>
> Mike
RE: couch-lucene hwo to refernce elements in a complex document?
Posted by Mike Kimber <mk...@kana.com>.
Ah, had not thought about that thanks and thanks for the tip!
Mike
-----Original Message-----
From: Robert Newson [mailto:rnewson@apache.org]
Sent: 16 May 2012 22:28
To: user@couchdb.apache.org
Subject: Re: couch-lucene hwo to refernce elements in a complex document?
This just means couchdb-lucene has encountered a document that doesn't
have a "headers" element. In general you should add guard clauses
anyway;
function(doc) {
if (doc.headers && doc.headers.core && doc.headers.core.user) {
var res = new Document();
res.add( doc.headers.core.user );
return res;
}
return null;
}
On 16 May 2012 21:38, Mike Kimber <mk...@kana.com> wrote:
> I have couch-lucene working when I index a top level element in my documents. However when I try and reference a sub element as I would with a couchdb view no results are returned. A extract from my document is:
>
> {
> "_id": "00023157-c1f8-4e39-ab9a-d56726739b8d",
> "_rev": "1-45cd4f7506ccede344d682904556be4b",
> "type": "maven-build-profile",
> "schema": "TODO-idOfSchemaDocument",
> "headers": {
> "started": 1328795714442,
> "core": {
> "user": "buildadm",
> "ip": "127.0.0.1",
> "executionId": "a607c818-c568-40a9-adbc-0844e6bf9a02"
> }
> }
> }
>
> The following works
>
> {
> "_id": "_design/lucene",
> "_rev": "19-1c7be47e52f8a65e9bb387e8c3251dd4",
> "language": "javascript",
> "fulltext": {
> "by_type": {
> "index": "function(doc) { var res = new Document(); res.add( doc. type); return res; }"
> }
> }
> }
>
> curl http://127.0.0.1:5999/_fti/local/build-profiles-raw-mk/_design/lucene/by_type?q= maven-build-profile
>
> The following does not:
>
> {
> "_id": "_design/lucene",
> "_rev": "19-1c7be47e52f8a65e9bb387e8c3251dd4",
> "language": "javascript",
> "fulltext": {
> "by_user": {
> "index": "function(doc) { var res = new Document(); res.add( doc.headers.core.user ); return res; }"
> }
> }
> }
>
>
> curl http://127.0.0.1:5999/_fti/local/build-profiles-raw-mk/_design/lucene/by_user?q=buildadm
>
> Log file wise it provides:
>
> 2012-05-16 21:33:01,980 WARN [build-profiles-raw-mk] _design/buildstats caused TypeError: Cannot read property "core" from undefined
> 2012-05-16 21:33:01,980 WARN [build-profiles-raw-mk] _design/buildstatsdetail caused TypeError: Cannot read property "core" from undefined
> 2012-05-16 21:33:02,062 WARN [build-profiles-raw-mk] _design/profiling caused TypeError: Cannot read property "core" from undefined
> 2012-05-16 21:33:02,063 WARN [build-profiles-raw-mk] _design/lucene caused TypeError: Cannot read property "core" from undefined
> 2012-05-16 21:33:17,039 INFO [build-profiles-raw-mk] View[name=_design/lucene/by_user, digest=482tp0k1h6vhiw1cs5humyido] now at update_seq 106
>
> I'm sure there is an easy answer to this, but to a javascript/couchdb newbie i'm confused as to why I can use doc.headers.core.user can be used in my couch map. But not in the above couch-lucene index.
>
> Thanks
>
> Mike