'in(..)' function not working in SoQL query - soql

Using SoQL (Socrata Query Language) we can filter the values of a data set using the in(...) function.
A sample example is shown in the socrata website using the Chicago open data portal.
https://data.cityofchicago.org/resource/6zsd-86xi.json?$where=primary_type in('THEFT', 'ROBBERY', 'INTIMIDATION')
But when I try this functionality using a different data set of the same data portal I don't get the answer. Here is the SoQL I used
https://data.cityofchicago.org/resource/uupf-x98q.json?$where=police_district in('12','24')
I get the following error.
{
"code" : "query.compiler.malformed",
"error" : true,
"message" : "Error, could not parse SoQL query \"select * from #uupf-x98q where police_district in('12','24')\"",
"data" : {
"query" : "select * from #uupf-x98q where police_district in('12','24')"
}
}

In the case of your second query, you're accessing it via a filtered view which limits some of the things you can do with that API endpoint. If you follow the link to the API Documentation for that dataset ("Export" -> "SODA API" -> "API Docs") it'll bring you to the dataset-level API docs where you'll have more success.
For the first query, I'd recommend you migrate to it's new API endpoint, where you'll find performance to be a lot better. It should be as simple as swapping out the dataset identifier or base URL in your query.

Related

Meteor Publish/Subscribe passing object with string parameter issue

I am trying to pass a object { key:value} and send it to meteor publish so i can query to database.
My Mongo db database has (relevant datas only) for products:
products : {
categs:['Ladies Top','Gents'],
name : Apple
}
In meteor Publish i have the following:
Meteor.publish('product', (query) =>{
return Clothings.find(query);
})
In client i use the following to subscribe:
let query = {categs:'/ladies top/i'}; // please notice the case is lower
let subscribe = Meteor.subscribe('product',query);
if (subscribe.ready()){
clothings = Products.find(query).fetch().reverse();
let count = Products.find(query).fetch().reverse().length; // just for test
}
The issue is, when i send the query from client to server, it is automatically encoded eg:
{categs:'/ladies%top/i'}
This query doesnot seem to work at all. There are like total of more than 20,000 products and fetching all is not an option. So i am trying to fetch based on the category (roughly around 100 products each).
I am new to ,meteor and mongo db and was trying to follow existing code, however this doesnot seem to be correct. Is there a better way to improve the code and achieve the same ?
Any suggestion or idea is highly appreciated.
I did go through meteor docs but they dont seem to have examples for my scenario so i hope someone out there can help me :) Cheers !
Firstly, you are trying to send a regex as a parameter. That's why it's being encoded. Meteor doesn't know how to pass functions or regexes as parameters afaict.
For this specific publication, I recommend sending over the string you want to search for and building the regex on the server:
client:
let categorySearch = 'ladies top';
let obj = { categorySearch }; // and any other things you want to query on.
Meteor.subscribe('productCategory',obj);
server:
Meteor.publish('productCategory',function(obj){
check(obj,Object);
let query = {};
if (obj.categorySearch) query.category = { $regex: `/${obj.categorySearch}/i` };
// add any other search parameters to the query object here
return Products.find(query);
});
Secondly, sending an entire query objet to a publication (or Method) is not at all secure since an attacker can then send any query. Perhaps it doesn't matter with your Products collection.

CosmosDB - Is there a way to get MongoDB API RequestCharge

So, when using MongoDB API with C# driver against CosmosDB, can we somehow get RequestCharge from CosmosDB response for each query?
So, for anyone struggling with same thing, here is the solution.
Cosmos DB MongoDB API has dedicated command called: getLastRequestStatistics
ref: https://learn.microsoft.com/en-us/azure/cosmos-db/request-units
So, immediately after a real query is executed, one should trigger:
var result = this._db.RunCommand<BsonDocument>(new BsonDocument{{ "getLastRequestStatistics", 1 }});
And that will give actual response from Cosmos DB with real cost. Response looks like:
{
"_t" : "GetRequestStatisticsResponse",
"ok" : 1,
"CommandName" : "find",
"RequestCharge" : 5.5499999999999998,
"RequestDurationInMilliSeconds" : NumberLong(25)
}

Obtaining topic description in search api

