Fixing ContentItem.ContentType indexing so it can be queried by search

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2011-03-28 22:13:25 -07:00
parent d0af08fce9
commit f2586d06d2
5 changed files with 50 additions and 8 deletions

View File

@@ -375,6 +375,42 @@ namespace Orchard.Tests.Modules.Indexing {
Assert.That(_searchBuilder.WithField("tag-value", "tag").Count(), Is.EqualTo(1)); Assert.That(_searchBuilder.WithField("tag-value", "tag").Count(), Is.EqualTo(1));
} }
[Test]
public void AnalyzedFieldsAreNotCaseSensitive() {
_provider.CreateIndex("default");
var documentIndex = _provider.New(1)
.Add("tag-id", 1)
.Add("tag-value", "Tag1").Analyze();
_provider.Store("default", documentIndex);
// trying in prefix mode
Assert.That(_searchBuilder.WithField("tag-value", "tag").Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("tag-value", "Tag").Count(), Is.EqualTo(1));
// trying in full word match mode
Assert.That(_searchBuilder.WithField("tag-value", "tag1").ExactMatch().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("tag-value", "Tag1").ExactMatch().Count(), Is.EqualTo(1));
}
[Test]
public void NotAnalyzedFieldsAreSearchable() {
_provider.CreateIndex("default");
var documentIndex = _provider.New(1)
.Add("tag-id", 1)
.Add("tag-valueL", "tag1")
.Add("tag-valueU", "Tag1");
_provider.Store("default", documentIndex);
// a value which is not analyzed, is not lowered cased in the index
Assert.That(_searchBuilder.WithField("tag-valueL", "tag").Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("tag-valueU", "tag").Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.WithField("tag-valueL", "Tag").Count(), Is.EqualTo(1)); // queried term is lower cased
Assert.That(_searchBuilder.WithField("tag-valueU", "Tag").Count(), Is.EqualTo(0)); // queried term is lower cased
Assert.That(_searchBuilder.WithField("tag-valueL", "tag1").ExactMatch().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("tag-valueU", "tag1").ExactMatch().Count(), Is.EqualTo(0));
}
[Test] [Test]
public void ShouldReturnAllDocuments() { public void ShouldReturnAllDocuments() {

View File

@@ -49,8 +49,8 @@ namespace Orchard.Core.Common.Handlers {
OnPublishing<ContentPart<CommonPartVersionRecord>>(AssignPublishingDates); OnPublishing<ContentPart<CommonPartVersionRecord>>(AssignPublishingDates);
OnIndexing<CommonPart>((context, commonPart) => context.DocumentIndex OnIndexing<CommonPart>((context, commonPart) => context.DocumentIndex
.Add("type", commonPart.ContentItem.ContentType).Store() .Add("type", commonPart.ContentItem.ContentType).Analyze().Store()
.Add("author", commonPart.Owner.UserName).Store() .Add("author", commonPart.Owner.UserName).Analyze().Store()
.Add("created", commonPart.CreatedUtc ?? _clock.UtcNow).Store() .Add("created", commonPart.CreatedUtc ?? _clock.UtcNow).Store()
.Add("published", commonPart.PublishedUtc ?? _clock.UtcNow).Store() .Add("published", commonPart.PublishedUtc ?? _clock.UtcNow).Store()
.Add("modified", commonPart.ModifiedUtc ?? _clock.UtcNow).Store() .Add("modified", commonPart.ModifiedUtc ?? _clock.UtcNow).Store()

View File

@@ -103,7 +103,7 @@ namespace Lucene.Services {
public ISearchBuilder WithField(string field, bool value) { public ISearchBuilder WithField(string field, bool value) {
CreatePendingClause(); CreatePendingClause();
_query = new TermQuery(new Term(field, value.ToString())); _query = new TermQuery(new Term(field, value.ToString().ToLower()));
return this; return this;
} }
@@ -121,7 +121,7 @@ namespace Lucene.Services {
public ISearchBuilder WithinRange(string field, string min, string max) { public ISearchBuilder WithinRange(string field, string min, string max) {
CreatePendingClause(); CreatePendingClause();
_query = new TermRangeQuery(field, QueryParser.Escape(min.ToLower()), QueryParser.Escape(min.ToLower()), true, true); _query = new TermRangeQuery(field, QueryParser.Escape(min.ToLower()), QueryParser.Escape(max.ToLower()), true, true);
return this; return this;
} }
@@ -177,7 +177,9 @@ namespace Lucene.Services {
if(!_exactMatch) { if(!_exactMatch) {
var termQuery = _query as TermQuery; var termQuery = _query as TermQuery;
if(termQuery != null) { if(termQuery != null) {
_query = new PrefixQuery(termQuery.GetTerm()); var term = termQuery.GetTerm();
// prefixed queries are case sensitive
_query = new PrefixQuery(term);
} }
} }
if ( _asFilter ) { if ( _asFilter ) {

View File

@@ -13,8 +13,12 @@ namespace Orchard.Tags.Handlers {
OnRemoved<TagsPart>((context, tags) => OnRemoved<TagsPart>((context, tags) =>
tagService.RemoveTagsForContentItem(context.ContentItem)); tagService.RemoveTagsForContentItem(context.ContentItem));
OnIndexing<TagsPart>((context, tagsPart) => OnIndexing<TagsPart>(
context.DocumentIndex.Add("tags", String.Join(", ", tagsPart.CurrentTags.Select(t => t.TagName))).Analyze()); (context, tagsPart) => {
foreach (var tag in tagsPart.CurrentTags) {
context.DocumentIndex.Add("tags", tag.TagName).Analyze();
}
});
} }
} }
} }

View File

@@ -201,7 +201,7 @@
<VisualStudio> <VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}"> <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties> <WebProjectProperties>
<UseIIS>False</UseIIS> <UseIIS>True</UseIIS>
<AutoAssignPort>False</AutoAssignPort> <AutoAssignPort>False</AutoAssignPort>
<DevelopmentServerPort>30320</DevelopmentServerPort> <DevelopmentServerPort>30320</DevelopmentServerPort>
<DevelopmentServerVPath>/OrchardLocal</DevelopmentServerVPath> <DevelopmentServerVPath>/OrchardLocal</DevelopmentServerVPath>