How can I use pagemap with google custom search refinements? - google-custom-search

I'm trying to add refinements to my google custom search.
I have meta tags on just about every page of the site, such as
<meta name="type-id" content="241" />
Where there are many different types, and I want to have one refinement for each type.
In the docs, it says
You can also use these more:pagemap: operators with refinement labels
But I have been unable to do that.
Note that I have had success using more:pagemap:metatags-type-id:241 in the search input, or as a webSearchQueryAddition - but despite googles docs, I haven't been able to get it to work with a refinement.
Here's a sample from my cse.xml (removing some attributes from the CustomSearchEngine tag):
<?xml version="1.0" encoding="UTF-8"?>
<CustomSearchEngine>
<Title>Test</Title>
<Context>
<Facet>
<FacetItem>
<Label name="videos" mode="FILTER">
<Rewrite>more:p:metatags-article-keyword:121</Rewrite>
</Label>
<Title>Videos</Title>
</FacetItem>
</Facet>
</Context>
</CustomSearchEngine>
Is this supposed to work? Am I using wrong syntax in the rewrite rule? Has anyone else done something like this?

Your label in the facet should be mode="BOOST" if you want to restrict to a structured data field within the scope of your engine.
<Facet>
<FacetItem>
<Label name="videos" mode="BOOST">
<Rewrite>more:p:metatags-article-keyword:121</Rewrite>
</Label>
<Title>Videos</Title>
</FacetItem>
</Facet>

Related

Dynamic localization using JSTL [duplicate]

I learnt from Google that Internationalization is the process by which I can make my
web application to use all languages. I want to understand Unicode for the process of internationalization, so I learnt about Unicode from here and there.
I am able to understand about Unicode that how a charset set in encoded to bytes and again bytes decoded to charset. But I don't know how to move forward further. I want to learn how to compare strings and I need to know how to implement internationalization in my web application. Any Suggestions Please? Please guide me.
My Objective:
My main objective is to develop a Web Application for Translation (English to Arabic & vice versa). I want to follow Internationalization. I wish to run my web Application for translation in all the three browsers namely FF, Chrome, IE. How do I achieve this?
In case of a basic JSP/Servlet webapplication, the basic approach would be using JSTL fmt taglib in combination with resource bundles. Resource bundles contain key-value pairs where the key is a constant which is the same for all languages and the value differs per language. Resource bundles are usually properties files which are loaded by ResourceBundle API. This can however be customized so that you can load the key-value pairs from for example a database.
Here's an example how to internationalize the login form of your webapplication with properties file based resource bundles.
Create the following files and put them in some package, e.g. com.example.i18n (in case of Maven, put them in the package structure inside src/main/resources).
text.properties (contains key-value pairs in the default language, usually English)
login.label.username = Username
login.label.password = Password
login.button.submit = Sign in
text_nl.properties (contains Dutch (nl) key-value pairs)
login.label.username = Gebruikersnaam
login.label.password = Wachtwoord
login.button.submit = Inloggen
text_es.properties (contains Spanish (es) key-value pairs)
login.label.username = Nombre de usuario
login.label.password = ContraseƱa
login.button.submit = Acceder
The resource bundle filename should adhere the following pattern name_ll_CC.properties. The _ll part should be the lowercase ISO 693-1 language code. It is optional and only required whenever the _CC part is present. The _CC part should be the uppercase ISO 3166-1 Alpha-2 country code. It is optional and often only used to distinguish between country-specific language dialects, like American English (_en_US) and British English (_en_GB).
If not done yet, install JSTL as per instructions in this answer: How to install JSTL? The absolute uri: http://java.sun.com/jstl/core cannot be resolved.
Create the following example JSP file and put it in web content folder.
login.jsp
<%# page pageEncoding="UTF-8" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="language" value="${not empty param.language ? param.language : not empty language ? language : pageContext.request.locale}" scope="session" />
<fmt:setLocale value="${language}" />
<fmt:setBundle basename="com.example.i18n.text" />
<!DOCTYPE html>
<html lang="${language}">
<head>
<title>JSP/JSTL i18n demo</title>
</head>
<body>
<form>
<select id="language" name="language" onchange="submit()">
<option value="en" ${language == 'en' ? 'selected' : ''}>English</option>
<option value="nl" ${language == 'nl' ? 'selected' : ''}>Nederlands</option>
<option value="es" ${language == 'es' ? 'selected' : ''}>EspaƱol</option>
</select>
</form>
<form method="post">
<label for="username"><fmt:message key="login.label.username" />:</label>
<input type="text" id="username" name="username">
<br>
<label for="password"><fmt:message key="login.label.password" />:</label>
<input type="password" id="password" name="password">
<br>
<fmt:message key="login.button.submit" var="buttonValue" />
<input type="submit" name="submit" value="${buttonValue}">
</form>
</body>
</html>
The <c:set var="language"> manages the current language. If the language was supplied as request parameter (by language dropdown), then it will be set. Else if the language was already previously set in the session, then stick to it instead. Else use the user supplied locale in the request header.
The <fmt:setLocale> sets the locale for resource bundle. It's important that this line is before the <fmt:setBundle>.
The <fmt:setBundle> initializes the resource bundle by its base name (that is, the full qualified package name until with the sole name without the _ll_CC specifier).
The <fmt:message> retrieves the message value by the specified bundle key.
The <html lang="${language}"> informs the searchbots what language the page is in so that it won't be marked as duplicate content (thus, good for SEO).
The language dropdown will immediately submit by JavaScript when another language is chosen and the page will be refreshed with the newly chosen language.
You however need to keep in mind that properties files are by default read using ISO-8859-1 character encoding. You would need to escape them by unicode escapes. This can be done using the JDK-supplied native2ascii.exe tool. See also this article section for more detail.
A theoretical alternative would be to supply a bundle with a custom Control to load those files as UTF-8, but that's unfortunately not supported by the basic JSTL fmt taglib. You would need to manage it all yourself with help of a Filter. There are (MVC) frameworks which can handle this in a more transparent manner, like JSF, see also this article.
In addition to what BalusC said, you have to take care about directionality (since English is written Left-To-Right and Arabic the other way round). The easiest way would be to add dir attribute to html element of your JSP web page and externalize it, so the value comes from properties file (just like with other elements or attributes):
<html dir="${direction}">
...
</html>
Also, there are few issues with styling such application - you should to say the least avoid absolute positioning. If you cannot avoid that for some reason, you could either use different stylesheets per (each?) language or do something that is verboten, that is use tables for managing layout. If you want to use div elements, I'd suggest to use relative positioning with "symmetric" left and right style attributes (both having the same value), since this is what makes switching directionality work.
You could find more about Bi-Directional websites here.
based on this tutorial, I am using the following on GAE - Google's App Engine:
A jsp file as follows:
<%# page import="java.io.* %>
<%
String lang = "fr"; //Assign the correct language either by page or user-selected or browser language etc.
ResourceBundle RB = ResourceBundle.getBundle("app", new Locale(lang));
%>
<!DOCTYPE html>
<%# page contentType="text/html;charset=UTF-8" language="java"%>
<head>
</head>
<body>
<p>
<%= RB.getString("greeting") %>
</p>
</body>
And adding the files named: app.properties (default) and app_fr.properties (and so on for every language). Each of these files should contain the strings you need as follows: key:value_in_language, e.g. app_fr.properties contains:
greeting=Bonjour!
app.properties contains:
greeting=Hello!
That's all

