Implementing Google Custom Search with filtering - google-custom-search

I have to implement a page with multiple google-powered search forms. We have a license from Google for CSE, and this is the situation:
I have a search form that's present at the top of every page that performs a simple search and displays the results in a separate page. This works.
I have a particular page that, in addition, shows another two search forms: one should filter articles by category, another should filter articles by category and restrict the result to a certain month. I have added a meta key with the publication date to each article for this.
I have gotten a bit lost in the documentation, though: if I add
<gcse:searchbox-only resultsUrl="/[site]/stat/search/google_search_results.html"></gcse:searchbox-only></div>
to the page, I can't filter the results. If I start to meddle with a CustomSearchObject, I don't see an option to show results on a different page.
For category-based filtering, I've tried appending
more:pagemap:metatags-taxonomies:news
to the query argument in the results page URL, and it does work, but I don't understand how to inject this to the form.
For restricting based on dates, I tried adding
&sort=more:pagemap:metatags-pubdate:r:YYYYMMDD:YYYYMMDD
but haven't been able to make it work. Getting the XML does work:
http://www.google.com/search?q=intitle:[mysite]%20more:pagemap:metatags-taxonomies:News&sort=metatags-pubdate:r:20120401:20120830&cx=[mykey]client=google-csbe&output=xml
returns correct results.
Is there documentation that doesn't assume so much? All I find are code snippets without context. I've checked Filtering and sorting, Custom Search Element Control API, and of course this site, but I can't put all the pieces together.

I managed to implement what I wanted. In the search page, I built simple forms pointing to my results pages (this might not be doable if you must implement google branding), and in the results page I put the following:
(in the <head>)
<script src="http://www.google.com/jsapi"></script>
<script>
// This function extracts the query from the URL (if GET) or builds a search query.
// Code removed to simplify the example.
function buildQuery () {
return '<?php echo $_POST['q'];?> more:pagemap:metatags-taxonomias:News'); // injecting the taxonomy metatag filter
}
google.load('search', '1', {language : 'es'});
google.setOnLoadCallback(function() {
var customSearchOptions = {};
customSearchOptions[google.search.Search.RESTRICT_EXTENDED_ARGS] = {'sort':'metatags-pubdate:d,metatags-pubdate:r:<?php echo $_POST['startdate'];?>:<?php echo $_POST['enddate'];?>'}; // these come from the POST request, are processed earlier in the script.
var customSearchControl = new google.search.CustomSearchControl('XXXXXXXXXXX', customSearchOptions); // Put your own App key here.
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
var drawOptions = new google.search.DrawOptions();
drawOptions.enableSearchResultsOnly(); // I don't want the search box here
customSearchControl.draw('cse-results-press', drawOptions);
var query = parseQuery();
if (query) {
customSearchControl.execute(query);
}
}, true);
</script>
In the <body>:
<div id="cse-results-press">Loading...</div>

Related

How to get activities from trello board

