Following is our document sample -
{
"_id": “asset::021d7aa1-8d1c-4a04-8d25-c09f4a4ab4fc”,
"_rev": “4-20f98b257c66403033b9891af66cd36f”,
“assetBarcode”: null,
“assetDescription”: “Jet MM-0300 3T Lever Tool”,
“assetDiagram”: null,
“assetGPSLat”: null,
“assetGPSLong”: null,
“assetImage”: “080b6c60-b4ac-4b64-b20e-72ff3fc21c03”,
“assetLocation”: {
“id”: “location::54101::287308”,
“name”: “Site”,
“parentId”: “location::54101::78a93935-2124-4e51-9b21-f61c44fb75a0”
},
“assetNumber”: “AD-Asset#w76”,
“attributes”: [
{
“attributeId”: “attribute::3119”,
“attributeName”: “Hoist Type”,
“attributeType”: “TEXT50”,
“attributeValue”: “Chain Lever Hoist”
},
{
“attributeId”: “attribute::3121”,
“attributeName”: “Serial Number”,
“attributeType”: “TEXT50”,
“attributeValue”: “”
},
{
“attributeId”: “attribute::16691”,
“attributeName”: “Hoist Manufacturer”,
“attributeType”: “TEXT50”,
“attributeValue”: “Jet”
},
{
“attributeId”: “attribute::3120”,
“attributeName”: "Model ",
“attributeType”: “TEXT50”,
“attributeValue”: “MM”
},
{
“attributeId”: “attribute::3123”,
“attributeName”: “Capacity Tons”,
“attributeType”: “TEXT50”,
“attributeValue”: “3”
},
{
“attributeId”: “attribute::10444”,
“attributeName”: “PO #”,
“attributeType”: “TEXT50”,
“attributeValue”: “”
},
{
“attributeId”: “attribute::3124”,
“attributeName”: “Capacity Lbs”,
“attributeType”: “TEXT50”,
“attributeValue”: “6000”
},
{
“attributeId”: “attribute::3125”,
“attributeName”: “No. of Chain Falls”,
“attributeType”: “TEXT50”,
“attributeValue”: “1”
},
{
“attributeId”: “attribute::3122”,
“attributeName”: “Lift-Ft”,
“attributeType”: “TEXT50”,
“attributeValue”: “”
}
],
“category”: {
“categoryId”: “category::13616”,
“categoryName”: “Hoist and Puller”,
“icoSourceCat”: “0”,
“legacyDontUse”: true
},
“channels”: [
“64.SHRW”
],
“chipIds”: null,
“createdByTID”: 64,
“createdDate”: “2017-06-17T09:38:50.004604Z”,
“createdDateTicks”: -636332891300046080,
“dataOwnerTID”: 0,
“expiryDate”: “2017-06-29T11:30:00+05:30”,
“files”: [
{
“Labels”: “Diagram”,
“azureBlobUID”: “b838c19c-e806-4a85-a2eb-3c9792b7c1e0”,
“containerName”: null,
“description”: “test”,
“effectiveDate”: “2017-06-17T11:30:00+05:30”,
“fileName”: “06172017033721.jpg”,
“filePath”: “/data/data/com.TESSALink.Android/files/InfoChip/64/Upload/06172017033721.jpg”,
“label”: [
“Diagram”
]
}
],
“filledFormSummary”: [
{
“completedDate”: “2017-06-17T12:32:21.224172Z”,
“formDocumentId”: “filledForm::b38786fd-dbfd-4748-86de-7d64353257a0”,
“formId”: “form::64::-1”,
“formType”: “Scrap”,
“name”: “Scrap Form”,
“result”: “FAIL”
}
],
“inServiceDate”: “2017-06-17T11:30:00+05:30”,
“isDeleted”: false,
“lastCompletedWorkDate”: null,
“modelAndPart”: {
“modelId”: null,
“modelNumber”: null,
“partDescription”: null,
“partId”: null,
“partNumber”: null
},
“modifiedDate”: “2017-06-17T09:38:50.004554Z”,
“nextCompletedWorkDate”: null,
“outServiceDate”: null,
“owner”: {
“id”: “tenant::54101”,
“name”: “C & A STEEL (1983) Ltd.”
},
“parentId”: null,
“rentalStatus”: null,
“serialNumber”: “Ser#w76”,
“status”: “Scrapped”,
“tenantId”: “tenant::64”,
“thumbnailImage”: null,
“type”: “asset”,
“version”: null
}
We need to perform quick search on following properties -
assetNumber,
serialNumber,
assetBarcode,
chipIds (- this is string array).
For advance search properties are -
assetNumber,
assetDescription,
category,
owner,
assetLocation,
serialNumber,
assetBarcode,
chipIds,
createdDate,
status,
expiryDate,
inServiceDate,
modelAndPart.
We created following view -
{
MapDelegate assetViewFilterMapDelegate = (doc, emit) =>
{
try
{
if (doc["_id"].ToString().StartsWith(Constants.AssetDocumentID))
{
List keys = new List();
keys.Add(doc[“assetNumber”]);
keys.Add(doc[“serialNumber”]);
keys.Add(doc[“assetBarcode”]);
keys.Add(doc[“chipIds”]);
emit(keys, doc);
}
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
};
var allAssetsView = database.GetView(Constants.AllAssetsView);
allAssetsView.SetMap(assetViewFilterMapDelegate, "1");
}
Following is the query created to fetch the data -
public List GetAllDocuments(string viewName, List keys, int startPosition = -1, int recordCount = Constants.MaxDefaultRecordsToFetch)
{
var objRetValue = new List();
try {
if (null != database) {
var assetsDocsView = database.GetView(viewName);
var query = assetsDocsView.CreateQuery();
List<Object> allKeys = new List<Object>();
if (startPosition >= 0) {
query.Skip = startPosition;
}
allKeys.Add(keys);
query.Keys = allKeys;
query.Limit = recordCount > 0 ? recordCount : query.Limit;
var rows = query.Run();
objRetValue = rows.Select(result => JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(result.Value, Formatting.Indented))).ToList();
}
} catch (Exception e) {
Debug.WriteLine(e.Message);
}
return objRetValue;
}
We call the GetAllDocuments as -
List allKeys = new List();
allKeys.Add(“searchToken”);
allKeys.Add(“searchToken”);
allKeys.Add(“searchToken”);
allKeys.Add(“searchToken”);
List searchedAssets = GetAllDocuments(Constants.AllAssetsView, allKeys) ;