Does the Wikipedia API support searches for a specific template?

Is it possible to query the Wikipedia API for articles that contain a specific template? The documentation does not describe any action that would filter search results to pages that contain a template. Specifically, I am after pages that contain Template:Persondata. After that, I am hoping to be able to retrieve just that specific template in order to populate genealogy data for the openancestry.org project.
The query below shows that the Albert Einstein page contains the Persondata Template, but it doesn't return the contents of the template, and I don't know how to get a list of page titles that contain the template.
http://en.wikipedia.org/w/api.php?action=query&prop=templates&titles=Albert%20Einstein&tlcontinue=736|10|ParmPart
Returns:
<api>
<query>
<pages>
<page pageid="736" ns="0" title="Albert Einstein">
<templates>
...
<tl ns="10" title="Template:Persondata"/>
...
</templates>
</page>
</pages>
</query>
<query-continue>
<templates tlcontinue="736|10|Reflist"/>
</query-continue>
</api>
I suspect that I can't get what I need from the API, but I'm hoping I'm wrong and that someone has already blazed a trail down this path.
You can use the embeddedin query to find all pages that include the template:
curl 'http://en.wikipedia.org/w/api.php?action=query&list=embeddedin&eititle=Template:Persondata&eilimit=5&format=xml'
Which gets you:
<?xml version="1.0"?>
<api>
<query>
<embeddedin>
<ei pageid="307" ns="0" title="Abraham Lincoln" />
<ei pageid="308" ns="0" title="Aristotle" />
<ei pageid="339" ns="0" title="Ayn Rand" />
<ei pageid="340" ns="0" title="Alain Connes" />
<ei pageid="344" ns="0" title="Allan Dwan" />
</embeddedin>
</query>
<query-continue>
<embeddedin eicontinue="10|Persondata|595" />
</query-continue>
</api>
See full docs at mediawiki.org.
Edit Use embeddedin query instead of backlinks (which doesn't cover template inclusions)
Using embeddedin does not allow you to search for a specific person, the search string becomes the Template:Persondata.
The best way I've found to get only people from Wikipedia is to use list=search and filter the search using AND"Born"AND"Occupation":
http://en.wikipedia.org/w/api.php?action=query&list=search&srsearch="Tom Cruise"AND"Born"AND"Occupation"&format=jsonfm&srprop=snippet&srlimit=50`
Remember that Wikipedia is using a search engine that doesn't yet allow us to search only the title, it will search the full text. You can take advantage of that to get more precise results.
The accepted answer explains how to list pages using a certain template, but if you need to search for pages using the template, you can with the hastemplate: search keyword: https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=hastemplate:NPOV%20physics

XML configuration of Zend_Form: child nodes and attributes not always equal?

A set of forms (using Zend_Form) that I have been working on were causing me some headaches trying to figure out what was wrong with my XML configuration, as I kept getting unexpected HTML output for a particular INPUT element. It was supposed to be getting a default value, but nothing appeared.
It appears that the following 2 pieces of XML are not equal when used to instantiate Zend_Form:
Snippet #1:
<form>
<elements>
<test type="hidden">
<options ignore="true" value="foo"/>
</test>
</elements>
</form>
Snippet #2:
<form>
<elements>
<test type="hidden">
<options ignore="true">
<value>foo</value>
</options>
</test>
</elements>
</form>
The type of the element doesn't appear to make a difference, so it doesn't appear to be related to hidden fields.
Is this expected or not?
As it was rather quiet on here, I took a look further into the source code and documentation.
On line 259 of Zend_Config_Xml, the SimpleXMLElement object attributes are converted to a string, resulting in:
options Object of: SimpleXMLElement
#attributes Array [2]
label (string:7) I can't see this because
value (string:21) something happens to this
becoming
options (string:21) something happens to this
So, I hunted through the documentation only to find that "value" is a reserved keyword when used as an attribute in an XML file that is loaded into Zend_Config_Xml:
Example #2 Using Tag Attributes in Zend_Config_Xml
"..Zend_Config_Xml also supports two
additional ways of defining nodes in
the configuration. Both make use of
attributes. Since the extends and the
value attributes are reserved keywords
(the latter one by the second way of
using attributes), they may not be
used..."
Thus, it would appear to be "expected" according to the documentation.
I'm not entirely happy that this is a good idea though, considering "value" is an attribute of form elements.
Don't worry about this. The reserved keywords were moved to their own namespace, and the previous attributes were depricated. In Zend Framework 2.0 the non-namespaced attributes will be removed so you can use them again.

list=alllinks confusion

I'm doing a research project for the summer and I've got to use get some data from Wikipedia, store it and then do some analysis on it. I'm using the Wikipedia API to gather the data and I've got that down pretty well.
What my questions is in regards to the links-alllinks option in the API doc here
After reading the description, both there and in the API itself (it's down and bit and I can't link directly to the section), I think I understand what it's supposed to return. However when I ran a query it gave me back something I didn't expect.
Here's the query I ran:
http://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=google&rvprop=ids|timestamp|user|comment|content&rvlimit=1&list=alllinks&alunique&allimit=40&format=xml
Which in essence says: Get the last revision of the Google page, include the id, timestamp, user, comment and content of each revision, and return it in XML format.
The allinks (I thought) should give me back a list of wikipedia pages which point to the google page (In this case the first 40 unique ones).
I'm not sure what the policy is on swears, but this is the result I got back exactly:
<?xml version="1.0"?>
<api>
<query><normalized>
<n from="google" to="Google" />
</normalized>
<pages>
<page pageid="1092923" ns="0" title="Google">
<revisions>
<rev revid="366826294" parentid="366673948" user="Citation bot" timestamp="2010-06-08T17:18:31Z" comment="Citations: [161]Tweaked: url. [[User:Mono|Mono]]" xml:space="preserve">
<!-- The page content, I've replaced this cos its not of interest -->
</rev>
</revisions>
</page>
</pages>
<alllinks>
<!-- offensive content removed -->
</alllinks>
</query>
<query-continue>
<revisions rvstartid="366673948" />
<alllinks alfrom="!2009" />
</query-continue>
</api>
The <alllinks> part, its just a load of random gobbledy-gook and offensive comments. No nearly what I thought I'd get. I've done a fair bit of searching but I can't seem to find a direct answer to my question.
What should the list=alllinks option return?
Why am I getting this crap in there?
You don't want a list; a list is something that iterates over all pages. In your case you simply "enumerate all links that point to a given namespace".
You want a property associated with the Google page, so you need prop=links instead of the alllinks crap.
So your query becomes:
http://en.wikipedia.org/w/api.php?action=query&prop=revisions|links&titles=google&rvprop=ids|timestamp|user|comment|content&rvlimit=1&format=xml

Problem with DisplayPattern in SharePoint 2010?

I am adding a new field to a list using the AddFieldAsXML method of SPFieldCollection. The method executes fine with no problem. And the column header shows up when I view the list; however the value never displays in the column. Here is what the field looks like after it has been added to the list. This xml is a snipped from the list schema derived using http://tw-s1-m4400-007:4016/_vti_bin/owssvr.dll?Cmd=ExportList&List={1F87433F-50E1-46C5-A138-00E1CF7E5801}
This code works great in 2007 but does not work in 2010. Any help would be appreciated.
<Field ID="{e24ccb96-35fd-44e5-b7d1-4150dbbc9a64}" Type="Computed" ReadOnly="TRUE"
Name="My_x0020_Status" DisplayName="MyStatus" ShowInEditForm="TRUE" ClassInfo="Icon"
AuthoringInfo="(My status)" SourceID="http://schemas.microsoft.com/sharepoint/v3"
StaticName="MyStatus" FromBaseType="TRUE">
<FieldRefs>
<FieldRef Name="ID" />
<FieldRef Name="Title" />
</FieldRefs>
<DisplayPattern>
<HTML>
<![CDATA[ <a href="form.htm?ID="
]]>
</HTML>
<Column Name="ID" />
<HTML>
<![CDATA[ ">
]]>
</HTML>
<Column Name="Title" />
<HTML>
<![CDATA[ </a>
]]>
</HTML>
</DisplayPattern>
</Field>
This link provided a lot of help in solving this issue:
http://social.technet.microsoft.com/Forums/en/sharepoint2010customization/thread/ef0d1d22-47ff-416c-becd-13d48de80e4d
Basically, display patterns fields are defined in the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\XSL\fldtypes.xsl file.
There is a file called fldtypes_ratings.xsl that you can use as an example of defining your custom field display.
You can create your own xsl file (i.e. fldtypes_myfile.xsl) to define your own custom display.
Here's a sample of my content:
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema"
xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-
prefixes="xsl msxsl ddwrt" ns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
<xsl:template match="FieldRef[#Name='MyCustomField']" mode="Computed_body">
<xsl:param name="thisNode" select="."/>
<SPAN class="mystuff-content-item" style="Width:100%;text-align:center">
<SPAN class='mystuff-socialized-status mystuff-socialized-status-unknown'></SPAN>
<SPAN class="mystuff-content-object-type" style="display:none">
MyContent
</SPAN>
<SPAN class="mystuff-content-followed" style="display:none">0</SPAN>
<SPAN class="mystuff-content-name" style="display:none"></SPAN>
<SPAN class="mystuff-content-id" style="display:none">
<xsl:value-of select="$List" />
<xsl:text>|</xsl:text>
<xsl:value-of select="$thisNode/#ID" />
</SPAN>
</SPAN>
</xsl:template>
</xsl:stylesheet>
Hope that helps!
I'm confused as to the point of referencing these articles -- both of them state "Two legacy field types that ship with SharePoint Foundation do not have a DisplayPattern type of RenderPattern in FLDTYPES.XML: (1) ContentTypeId fields are never visible. (2) Computed fields are rendered on list views and in Display mode by a DisplayPattern element in their Field elements within the schema.xml of each list on which they appear."
The original question is clearly defined as a "Computed" field, that according to the linked articles do not use the fldttypes.xml for their renderpattern, but intstead use the DisplayPattern element just as the original question posted. It would help to post references to how the DisplayPattern works in 2010 -- since the documentation clearly states that it Does work, but never says how.
See my blog on this here: http://www.threewill.com/2012/07/computed-fields-in-sp-2010/. Hopefully this makes it clear on how to do computed fields in SP2010.
This method of customization from 2007 is made obselete by changes in 2010's rendering of fields. Read the note from the SDK entry on RenderPattern for more detail:
Important!
This topic describes markup that was used in a now obsolete method of rendering custom fields types on list views and on the Display, Edit, and New forms. It is provided solely to assist persons who are debugging a custom field type that was originally developed against an earlier version of SharePoint Foundation. For information about the recommended methods, see How to: Create Field Rendering Templates and How to: Create a Custom Field Type.
Custom fields whose rendering is defined with RenderPattern markup still render properly on forms. However, SharePoint Foundation, by default, uses XSLT stylesheets to render fields on list views, even for legacy custom fields whose list view rendering is defined with a RenderPattern. To enable the rendering of such a field, a TRUE element must be added to the containing FieldTypes element in the field type definition file (fldtype*.xml).