views:

185

answers:

1

I would like to make the field name in my query case incesitive so that when users make the queries

title:Jurassic

or

Title:Jurassic

NHibernate Search would yield the same result.

As I understand the way Lucene works field names are case sensitive. Is there a way to configure NH Search/Lucene to lowercase the field names when indexing and lowercase the fieldname when searching?

A: 

Field names are case sensitive. One way is to specify all of your fields to be completely lowercase and then lowercase your query.

class example:

[Indexed]
class Article
{
     [Field(Name="title", Index=Index.Tokenized, Store=Store.No)]
     Title { get; set; }
}

query example

string query = tbSearch.Text;
query = query.ToLower();
IFullTextQuery ftq = search.CreateFullTextQuery(query);
Andrew Smith
I knew I could always lowercase everything. I was just wondering if thhere were some automatic way to configure the query parser to match fields in a case insensitive way.
Simon Laroche
I think the best way to handle that is to look into building your own QueryParser. Lucene.Net comes with a MultiFieldQueryParser. I think checking out the source code to this class will help you understand what it takes to build a custom QueryParser.
Andrew Smith
Be careful, the QueryParser wouldn't recognize Operators anymore, since all Operators like AND/OR/NOT/TO have to be uppercase
binco