Archive September 2010:
Commuting is often a nail in the coffin for a lot of people. It doesn't have to be. Here's a number of suggestions how you can make the most of your commuting and improve productivity.
Read books
Reading is good. If you read during commuting, you might find the commuting nicer. You will get more time to spend at other activities than reading, when you're not commuting.
If you don't want to read, maybe you can listen to an e-book using your mp3 player.
Important: make sure your book is in pocket form. Also, if you're reading, it might be a good idea listening to music at the same time, to filter out a lot of the noise that comes from trains, buses, other passengers et al.
Listen to podcasts
The Internet is full of great podcasts on all kind of subjects. Why not spend some time listening to your favourite podcast (radio) show?
Here's a list of great podcasts for web developers: Top 15 Podcasts All Web Developers Should Follow
Get in touch
How often do you get in touch with friends and family? During commuting, particularly when going home, it's the perfect time to get in touch. Just make a phone call or send some texts, it's really easy and the person on the other side might enjoy it more than you think!
Also, there's the possibility to get up to speed on what's happening in your Facebook feed or Twitter feed. Just use you smart phone or browse to m.facebook.com / mobile.twitter.com.
Write!
Prepare a blog post or organize your photos. This, of course, requires a laptop. But then again, many people do have a laptop these days. A laptop can certainly be seen as an investment if you don't have one yet!
It's also a good idea to invest in a mobile Internet device.
Sleep
If it's possible without you missing to get off at your station, sleep. This way you'll probably have a higher level of energy during the day. If you're able to sleep during commuting and stay up later at night when at home, you can save some time here.
Don't forget the ear-plugs or the mp3 player though!
If you use Solr and have a search query including an UTF-8 character, like Swedish åäö, you have to turn on the correct encoding for Apache Tomcat. You do this by simply adding URIEncoding="UTF-8" to the appropriate connector in Tomcat's server.xml file (normally located in the Tomcat conf folder).
Here's the complete code snippet to get UTF-8 characters working with Solr search:
<Connector port="8983" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8" />
You can also read about URI Charset Config in the Solr documentation.
Related post: Get started using Solr for search in ASP.NET
I recently stumbled upon a problem where some Visual Studio templates wasn't available when I choose Add new item in Visual Studio.
I needed to generate some LINQ to SQL classes, but the Data alternative wasn't there.
After some searching, here's what solved the problem:
For Visual Studio 2010, find the VS command prompt (in the start menu), right click it and choose 'Run as administrator'. Execute this command:
devenv.exe /vsinstalltemplates
You won't be noticed if anything succeeds or fails, but you should now have the appropriate Visual Studio templates available in the Add new item menu.
For Visual Studio 2008, I solved the problem by re-installing Visual Studio 2008 Service Pack 1.
Also, you can have a look in the C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates folder to see what's missing. You can even copy zip files from other Visual Studio installations to the folders here and execute the above command for Visual Studio 2010, and get it working.
Also - there's a difference when adding files in Solution Explorer, compared to through the File menu.
Here are some blog posts and stack overflow posts that helped me:
Solr is an advanced search coming from Apache's Lucene project. Thanks to SolrNet, a .NET library for Solr, it is quite convenient to use Solr for search in ASP.NET. I'll show you how. (You can also download the sample app right off, if you'd like to)
Install Apache Tomcat and Solr
First of all, make sure you get the latest version of Apache Tomcat and Solr. (I installed Tomcat 7 and Solr 1.4.1 (zip version) as of September 2010.)
Tomcat installation
When installing Tomcat, make sure to remember the port you specify (normal for Solr is 8983). After installation, the Apache Tomcat Properties window should popup. If not, find Configure Tomcat in the start menu and make sure the web server's started. If it's started, you should find the default Tomcat startpage if you browse to http://localhost:8983.
Solr installation
Before you install Solr, stop the Tomcat web server (through the Configure Tomcat window).
When you've downloaded the Solr zip file (make sure it's the zip version!), unzip the archive and find the dist folder. In the dist folder, find the apache-solr-1.4.1.war file and copy it to C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps, renaming it to solr.war.
Now, we also need to create the Solr folder, which will host our Solr configuration files, indexes and so on. I created C:\Solr. You'll also need to copy the contents of the apache-solr-1.4.1\example\solr folder to your newly created Solr folder. When you're done, you should at least have the bin and conf folder.
Finally, we need to tell Tomcat where our Solr folder is located. Open up the Configure Tomcat window, navigate to the Java tab and add this row to Java Options:
-Dsolr.solr.home=c:\solr
It should look like this:

