New Examine version. Fixes internal search and make it better.
[TFS Changeset #77995]
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -98,6 +98,9 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\foreign dlls\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Lucene.Net, Version=2.9.2.2, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>C:\Users\Shannon\Documents\Visual Studio 2008\Projects\Umbraco\Branch-4.1\foreign dlls\Lucene.Net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Scripting">
|
||||
<HintPath>..\..\foreign dlls\DLR 2.0 SP1\Microsoft.Scripting.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -666,6 +669,7 @@
|
||||
<Compile Include="umbraco\preview\Preview.cs" />
|
||||
<Compile Include="umbraco\scripting\MacroScript.cs" />
|
||||
<Compile Include="umbraco\scripting\ScriptEngine.cs" />
|
||||
<Compile Include="umbraco\Search\ExamineEvents.cs" />
|
||||
<Compile Include="umbraco\Search\QuickSearch.ascx.cs">
|
||||
<DependentUpon>QuickSearch.ascx</DependentUpon>
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
|
||||
60
umbraco/presentation/umbraco/Search/ExamineEvents.cs
Normal file
60
umbraco/presentation/umbraco/Search/ExamineEvents.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using umbraco.BusinessLogic;
|
||||
using Examine;
|
||||
using UmbracoExamine;
|
||||
using Lucene.Net.Documents;
|
||||
|
||||
namespace umbraco.presentation.umbraco.Search
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to wire up events for Examine
|
||||
/// </summary>
|
||||
public class ExamineEvents : ApplicationBase
|
||||
{
|
||||
|
||||
public ExamineEvents()
|
||||
: base()
|
||||
{
|
||||
var indexer = ExamineManager.Instance.IndexProviderCollection["InternalIndexer"] as UmbracoExamineIndexer;
|
||||
if (indexer != null)
|
||||
{
|
||||
indexer.DocumentWriting += new EventHandler<Examine.LuceneEngine.DocumentWritingEventArgs>(indexer_DocumentWriting);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void indexer_DocumentWriting(object sender, Examine.LuceneEngine.DocumentWritingEventArgs e)
|
||||
{
|
||||
if (e.Fields[UmbracoExamineIndexer.IndexTypeFieldName] == IndexTypes.Content && e.Fields.Keys.Contains("nodeName"))
|
||||
{
|
||||
//add the lower cased version
|
||||
e.Document.Add(new Field("__nodeName",
|
||||
e.Fields["nodeName"].ToLower(),
|
||||
Field.Store.YES,
|
||||
Field.Index.ANALYZED,
|
||||
Field.TermVector.NO
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Event handler to create a lower cased version of the node name, this is so we can support case-insensitive searching and still
|
||||
/// use the Whitespace Analyzer
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
//void ExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
|
||||
//{
|
||||
// if (e.IndexType == UmbracoExamine.IndexTypes.Content && e.Fields.Keys.Contains("nodeName"))
|
||||
// {
|
||||
// //add the lower cased version
|
||||
// e.Fields.Add("__nodeName", e.Fields["nodeName"].ToLower());
|
||||
// }
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ using System.Collections.Generic;
|
||||
using UmbracoExamine;
|
||||
using System.Web.Script.Serialization;
|
||||
using Examine;
|
||||
using Examine.LuceneEngine.SearchCriteria;
|
||||
|
||||
namespace umbraco.presentation.umbraco.Search
|
||||
{
|
||||
@@ -30,10 +31,10 @@ namespace umbraco.presentation.umbraco.Search
|
||||
var txt = UmbracoContext.Current.Request["q"].ToLower();
|
||||
|
||||
//the app can be Content or Media only, otherwise an exception will be thrown
|
||||
var app = "Content";
|
||||
var app = UmbracoExamine.IndexTypes.Content;
|
||||
if (!string.IsNullOrEmpty(UmbracoContext.Current.Request["app"]))
|
||||
{
|
||||
app = UmbracoContext.Current.Request["app"];
|
||||
app = UmbracoContext.Current.Request["app"].ToLower();
|
||||
}
|
||||
|
||||
int limit;
|
||||
@@ -41,24 +42,29 @@ namespace umbraco.presentation.umbraco.Search
|
||||
{
|
||||
limit = 100;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//if it doesn't start with "*", then search only nodeName and nodeId
|
||||
var internalSearcher = (app == "Member")
|
||||
? UmbracoContext.Current.InternalMemberSearchProvider
|
||||
: UmbracoContext.Current.InternalSearchProvider;
|
||||
var criteria = internalSearcher.CreateSearchCriteria(app);
|
||||
|
||||
//create some search criteria, make everything combined to be 'And' and only search the current app
|
||||
var criteria = internalSearcher.CreateSearchCriteria(app, Examine.SearchCriteria.BooleanOperation.And);
|
||||
|
||||
IEnumerable<SearchResult> results;
|
||||
if (txt.StartsWith("*"))
|
||||
{
|
||||
//TODO: Why is this here?? i don't understand.
|
||||
results = internalSearcher.Search("*", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
var operation = criteria.NodeName(txt);
|
||||
var operation = criteria.Field("__nodeName", txt.MultipleCharacterWildcard());
|
||||
|
||||
// ensure the user can only find nodes they are allowed to see
|
||||
if (UmbracoContext.Current.UmbracoUser.StartNodeId > 0)
|
||||
{
|
||||
operation.Or().Id(UmbracoContext.Current.UmbracoUser.StartNodeId);
|
||||
operation = operation.And().Id(UmbracoContext.Current.UmbracoUser.StartNodeId);
|
||||
}
|
||||
|
||||
results = internalSearcher.Search(operation.Compile());
|
||||
|
||||
Reference in New Issue
Block a user