ColdFusion, Solr, and Title Searches - an FYI

This post is more than 2 years old.

This week I worked with a user who was having an interesting issue with Solr-based searches under ColdFusion. He was trying to make use of "boosting", which is a way of saying that a match found in one field should be considered more important than another. So for example, imagine you have a collection of articles. The user searches for N and you want to ensure that if the title includes N it is rated higher. Normally Solr is going to use it's own judgement. It may say, for example, that if N occurs a crap load in the body then it should be rated higher than an article with N in the title. While that logic makes sense, Solr does allow you to weigh different fields higher if you want. Normally the syntax should be something like this:

#search# OR title:#search#^10

However, in testing with the user, this didn't seem to work consistently. And then I noticed something odd. For our testing, we were using "ColdFusion" as a search string. While I tested I once did "coldfusion" and noticed that a record that should not have been returned wasn't. I hit up my Solr expert, Shannon Hicks for help. Together we found that the Solr configuration ColdFusion creates sets title as a case sensitive field. That's important to know in general, but certainly impacted our tests here.

So the fix? I simply had the user employ one of the custom fields as a copy of the title field. Once done we could then do:

#search# OR custom1:#search#^10

And it worked immediately. I hope this is helpful!

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by dcs posted on 12/23/2011 at 7:38 AM

When you create a Solr collection in ColdFusion it creates the title field using the "text_ws" type. What you can do if you want the title field to act more or less like it did under Verity is to change that "text_ws" (a case-sensitive type) to "text" (a case-insensitive type) in the schema.xml file (under Windows this can be found under C:\ColdFusion9\collections\<collection_name>\conf\schema.xml, assuming it was created in the default location) and restart the Solr service. That might be more than most people are prepared to do. The only issue with using the custom1 field or another custom field is that it keeps you from using that field for some other piece of data. Hope this helps.

Comment 2 by dcs posted on 1/11/2012 at 8:13 PM

Just as a followup, I blogged on this issue here:

Truthfully, I think it is a bug in the way CF creates the Solr collection (why should "title" all of a sudden be case-sensitive?) but it is easy enough to fix schema.xml, restart the Solr service, and index the collection.