I have built a site that pulls the comments from Trello to show it on my site using this code:
var resource = "cards/" + card.id + "/actions";
Trello.get(resource, function(comments) {
if(!$.isEmptyObject(comments)){
var commentStr="<div class='comments_c'>";
$.each(comments, function(c, cda){
//console.log(cda.data.text);
commentStr += "<p>"+cda.data.text+"</p>";
//addComments(cda.data.text);
});
commentStr += "</div>";
}
console.log(commentStr);
Now it works fine to pull the comments but it doesn't show the activity like "Sarah Hastings added this card to ". The api documentation doesn't talk about it and I am at a dead-end. We need it for reporting and looking for a way to get the activities (copied, moved, added) from Trello to our site. Any help is appreciated.
By default, the cards/[idCard]/actions endpoint returns actions filtered to commentCard,updateCard:idList. If you want to get actions of additional types from that endpoint you will want to include the filter parameter with the list of action types that you want returned. You can see the full list of options documented here: https://developers.trello.com/advanced-reference/card#get-1-cards-card-id-or-shortlink-actions by clicking Show next to Arguments for that call.
For example actions of adding cards to a board would be of type: moveCardToBoard so you would want to add that to the filter parameter.

How to get the most popular page under a section using Site Catalyst (Omniture)?

I want to use the site catalyst api to get the most popular page (page that has maximum pageviews) under a given site-section? Let me explain better with an example.
My website has multiple channels (News/Journals/Books/Events etc). Each of the channel has many pages under it. I want a api call that will get the most popular news page or Journals page or Books page etc.
I am passing data to sitecatalyst like this..
s.pageName = o_title;
s.channel = o_structure
s.prop1 = o_iden
where o_title has the page title of a newspage or a journalpage etc..
o_structure refers to either "News" or "Journals" or "Books" etc.
Currently I am able to only get the most popular page on the entire site. I would appreciate if someone can help me find the most popular page per section.
Thanks,
Rag
I assume that you already know the basics of using the Omniture API, how to queue up a report and look for status and get it etc... here is a basic REST data string to get site sections (s.channel) broken down by page names (s.pageName) with page views as metric. You will use the Report.QueueRanked API method, and you need to specify the rsid(s) to get the data from and the date ranges.
{
"reportDescription": {
"reportSuiteID":"RSID",
"dateFrom":"YYYY-MM-DD",
"dateTo":"YYYY-MM-DD",
"metrics":[
{
"id":"pageViews"
}
],
"sortBy":"pageViews",
"elements":[
{
"id":"siteSection"
},
{
"id":"page"
}
]
}
}

yii search form via post instead of get

I have a simple search
public function search() {
$criteria=new CDbCriteria;
$criteria->with = array('agent');
$criteria->compare('full_name',$this->full_name,true);
if ($this->gender_id != "") {
$criteria->compare('gender_id',$this->gender_id);
}
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>30,
),
));
}
But I don't like that the search parameters appear in the address bar when you use the get method to search. I've changed my search widget to use the post method instead:
$form=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'post',
));
But now when I hit the search button the page just refreshes instead of showing the search results, I assume I'm missing something here...
In your actionAdmin function of the controller replace $_GET by $_POST...
if(isset($_GET['Model']))
$model->attributes=$_GET['Model'];
replace $_GET in above lines by $_POST like:
if(isset($_POST['LoginLog']))
$model->attributes=$_POST['LoginLog'];
On a side note on search it is always advised to use GET instead of POST, the basic rule i use is whenever some data needs to be submitted it should be POST, whenever some data needs to be fetched it should be GET..
Update:
The main reasons I can think of i would use GET for search
1) In searches user needs the functionality to back to previous filter, which if used as get url params, is straight forward.
2) If the filter params are in url, its extremely easy to share results after certain filters..Imagine you want to share some results with a friend, would you give him instructions to filter step by step (In case of POST), or give a direct url(GET)
3) Its very easy to change params from url, imagine currently you are visiting 2nd page, but on page while displaying filters only links to next 5 pages are displayed, but you want to jump to straight 15th page results..
There will be many more advantages, I can think of these at the moment..

WHMCS Addon Module with Multiple Pages

I am currently working on developing my first WHMCS Addon Module, and so far everything has gone very well. However, I need to make multiple content pages, and the only way to display output according to the Wiki Article is to echo it in the output function. How can I create individual pages when the only way to display content is via a single PHP function?
I am assuming using divs, and hiding the relevant divs, although not exactly the best method. It says you can use the "modulelink" variable to link back to the module, but I have no idea how to use this, or if it can be used for making multiple content pages.
http://docs.whmcs.com/Addon_Module_Developer_Docs
After some tinkering, it was much more simple than I realized, and the "modulelink" variable was just so you could link back to the page. To create additional pages, you can basically just do something along the lines of...
Datacenters
Then in the output function have...
$category = $_GET['catid'];
if ($category == "1" || $category == "")
{
//page 1 content here
}
else if ($category == "2")
{
//page 2 content here
}
and so on.

What is the maximum number of url parameters that can be added to the exclusion list for google analytics

