title: Limit couchdb-lucene results by key / specific field? map?
body: <p>I have a pretty straight-forward question.</p>
  
  <p>I am using couchdb-lucene to search the full text of my documents.</p>
  
  <p>My documents each have the following fields:</p>
  
  <p>_id</p>
  
  <p>_rev</p>
  
  <p>docID (the unique ID of the document from our system)</p>
  
  <p>title (title of the document)</p>
  
  <p>content (body of the document)</p>
  
  <p>userID (the user that owns the document)</p>
  
  <p>My design document looks likes this:</p>
  
  <pre><code>{
     "_id": "_design/lucene",
     "_rev": "10-770b7044393e067b7024a896ccf3c502",
     "fulltext": {
         "by_all": {
             "index": "function(doc) { var ret=new Document(); ret.add(doc.title); ret.add(doc.content); return ret }"
         },
         "by_title": {
             "index": "function(doc) { var ret=new Document(); ret.add(doc.title); return ret }"
         }
     }
  }
  </code></pre>
  
  <p>I couldn't figure out how to return the docID as part of the results, so I just made the ID equal to the docID for now, but I would like to understand how to return the docID since the design document above only returns the score and ID of the document. I would rather not have to set the ID to the same value as docID just to access it.</p>
  
  <p>When I run a request such as:</p>
  
  <p>localhost:5984/foo/_fti/_design/lucene/by_all?q=example~0.5f</p>
  
  <p>I get back a collection of all documents where the title or content field contains "example", and that's great, but how can I search for "example" in the title and content fields of ONLY the documents that have a specific userID? How can I pass in and use that value?</p>
  
  <p>I want to do something like this:</p>
  
  <p>localhost:5984/foo/_fti/_design/lucene/by_all?q=example~0.5f&amp;userId=123</p>
  
  <p>When I do: localhost:5984/foo/_fti/_design/lucene/by_all?q=example~0.5f it returns documents for all users, what do I need to do to limit the documents only to those belonging to a specific user? I don't want to search every document out of millions when only a few thousand are relevant to a specific user.</p>
  
  <p>Thanks!</p>
  
  <p>p.s. I know I can use a map in views: "map": "function(doc){ emit(doc._id, doc._rev)}"</p>
  
  <p>Is this relevant? Is there some way to use the map within the couchdb-lucene results? I couldn't figure out how to specify which value to use at the key for the map, so it was returning the ID by default, how can the key be set to use a specific field? Maybe map isn't even the right track... I don't know what to do here, I'm very new to both CouchDB and Lucene and don't really quite understand it all yet.</p>
  
  <p>Thanks again!</p>