Titanium JIRA Archive
Appcelerator Community (AC)

[AC-5842] Query custom objects field with $text and $search

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionNeeds more info
Resolution Date2018-11-28T22:10:04.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsArrow Cloud, ArrowDB, Documentation, Studio
Labelsn/a
ReporterAndy Kirra
AssigneeShak Hossain
Created2018-08-17T16:34:32.000+0000
Updated2018-11-28T22:10:04.000+0000

Description

I have arrowdb custom objects that have a field named “message” I'm trying to perform a query by keywords on this field -> my query where obj:
where = { "message" : { "$text" : { "$search" : "keyword" } } }
Following the documentation: Perform a text search on the contents of the field. A $text expression has the following syntax:
{ "$text": { "$search": <string> }} 
Also here's an example from the documentation:
where={"$text": { "$search": "javascript,ruby,python,-php" }}
+PROBLEM+ I'm getting a 500 error: { "success": false, "error": true, "code": 500, "message": {} } +EXPECTED+ Perform a text search on the contents of the field message. +TEST CASE+ The following code has 2 functions: 1(doCreate) - creates a custom "report" object (with property message = 'abc aaa bbb ccc') 2(doSearch) - query the reports by field message (by keyword 'abc')
//QUERY THE FIELD MESSAGE OF THE PREVIOUSLY CREATED CUSTOM OBJ
function doSearch(e) {
	
Cloud.Objects.query({
    classname: 'report',
    page: 1,
    per_page: 10,
    where: {
    //WORKING QUERIES (give the expected result)
    	 //"message" : "abc aaa bbb ccc"
    	 //"message" : { "$regex": "^" + "abc"} 
    //NOT WORKING (Gives 500 error)
         "message" : { "$text" : {"$search" : "abc"} }
    }
	}, function (e) {
	    if (e.success) {
	        for (var i = 0; i < e.report.length; i++) {
	            var report = e.report[i];
	            Ti.API.info("report: "+JSON.stringify(report,null,2));
	        }
	    } else {
	       Ti.API.info('Error:\n' + JSON.stringify(e,null,2)); 
	    }
	});
}

//CREATE A CUSTOM OBJECT (to have an object to query )
function doCreate(e) {
	
Cloud.Objects.create({
    classname: 'report',
    fields: {
        message: 'abc aaa bbb ccc',
    }
	}, function (e) {
	    if (e.success) {
	    	
	        var report = e.report[0];
	        Ti.API.info("report: "+JSON.stringify(report,null,2));
	    } else {
	        alert('Error:\n' +
	            ((e.error && e.message) || JSON.stringify(e)));
	    }
	});
	
}

Comments

  1. Rakhi Mitro 2018-08-21

    Hello, Thanks for sharing with us. Can you please test this on latest SDK and let us know how it goes.
  2. Andy Kirra 2018-08-24

    Hi, Thanks for your answer, I get the same error on SDK 7.3.0. (code: 500)
  3. Rakhi Mitro 2018-08-26

    Hello, Thanks for your feedback. In which platform you are getting this error? Please attach complete test case and full console logs.

JSON Source