Chicago Data Portal API format for filter with multiple conditions - socrata

Probably very easy, however I cant find the answer in the documentation.
I have the following API url which I like to extend with additional filter condition for the "location_description". It currently filters on "residence":
https://data.cityofchicago.org/resource/6zsd-86xi.json?$$app_token=xxxxxxxxx&primary_type=BURGLARY&location_description=RESIDENCE
However, I like to extend this to include "APARTMENT,RESIDENCE-GARAGE".
So When I try this format:
https://data.cityofchicago.org/resource/6zsd-86xi.json?$$app_token=xxxxxxxxx&primary_type=BURGLARY&location_description=RESIDENCE,APARTMENT,RESIDENCE-GARAGE
It will not work.
Tried different formats including "", () etc, but no luck.
Question: How do I format this URL correctly so that I can filter on multiple "location_description"?
Thanks for the assistance.

For this, it might be a bit easier to use the where statement since it'll resemble a SQL query and may be more familiar (and easier to look at general query documentation). For now, I've removed the $$app_token to simplify the URL:
https://data.cityofchicago.org/resource/6zsd-86xi.json?$where=primary_type='BURGLARY' AND (location_description='RESIDENCE' OR location_description='APARTMENT' OR location_description='RESIDENCE-GARAGE')

Related

Wikipedia api fulltext search to return articles with title, snippet and image

I've been looking for a way to query the wikipedia api based on a search string for a list of articles with the following properties:
Title
Snippet/Description
One or more images related to the article.
I also have to make the query using jsonp.
I've tried using the list=search parameter
http://en.wikipedia.org/w/api.php?action=query&list=search&prop=images&format=json&srsearch=test&srnamespace=0&srprop=snippet&srlimit=10&imlimit=1
But it seems to ignore the prop=images, I've also tried variations using the prop=imageinfo and prop=pageimages. But they all give me the same result as just using the list=search.
I've also tried action=opensearch
http://en.wikipedia.org/w/api.php?action=opensearch&search=test&limit=10&format=xml
Which gives me exactly what I want when i set format=xml, but returns a simple array of page titles when using format=json and therefore fails because of the jsonp requirement.
Is there another approach to doing this? I'd really like to solve this in a single request rather than make the first search request and then a second request for the images using titles=x|y|z
As Bergi suggested, using generators is the way to go here. Specifically what I would do:
use list=search as a generator, to get the list of articles
use prop=pageimages to get a representative image for each article
use prop=extracts to get a description for each article
The whole query could look like this:
http://en.wikipedia.org/w/api.php?format=json&action=query&generator=search&gsrnamespace=0&gsrsearch=test&gsrlimit=10&prop=pageimages|extracts&pilimit=max&exintro&explaintext&exsentences=1&exlimit=max
I've tried using the list=search parameter, but it seems to ignore the prop=images
If you want to retrieve any properties, you need to specify a list of pages for which you want to get these; e.g. by using the titles=, pageids=, or revids= parameters. You didn't send any, so you did not get a result for the prop=images.
If you did use api.php?action=query&list=search&srsearch=test&prop=images&titles=test you would have gotten the search results for test and the images of the Test page.
You can however also use the collection that the list query generates for your property query, using the list module as a generator. The query would look like
api.php?action=query&generator=search&gsrsearch=test&gsrnamespace=0&gsrprop=snippet&prop=images. Unfortunately, it does not yield the attributes that the list contained, but only used the pageids for a basic property query.
Using two queries is probably the way to go. Btw, I'd recommend to use the pageimages property, it will likely give you the best results.

How do I filter items returned by list to exclude files last modified by me?

Looking at the results of list, there is a lastModifyingUserName, but not a userid or other concrete reference to a user such that I can strongly verify that the file was last modified by me or someone else.
I can approximate this behavior using a string comparison of my user profile information, but this isn't an exact check.
I also looked at the timestamps, and timestamps for a file that was modified by me don't seem to line up, so it doesn't look like I can do this using timestamps either, which looks like a bug in and of itself, e.g.:
"modifiedByMeDate": "2013-01-31T02:25:26.738Z",
"modifiedDate": "2013-01-31T02:29:58.363Z",
Google are working on improving this so that there is consistency between the actor returned in the lastModifyingUserName field and the permission ID.
Right now I agree with you it is pretty impossible, sorry.

