Christian Meichtry
Christian Meichtry

Reputation: 95

CouchDB find by search term

I import a CSV file to CouchDB with the correct structure.

Now I would like to search for records matching one search term in ANY of the fields. Here is an example record :

{
  "_id": "QW141401",
  "_rev": "1-7aae4ce6f6c148d82d7d6e1e3ba28542",
  "PART": {
    "ONE": "QUA01135",
    "TWO": "W/364",
    "THREE": "QUA04384",
    "FOUR": "QUA12167"
  },
  "FOO": {
    "BAR": "C40"
  },
  "DÉSIGNATION": "THE QUICK BROWN FOX"
}

Now given a search term, for example QUA04384 this record should come up. Aloso for C40. And, if possible, also for a partial match like FOX

The keys under PART and FOO can change from record to record...

Upvotes: 1

Views: 182

Answers (2)

Mark Leighton Fisher
Mark Leighton Fisher

Reputation: 5703

A stupid way to do this is to build an additional field (call it 'fulltext') in each Lucene document, containing the concatenation of all other field values. (Remember to build this completely dynamically so that every single field has its contents in this additional field no matter what the original field name was.) Then you can perform your searches on this 'fulltext' field.

Upvotes: 0

Juanjo Rodriguez
Juanjo Rodriguez

Reputation: 2131

This could be a similar question. Probably you are looking for a Full Text Search mechanism.

Yo can try with couchdb-lucene or elasticseach

Upvotes: 1

Related Questions