Index on ContentType needs to be Lower Case


In Orchard.Core.Common.Handlers.CommonPartHandler you will find this line of code:
.Add("type", commonPart.ContentItem.ContentType).Store()
If you actually just try to search for the content type (have your Search settings just filtered on "type") you will find you can never actually find anything. The reason (after analyzing the index with Luke.Net) is that the information is stored with capital letters. Because when you use Orchard search your query is automatically lower-cased, the results never show up. I am proposing this fix
.Add("type", commonPart.ContentItem.ContentType.ToLowerInvariant()).Store()
This is working for me, look forward to replies. It is strange to me though as I have other fields being indexed where I am NOT forcing to lower case and the search works fine. However, I am using .Analyze() on the indexed item and am NOT using .Store() so I wonder if between the two of them it is automatically lower cased - love to hear back from someone who knows.
Closed Jul 1, 2014 at 8:49 PM by sebastienros


sebastienros wrote Jul 1, 2014 at 8:49 PM

ContentType and Id are technical values which should not be analyzed. If you want to filter on these values then use the API and then .ExactMatch()

jao28 wrote Jul 7, 2014 at 4:54 PM

Hi Sebastien,

I am already using the API and .ExactMatch(). Here is my current code base:
    .WithField("type", searchContentType)
searchResults = searchBuilder.Search();
Even though I search for the correct "Content Type" in the "searchContentType" field, as soon as it is passed into Lucene.Services.LuceneSearchBuilder --> WithField(string field, string value) method then it is automatically lowercased:
public ISearchBuilder WithField(string field, string value) {

    if (!String.IsNullOrWhiteSpace(value)) {
        _query = new TermQuery(new Term(field, QueryParser.Escape(value.ToLower())));

    return this;
For this reason I do not believe it is possible to use the search API as the value passed in to search is lowercased while the content type is being stored as an upper case (i.e. not lower cased). It seems that:
  1. Everything going into Lucene should be lower cased
  2. OR the WithField method should not automatically lower casing (leave that to the user)
  3. OR I need to make up a new indexed content type (call it mytype) that is lower cased and can be used as I want it (so as not to mess up Orchard core)
Look forward to thoughts.

manudea wrote Aug 14, 2014 at 9:58 AM

I think the best is the proposed fix n. 1)

please vote here to be fixed in this new ticket (this one was closed without a fix)