1 #include <Poco/JSON/Object.h>
2 #include <Poco/JSON/Array.h>
3 #include <Poco/JSON/JSON.h>
4 #include <Poco/JSON/Stringifier.h>
5 #include <Poco/JSON/Parser.h>
6 #include <Poco/JSON/JSONException.h>
7 #include <Poco/Dynamic/Var.h>
30 os <<
"Filter type = " << (
unsigned int)(filter.
getFilterType()) <<
" AttributeName: '" << filter.
attributeName <<
"' attributeValues: '";
37 os <<
" exclude: '" << std::boolalpha << static_cast<bool>(filter.
excludeValue) <<
"'";
65 vecFilters.push_back(pFilter);
80 Poco::JSON::Array::Ptr pArrayFilters =
new Poco::JSON::Array();
81 for (
size_t i=0;i<vecFilters.size();++i)
83 Poco::JSON::Object::Ptr obj =
new Poco::JSON::Object();
87 Poco::JSON::Array::Ptr pArray =
new Poco::JSON::Array();
89 for (
size_t k=0;k<vecFilters[i]->getAttributeValues().size();++k)
90 pArray->add(vecFilters[i]->getAttributeValues()[k]);
93 pArrayFilters->add(obj);
96 std::stringstream ostr;
97 Poco::JSON::Stringifier::stringify(pArrayFilters, ostr);
101 catch(std::exception& e)
117 Poco::JSON::Parser parser;
118 Poco::Dynamic::Var res = parser.parse(json);
119 Poco::JSON::Array::Ptr pArray = res.extract<Poco::JSON::Array::Ptr>();
121 for (
size_t i=0;i<pArray->size();++i)
123 Poco::Dynamic::Var tmp = pArray->get(i);
124 if (tmp.type()==
typeid(Poco::JSON::Object::Ptr))
126 Poco::SharedPtr<SphinxFilter> pFilter =
new SphinxFilter;
128 Poco::JSON::Object::Ptr obj = tmp.extract<Poco::JSON::Object::Ptr>();
131 if(tmp.isInteger() && !tmp.isSigned())
133 unsigned long filterType = tmp.convert<
unsigned long>();
136 throw Poco::JSON::JSONException(
"Wrong filter type param. Input value = "+std::to_string(filterType));
138 pFilter->setFilterType(static_cast<SphinxFilter::FilterType>(filterType));
145 if (attributeName.empty())
146 throw Poco::JSON::JSONException(
"Attribute name is empty.");
147 pFilter->setAttributeName(attributeName);
151 if (!pArrayVal.isNull())
153 for (
size_t j = 0;j <pArrayVal->size();++j)
155 tmp = pArrayVal->get(j);
157 pFilter->addAttributeValue(tmp.convert<std::string>());
159 if(tmp.isInteger() && !tmp.isSigned())
160 pFilter->addAttributeValue(std::to_string(tmp.convert<Poco::UInt64>()));
162 if (pFilter->getAttributeValues().empty())
163 throw Poco::JSON::JSONException(
"Array attribute values is empty.");
170 if(tmp.isInteger() && !tmp.isSigned())
171 excludeValue = static_cast<SphinxFilter::ExcludeType>(tmp.convert<
unsigned int>());
174 excludeValue = static_cast<SphinxFilter::ExcludeType>(std::stoul(tmp.convert<std::string>()));
176 pFilter->setExcludeValue(excludeValue);
181 catch(Poco::JSON::JSONException& e)
187 catch(std::exception& e)
198 for (
size_t i=0;i<filtersArray.vecFilters.size();++i)
199 os << *(filtersArray.vecFilters[i]);