Solr, DataImportHandler, UUID and SQL Server

I’ve recently been setting up Apache Lucene/Solr to index static PDF files and also import data to the collection from MS SQL Server.

After successfully indexing PDF files and providing them with a unique id via UUID I wanted to import several SQL tables that each had a ID column called ‘id’. These tables would obvioulsy have overlapping ID’s at some stage so I wanted to use UUID on these documents as well.

I struggles to find much documentation on Solr, SQL Server and UUID, but after successfully setting up UUID via http://wiki.apache.org/solr/UniqueKey, you also need to the UpdateRequestHander on the dataimport handler as well. Therefore the following code:

<requestHandler name=”/dataimport” class=”org.apache.solr.handler.dataimport.DataImportHandler”>
<lst name=”defaults”>
<str name=”config”>db-data-config.xml</str>
</lst>
</requestHandler>

changed to this

<requestHandler name=”/dataimport” class=”org.apache.solr.handler.dataimport.DataImportHandler”>
<lst name=”defaults”>
<str name=”config”>db-data-config.xml</str>
<str name=”update.chain”>uuid</str>
</lst>
</requestHandler>

then auto creates unique id’s when importing on mass from SQL Server tables.

Removing wp_head() elements (rel=’start’, etc.)

In customising WordPress you may find a need to occasionally remove or add to the Link elements that WordPress automatically outputs in the function call wp_head(). I’ve recently had a need to remove the rel=’prev’ and rel=’next’ link elements and in trying to avoid customising the core WordPress functions the following solutions works.

Ensure you have a functions.php file in your theme directory that you are using. If not create the file and edit the file. The following lines will help remove select lines from your wp_head() function:

remove_action( 'wp_head', 'feed_links_extra', 3 ); // Removes the links to the extra feeds such as category feeds
remove_action( 'wp_head', 'feed_links', 2 ); // Removes links to the general feeds: Post and Comment Feed
remove_action( 'wp_head', 'rsd_link'); // Removes the link to the Really Simple Discovery service endpoint, EditURI link
remove_action( 'wp_head', 'wlwmanifest_link'); // Removes the link to the Windows Live Writer manifest file.
remove_action( 'wp_head', 'index_rel_link'); // Removes the index link
remove_action( 'wp_head', 'parent_post_rel_link'); // Removes the prev link
remove_action( 'wp_head', 'start_post_rel_link'); // Removes the start link
remove_action( 'wp_head', 'adjacent_posts_rel_link'); // Removes the relational links for the posts adjacent to the current post.
remove_action( 'wp_head', 'wp_generator'); // Removes the WordPress version i.e. - WordPress 2.8.4

Don’t remove these items unless you have a need to. The WordPress generator removal could be useful if you are not religiously upgrading your WordPress install as it helps hide the WP version from potential hackers to a certain degree.

RGB to HEX Converter

Working with CSS I am constantly trying to convert RGB values from Photoshop to their hex equivalent. There is probably a setting in PhotoShop that I have missed, but the following small form will quickly convert RGB values to the HEX equivalent. You can then use these values in CSS with # at the beginning.

Let me know if you find this useful:

R:
G:
B:
:

Determine URL of an ImagePlaceholder

I came across a problem recently whereby I wanted to determine the MCMS URL of an image stored in the MCMS Resource gallery.  The script had several image placeholders, some of which may of had images bound to them.

My requirements involved determining the URL of any given image and then to use this in some CSS styling.   Faced with this scenario the following code should help:


//Setup placeholder object and string for URL
Placeholder pl;
string imgSrcUrl = "";

//setup default CSS string
string FeatureCSS = ””;

pl = ImageX.BoundPlaceholder;//get the bound placeholder for this control
if (pl!=null){//test the placholder is not null
imgSrcUrl = ((ImagePlaceholder)pl).Src ;//get the source url from the placholder
if (imgSrcUrl!=null && imgSrcUrl!=”"){
FeatureCSS = “<style type=\”text/css\”>\n#section {\nheight: 232px;\nbackground: url(”+imgSrcUrl+”) no-repeat -26px 0;\n}\n</style>”;
}
else doSomethingElse();
}
else doSomethingElse();