I set up a profile for Google Analytics. I have several dozen url parameters that various pages use and I want to exclude. Luckily, google has a field you can modify under the general profile settings [Exclude URL Query Parameters:]. Of the several dozen items I have they are all working, and not being considered part of the URL. Except for the parameter propid
I added propid to the comma separated list on Monday. But, everyday when I check GA, sure enough they are coming through with that parameter still attached.
So, am I trying to exclude too many parameters? I couldn't find any documentation on GA's site to say there was a limit.
here is the exact content of the exclude URL Query parameter field
There reason there are so many is the bh before me didn't know the difference between get/post.
propid,account,pp,kw1,kw2,kw3,sortby,page,msg,sd,ed,ea,ec,sc,subname,subcode,sa,qc,type,code,propid,acct,minbr,maxbr,minfb,maxfb,minhb,maxhb,minrm,maxrm,minst,maxst,minun,maxun,minyb,maxyb,minla,maxla,minba,maxba,minuc,maxuc,card,print,year,type
update
I thought after more time had passed the "bad data" would fall of of GA. But as of yesterday it is still reporting on the propid querystring value despite adding that as well as other variables to the exclude list.
update2
I found this post on google https://www.google.com/support/forum/p/Google+Analytics/thread?tid=72de4afc7b734c4e&hl=en
It reads that the field only allows 255 char, Ok. Problem Solved. Except my field of values is only 247 charcters.. ARGGGHH!
*Update 3 *
So Here is the code I've added to the googleAnalytics.asp include page that goes at the top of everyone of my asp classic pages. Can anyone see a flaw in the design? I don't care about ANY query string info. (it could have been named *.inc, but I like having intellisense working)
<script type="text/javascript">
<% GAPageDisplayName = REQUEST.ServerVariables("PATH_INFO") %>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-20842347-1']);
_gaq.push(['_setDomainName', '.sc-pa.com']);
<% if GAPageDisplayName <> "" then %>
_gaq.push(['_trackPageview','<%=GAPageDisplayName %>']);
<% else %>
_gaq.push(['_trackPageview']);
<% end if %>
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
Update 4
I'll only accept an answer if you will include something talking to the original question. My question was very specific, I wanted to know exactly the number of characters google allows. Everything I included in my original question body was simply to backfill the question to put everything in context.
Might I suggest an alternate solution to the reliance on manually excluding all of these (and feasibly any string ever used)?
I'd suggest passing a parameter to the trackPageView function to 'force' the recording of a manually/programatically set 'page name' value.
Whereas by default, GA records/defines a page based on a unique URL, the inclusion of a pagename parameter would associate all pageviews of a page with that parameter as pageviews to a single page.
For example, standard GA pageview code looks like this: _gaq.push(['_trackPageview']);, whereas the inclusion of a specific page name looks like this: _gaq.push(['_trackPageview', 'Homepage']);. With the latter, presuming that the homepage is at www.site.com, regardless of how that page is accessed GA will always consolidate all pageview stats for it as 'Homepage'. So, www.site.com/index.php, www.site.com/?a=b and www.site.com/?1=2&x=y will always report as 'Homepage' as if it was one page.
The only drawback here is that you need to be incredibly careful around any occurences of pagination, nested pages, content swapping, site search, or any functionality which may in fact rely on the use of query strings; you may need to consider some logic on how the page name values are output, rather than attempting to define on a per-page basis depending on the site of your site(s).
Hope that's helpful!
Do you realize that you have propid listed twice in the exclusion field? Once at the beginning and then again about one-third of the way through. That's the only thing that stands out to me. See what happens if you remove either of these.
You also have type duplicated, so if the above fixes the problem for propid, also consider removing the second type.
Google limits the characters in the "Exclude Url Query" field (2048 characters max), not the number of queries. I had the same issue you're having and what I discovered was that I had populated my query string parameter list based on the pagenames in my pages report. Well those pagenames first pass through a view-level lowercase filter that I have set up. And since the "Exclude URL Query" field is case sensitive, some of the parameters were getting through. Hopefully this helps.