コード例 #1
0
ファイル: Utils.cpp プロジェクト: Garfonso/webOsSyncML-2.0
std::vector<Funambol::WString>& BlockingServiceCall(const char* method, const Funambol::WString& parameters,const Funambol::WString& param2)
{
	pthread_mutex_lock(&callbackMutex);
	globalResults.clear();
	partlyResult = "";
	const char* params[2];
	params[0] = fromWString(parameters);
	params[1] = fromWString(param2);
	PDL_Err error = PDL_CallJS(method,params,2);
	if(error == PDL_NOERROR)
	{
		Funambol::LOG.debug("Set of callback, now blocking till result received.");
		pthread_cond_wait(&callbackReady,&callbackMutex);
		Funambol::LOG.debug("Callback succeeded.");
	}
	else
	{
		Funambol::LOG.error("Could not start callback. Error: %s (%d).",PDL_GetError(),error);
	}
	pthread_mutex_unlock(&callbackMutex);
	return globalResults;
}
コード例 #2
0
const char* WebModelUnified::website_search(const char* req){
    JSONObject root;
    JSONArray jsarray;
    Connection* conn = connect();
    Query query = conn->query();

    string reqstr(req);
    string reqstr_spaced = replaceChar(reqstr, '+', ' ');
    vector<string> splittedstr;
    split(splittedstr, reqstr_spaced, boost::algorithm::is_any_of(" "));

    int titleForce = 10;
    int descriptionForce = 1;
    int urlForce = 3;

    query << "SELECT * , ";
    //Occurences total
    for(size_t i1 = 0; i1 < splittedstr.size(); i1++)
    {
        string s = splittedstr[i1];
        if(i1 != 0){
            query << " + ";
        }

        query << "((" <<
          titleForce << " * (char_length(title) - char_length(replace(title,'" << s << "',''))) + " <<
          descriptionForce << " * (char_length(description) - char_length(replace(description,'" << s << "',''))) + " <<
          urlForce << " * (char_length(url) - char_length(replace(url,'" << s << "','')))" <<
        ") / char_length('" << s << "'))";
    }
    query << " as Occurances " << " FROM website ";

    //Where clause
    for(size_t i1 = 0; i1 < splittedstr.size(); i1++)
    {
        string s = splittedstr[i1];
        if(i1 == 0) {
            query << "WHERE ";
        } else {
            query << "OR ";
        }
        query << "(url LIKE '%" << s << "%' or title LIKE '%" << s << "%' or description LIKE '%" << s << "%') ";
    }

    query << " ORDER BY " << "Occurances desc, title ASC ";

    StoreQueryResult ares = query.store();
    unsigned int numrow = ares.num_rows();

    for(unsigned int i = 0; i < numrow; i++)
    {
        JSONObject result;

        result[L"title"] = new JSONValue(wchartFromChar(ares[i]["title"]));
        result[L"description"] = new JSONValue(wchartFromChar(ares[i]["description"]));
        result[L"url"] = new JSONValue(wchartFromChar(ares[i]["url"]));
        JSONValue* resultVal = new JSONValue(result);

        jsarray.push_back(resultVal);
    }

    root[L"results"] = new JSONValue(jsarray);

    JSONValue* jvalue = new JSONValue(root);

    const char* returnStr = fromWString(jvalue->Stringify());
    delete jvalue;
    return returnStr;
}