Closed ZaheerUdDeen closed 6 years ago
Anyone can answer Please?
Hi @ZaheerUdDeen, one of us will be able to answer this tomorrow. Thank you for understanding.
@ZaheerUdDeen I believe the best way is using a view as I didn't find a clean solution using Cloudant Query or Search.
Here's an example using your point 1:
Create a view with each Ingrediants
element as key
. Something like:
function (doc) {
if(doc.productList) {
for(var prod in doc.productList) {
emit(doc.productList[prod].Ingrediants, doc.productList[prod]);
}
}
}
Now you can query the view using startkey
and endkey
and loop through the rows:
List<ViewResponse.Row<String, JsonElement>> rows = db.getViewRequestBuilder("newddoc", "new-view")
.newRequest(Key.Type.STRING, JsonElement.class)
.startKey("c")
.endKey("d")
.build()
.getResponse().getRows();
for(ViewResponse.Row row : rows) {
// Do something with each key and value
System.out.println(row.getKey());
System.out.println(row.getValue());
}
You should also be able to use the same idea above for your point 2.
closing - no further action
Scenario. I have a document in the database which has thousands of item in
productList
as below. All the object in arrayproductList
has the same shape and same fields with different values. Now I want to search in the following way. 1.when a user write 'c' againstIngrediants
field, the list will show allIngrediants
start with alphabet 'c'. 2..when a user write 'A' againstbrandName
field, the list will show allbrandName
start with alphabet 'A'.please give an example using this to search for it, either it is by -creating an index(json,text). -creating a Search index (design document). or -using views etc Note: I don't to create an index at runtime(I mean index could be define by Cloudant dashboard) I just want to query it, by this library in the application.
I have read the documentation's, I got the concepts. Now I want to implement it with the best approach. I will use this approach to handle all such scenarios in future.
Sorry if the question is stupid :)
thanks.