Hi,

Nitin Shiralkar wrote:
Questions:


1.       Is there a better to way to handle above un-tokenized field
to enable case-insensitive searches?

Try a variation of this QueryParser subclass. The class assumes
that only the field "title" is tokenized/analyzed. For other
fields, a TermQuery will be used:


    public class ExtendedQueryParser : QueryParser
    {
        public LuciferQueryParser(string field, Analyzer analyzer)
            : base(field, analyzer)
        {
        }

        public override Query GetFieldQuery(string field, string queryText)
        {
            if (field == "title")
                return base.GetFieldQuery(field, queryText);

            return new TermQuery(new Term(field, queryText));
        }

public override Query GetWildcardQuery(string field, string termStr)
        {
            try
            {
                if (field != "title")
                    SetLowercaseExpandedTerms(false);

                return base.GetWildcardQuery(field, termStr);
            }
            finally
            {
                if (field != "title")
                    SetLowercaseExpandedTerms(true);
            }
        }

        public override Query GetPrefixQuery(string field, string termStr)
        {
            try
            {
                if (field != "title")
                    SetLowercaseExpandedTerms(false);

                return base.GetPrefixQuery(field, termStr);
            }
            finally
            {
                if (field != "title")
                    SetLowercaseExpandedTerms(true);
            }
        }
    }


Robert

Reply via email to