I seem to be having problem pulling out the text content of the following query without making another call:
http://tinyurl.com/mgsewz2 via the mqlread api
{
"id": "/en/alcatraz_island",
"/common/topic/description": [{}],
"/common/topic/topic_equivalent_webpage": [],
"/common/topic/official_website": null
}
I can't retrieve the following
description
equivalent webpage (I'm looking for the en wiki page)
, but I can obtain the official_website url.
It looks like I can get it via the search api via output= but I can't walk through the entire set that I'm looking for without getting search request is too large error.
http://markmail.org/message/hd6pcveta7bhuz25#query:+page:1+mid:u7xegxlhtmhwiqbl+state:results
Thanks!
It you want to download large subsets of Freebase data, your best bet is to use the Freebase RDF Dumps. They contain all the properties that you listed above.

Using the Freebase search api mql_output parameter to obtain linked data

I am trying to use the freebase search API to obtain the parties of specific politicians as well as general biographical data (using php). I know that the search api passes the id of each search result found to an MQL query specified by the mql_output parameter.
Here is the MQL query I have at the moment which I use for the mql_ouput parameter
{
"name":null,
"/people/person/date_of_birth":null,
"/people/person/gender":null,
"/wikipedia/topic/en_id":null,
"id":null,
"/government/politician/party":[
{
party : null
}
]
}
and this is the resultant query url
https://www.googleapis.com/freebase/v1/search?Barrack%20Obama&filter=%28all%20type%3Apolitician%29&mql_output=%7B%22name%22%3Anull%2C%22%5C%2Fpeople%5C%2Fperson%5C%2Fdate_of_birth%22%3Anull%2C%22%5C%2Fpeople%5C%2Fperson%5C%2Fgender%22%3Anull%2C%22%5C%2Fwikipedia%5C%2Ftopic%5C%2Fen_id%22%3Anull%2C%22id%22%3Anull%2C%22%5C%2Fgovernment%5C%2Fpolitician%5C%2Fparty%22%3A%5B%7B%7D%5D%7D&key=AIzaSyDdJ_9L6mcWXinx5Lehku2TULmJhOMESew&indent=true
Thanks for your help, sorry that it's quite basic question,
Mark
Answer
Could not self answer due to not enough forum rep.
I just realised what I needed to do after going over some more examples. To have the database retrieve the party information I needed to use the following query.
{
"name":null,
"/people/person/date_of_birth":null,
"/people/person/gender":null,
"/wikipedia/topic/en_id":null,
"id":null,
"/government/politician/party":{
"party" : null
}
}
Mark
I just realised what I needed to do after going over some more examples. To have the database retrieve the party information I needed to use the following query.
{ "name":null, "/people/person/date_of_birth":null, "/people/person/gender":null, "/wikipedia/topic/en_id":null, "id":null, "/government/politician/party":{ "party" : null } }
Mark

StructureGroup Details using the Content Delivery/Broker API

I am trying to get all the structure groups published in a given publication using the PublicationID. I am expecting to get the structure groups with StructureGroupCriteria by passing the Root Structure Group TCM ID but getting page ids (I am expecting SGs).
Now I am trying to loop through the list and get details of each structuregroup. I did not find any API (.net) to get these details and also the API is returning only Pages.
What I have done and working so far using StructureGroupCriteria, returns list of Page IDs instead of SG IDs
PublicationCriteria pubCriteria = new PublicationCriteria(pubID);
// Root StructureGroup TCM ID -- tcm:45-3-4
StructureGroupCriteria sgCriteria = new StructureGroupCriteria("tcm:45-3-4", true);
Criteria allSGsInPub = CriteriaFactory.And(pubCriteria, sgCriteria);
Query allSGs = new Query(allSGsInPub);
string[] sgInfo = allSGs.ExecuteQuery();
Response.Write("Total : " + sgInfo.Length);
foreach (string sgid in sgInfo ) {
// HOW DO I get the Structure Group Details here
//TCMURI sgURI = new TCMURI(sgid);
}
Q # 1 : How to get the all the structuregroups and individual structure group details? (May be something simple, I am not able to find right API).
Q # 2 : How can I get all the structuregroups using ItemTypeCriteria sgCriteria = new ItemTypeCriteria(4); // 4 is SG Item Type .
When I tried this option, the query worked successfully but no results returned. Is this the expected behavior and should we always use StructureGroupCriteria instead of ItemTypeCriteria?
The reason for this approach, I want to avoid using the Root StructureGroup ID which is required with the above code. But at the moment, none of the approaches returning StructureGroup information and I always get Page Information.
Tridion Version: 2011 SP1, .net API.
Note: When I publish I am checking the publish SG info checkbox and published successfully. On Broker DB side, I can see the information on the taxnonomy table as well.
I was playing with Odata service and accidentally I found that I can get all my structure group information from Odata web service.
/cd_webservice/odata.svc/StructureGroups?$filter=PublicationId%20eq%2045
Also, the results are returning child structure groups with a depth parameter.
Just to clarify , using Broker API it is not feasible to get the structure groups (my original question). However, the workaround solution is to use OData Service to get the Structure Groups.
I don't think you will get Structure Groups returned by the Query object.
According to the documentation, when you publish Structure Group information the Structure Group hierarchy is published to the Content Delivery side where it is stored as a taxonomy.
Have you tried using the Taxonomy APIs to get the information you need?

Resources