Click here to Skip to main content
15,887,897 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
I am using Parse.com and access it using Javascript. I want to search data in such a manner that it will not search for case sensitive like if i search abc then it will give abc, Abc, ABC,aBc etc all. but currently it gives only abc.

JavaScript:
var search_data="Temp";
var product = Parse.Object.extend("product");
var query = new Parse.Query(product);

query.contains("name",search_data); 
query.find({
     success: function(results) {
        console.log("Total Product Found : "+results.length);
        printSearchProducts(results,query); //custom method to print product detail
     },
     error: function(error) {
         console.log("Error: " + error.code + " " + error.message);
     }
 });


Actual Result: Temp1,Temp2,Temp3,ProductTemp3,Temp4Product etc.
Required Result: Temp1,Temp2,Temp3,ProductTemp3,Temp4Product,temp5,producttemp6,TEMP7,tEMp8 etc.
Posted
Comments
ZurdoDev 12-Sep-13 7:33am    
Have you read the documentation and/or asked parse.com?
Shashi Badhuk 12-Sep-13 8:10am    
Hi RyanDev
yes, i have asked parse.com too about this issue but i did not get any reply yet from them that is why i posted my problem here.
Thanks.

1 solution

I have solved this issue.
I remove constraint query.contains("name",search_data); and apply manual search using java script inside printSearchProducts method like:
var search_data="Temp";
var product = Parse.Object.extend("product");
var query = new Parse.Query(product);
query.limit(500);
query.find({
    success: function(results) {
         printSearchProducts(results,query,search_data); 
    }, 
    error: function(error) {
         console.log("Error: " + error.code + " " + error.message);
   } 
});

printSearchProducts Method Where search manually via Java Script.
function printSearchProducts(results,query,search_data) {
    var counter = results.length; 
    var productName = '',i=0; 
    search_data = search_data.toLowerCase(); 
    if(counter){
        while(i<counter){>
            var found = -1;
            productName = results[i].get("name");
            var lower_name = productName.replace(/[^a-zA-Z]/g,'_').toLowerCase();
            found = lower_name.indexOf(search_data);
            if(found>=0) {
                  //Access or print the required result here 
            } 
            i++;
        }
    }  
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900