How to query a Lotus view and have the result formatted as json?

I have a view called 'walking' which I want to query:
http://site/activity.nsf/walking?searchview&query=FIELD%20Gradient%20CONTAINS%20gradienteasy.gif
This returns the results in an HTML table. What I would like to do is have the results formatted as JSON which I will then use client-side. Is this possible?
I know you can get JSON returned from a straight view by doing this:
http://site/activity.nsf/walking?readviewentries&outputformat=json
Scott Good and I have done several sessions at a variety of conferences on generating and consuming JSON from traditional Domino applications (not using XPages). The most recent was the "JMP303 JSON in client- and server-side code Master Class" we gave at Lotusphere 2011. Link to the presentation materials and slides are: here
/Newbs
You will have to create a view that is marked with the "Treat view contents as HTML" property and set up a column formula that generates the JSON syntax that you want'.
There is a nice post on OpenNTF with the code to create a very generic view which returns JSON for the documents that match the View's selection formula:
http://openntf.org/XSnippets.nsf/snippet.xsp?id=use-transform-to-build-json-and-consume-the-output-in-an-xagent
That sample uses an "XAgent" (Xpage with no UI) to set the content-type header, etc. But you could probably do the same thing using a $$ViewTemplate form, if needed.

sfPropelPager reduce queries

i'm working in a symfony project and using sfPropelPager to show a paged list of elements.
The problem is that with a great amount of data to list (i.e. thousands of registers) it makes a query to the database for each page to show!!!! That means about 100 extra queries in my case, and that is unacceptable.
Showing some of my code: the function that returns the pager object
$pager = new sfPropelPager('MyTable',sfConfig::get('sfPropelPagerLines'));
$c = new Criteria();
$c->add('my_table_field',$value);
$c->addDescendingOrderByColumn('date');
$pager->setCriteria($c);
$pager->init();
return $pager;
So, please, if you know a way to get all the results with only one query, it would be a great solution for my problem. Otherwise i must implement that list with an ajax call for every page the user wants to see
Thank you very much for your time.
I'm not sure to get your problem but, anyway, avoid the use of Criteria. Try to make queries with the ModelCriteria API: http://www.propelorm.org/reference/model-criteria.html.
For each paginated page, a query to the database will be done, this is the standard behavior for all pagers I know. If it's related to related objects (assuming you want to display information from relations), you may want to create a query that links those objects before to paginate, that way you'll get one query per page for all your data to display.
Read this doc for instance: http://www.propelorm.org/documentation/03-basic-crud.html#query_termination_methods
At last i did'nt get a solution for the problem, i had to implement the list via AJAX call, calling to a function that returns the requested page, so at the load of the page, no query for this list is slowing the user experience.
Thank you anyway to help me :)

How can I get an array with the names of all defined categories?

I need to retrieve an array with category names.
It seems that tag names and category names are both stored in the same table (wp_terms), and to distinguish them you need to look in the wp_term_taxonomy table where the IDs from wp_terms are listed with options post_tag or category.
So I need to do some sort of relation query which, to be honest, is more than I can handle at this point. I did find that apparently there is some sort of a short cut to this. I haven't been able to find a good description of the function, but if you consider this: $wpdb->categories->cat_name` you may know what it's all about. I certainly don't.
How do I get an array with the names of all defined categories including nothing else?
You can use get_categories for this.
http://codex.wordpress.org/Function_Reference/get_categories
This will fetch all categories
get_categories(array('hide_empty' => 0));
http://codex.wordpress.org/Function_Reference/get_categories
I find the documentation to be quite good actually.
edit:
if you just need it for a static menu use the menu panel, add support for it in your theme first:
add_theme_support( 'menus' );
I would have thought using get_categories(); would work for you. The documentation in the codex seems pretty straight forward. You can see exactly how get_categories() is used with wp_list_categories()
A lot of times when I can't find the right documentation for it, I just google something like "Worpdress Codex Get 'xxx'" and I can find what I need.
Let us know if get_categories() works for you.
http://codex.wordpress.org/Function_Reference/get_categories