Create a document using : "_design/views103" (After selecting a database).
Enter "indexes" as key.
Enter following content after converting as JSON to value field:
Enter "indexes" as key.
Enter following content after converting as JSON to value field:
{ "search_name": { "index": "function(doc) { index("default", doc._id); if (doc['customerID']) { index("customerID", doc['customerID'], {"store": "yes"}); } }" } }
_id automatically used as index.
https://{name}.cloudant.com/animaldb/_design/views103/_search/animals?q={id}
Wild card searches are supported, for both single (?
) and multiple (*
) character searches.dat?
would match date and data,dat*
would match date, data, database, dates etc. Wildcards must come after a search term, you cannot do a query like*base
.
customerID is a key field in data object.
https://{name}.cloudant.com/transactions/_design/views103/_search/animals?q=customerID:%228547963512%22https://cloudant.com/for-developers/views/https://cloudant.com/for-developers/search/
With this index you can run any of these queries.
Desired result | Query |
---|---|
Birds | class:bird |
Animals that begin with the letter "l" | l* |
Carnivorous birds | class:bird AND diet:carnivore |
Herbivores that start with letter "l" | l* AND diet:herbivore |
Medium-sized herbivores | min_length:[1 TO 3] AND diet:herbivore |
Herbivores that are 2m long or less | diet:herbivore AND
min_length:[-Infinity TO 2] |
Mammals that are at least 1.5m long | class:mammal AND
min_length:[1.5 TO Infinity] |
Find "Meles meles" | latin_name:"Meles meles" |
Mammals who are herbivore or carnivore | diet:(herbivore OR
omnivore) AND class:mammal |
No comments:
Post a Comment