Now, you should first start the web server and then be able to navigate to http://localhost:8983/solr. Installation and basic configuration done!
Quick look at the configuration files
The Solr configuration files are important - you will use them to tell Solr what should be indexed and not. The most important config files are schema.xml and solrconfig.xml. These are located in the C:\Solr\conf folder.
Easier use of Solr with the SolrNet library
SolrNet is a great .NET library for Solr, making it all easier. Download assemblies (and samples) on the SolrNet Google Code page.
Sample ASP.NET app with SolrNet for download
I've developed a sample web application for you, using SolrNet for search in ASP.NET.
Basically, you've got some data in the SQL Server database and use SolrNet to find items in the search index and present all you want from the database.
Here's what you should know:
- Map fields to Solr using attributes (Player.cs in the classes folder)
- This is sample code, not everything might be suitable for a production environment
- You should use Linq to Sql, NHibernate or similar for better scaling and easier data access
Download the sample Solr app
I'd like to thank A. Friedman for his contribution to the Solr and ASP.NET world. Here's his great blog post on Solr and SolrNet.
Code snippets using SolrNet
Here's some code snippets from my Solr app. You can find them in the source code, although I found it being a good idea to post code for a couple of common actions using Solr and SolrNet for search.
Search the index and bind to Repeater:
var search = new DefaultSearcher()
.Search(query, 10, 1);
rptResults.DataSource = search.Result;
rptResults.DataBind();
Re-index all data:
new SolrBaseRepository.Instance<Player>().Start();
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Player>>();
var players = new PlayerRepository().GetPlayers();
solr.Add(players);
solr.Commit();
Remove from index:
new SolrBaseRepository.Instance<Player>().Start();
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Player>>();
var specificPlayer = new PlayerRepository().GetPlayer(id);
solr.Delete(specificPlayer);
solr.Commit();
Adding multiple fields to the search index
By standard, Solr lets you index one field only, thanks to the defaultSearchField in schema.xml. It's easy to turn on indexing of multiple fields though, using copyField and an additional field which takes multi values.
What you have to do is to edit schema.xml a bit:
- Setup the fields you want to get indexed, using field.
- Create an additional field called "text", setting its multiValued property to true.
- Use copyField to copy data to this additional field.
- Use this additional field, "text", as the defaultSearchField.
Here's how:
<fields>
<field name="id" type="int" indexed="true" stored="true" required="true" />
<field name="firstname" type="text" indexed="true" stored="false" required="false" />
<field name="lastname" type="text" indexed="true" stored="false" required="false" />
<field name="text" type="text" indexed="true" stored="false" multiValued="true" />
</fields>
<copyField source="firstname" dest="text" />
<copyField source="lastname" dest="text" />
<uniqueKey>id</uniqueKey>
<defaultSearchField>text</defaultSearchField>
<solrQueryParser defaultOperator=uot;AND" />
Debugging Solr
If you encounter any problems with Solr, try this to get it working:
- Turn off elevate.xml handler (comment appropriate lines in solrconfig.xml).
- Case sensitive configuration files - make sure you spell copyField, multiValued etc correctly.
- In solrconfig.xml, make sure you use matching data types to those you've defined in your ASP.NET app.
More Solr
Solr is really powerful and gives you a lot of options. I recommend the Solr Wiki for more information on what actually is possible.
A while ago I wrote a post on my favourite Windows tools. Those tools are still my favourites, although I've found a much more efficient way of installing them.
Using Ninite.com makes it all so much easier.
You get a set of applications in different categories, just tick those ones you want, download an installer and then Ninite does the rest. Couldn't be easier!
No more manual installation of a lot of different applications!