diff --git a/src/Orchard.Web/Core/Indexing/Lucene/DefaultSearchBuilder.cs b/src/Orchard.Web/Core/Indexing/Lucene/DefaultSearchBuilder.cs index 47aae8ac2..93a084672 100644 --- a/src/Orchard.Web/Core/Indexing/Lucene/DefaultSearchBuilder.cs +++ b/src/Orchard.Web/Core/Indexing/Lucene/DefaultSearchBuilder.cs @@ -28,6 +28,7 @@ namespace Orchard.Core.Indexing.Lucene { private bool _sortDescending; private string _parse; private readonly Analyzer _analyzer; + private string _defaultField; public ILogger Logger { get; set; } @@ -46,7 +47,16 @@ namespace Orchard.Core.Indexing.Lucene { _analyzer = DefaultIndexProvider.CreateAnalyzer(); } - public ISearchBuilder Parse(string query) { + public ISearchBuilder Parse(string defaultField, string query) { + if ( String.IsNullOrWhiteSpace(defaultField) ) { + throw new ArgumentException("Default field can't be empty"); + } + + if ( String.IsNullOrWhiteSpace(query) ) { + throw new ArgumentException("Query can't be empty"); + } + + _defaultField = defaultField; _parse = query; return this; } @@ -111,7 +121,7 @@ namespace Orchard.Core.Indexing.Lucene { private Query CreateQuery() { if(!String.IsNullOrWhiteSpace(_parse)) { - return new QueryParser(DefaultIndexProvider.LuceneVersion, "body", DefaultIndexProvider.CreateAnalyzer()).Parse(_parse); + return new QueryParser(DefaultIndexProvider.LuceneVersion, _defaultField, DefaultIndexProvider.CreateAnalyzer()).Parse(_parse); } var query = new BooleanQuery(); diff --git a/src/Orchard/Indexing/ISearchBuilder.cs b/src/Orchard/Indexing/ISearchBuilder.cs index 3994a37bd..83e3ffda4 100644 --- a/src/Orchard/Indexing/ISearchBuilder.cs +++ b/src/Orchard/Indexing/ISearchBuilder.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; namespace Orchard.Indexing { public interface ISearchBuilder { - ISearchBuilder Parse(string query); + ISearchBuilder Parse(string defaultField, string query); ISearchBuilder WithField(string field, string value); ISearchBuilder WithField(string field, string value, bool wildcardSearch);