Last active
December 31, 2015 22:59
-
-
Save JamesSkemp/8056992 to your computer and use it in GitHub Desktop.
Example of how I converted Advanced Database Crawler functionality to Sitecore 7.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Sitecore 6.x code */ | |
var searchParam = new SearchParam | |
{ | |
Database = currentDB, | |
Language = "", | |
TemplateIds = "", | |
LocationIds = blog.ID.Guid.ToString(), | |
FullTextQuery = terms | |
}; | |
using (var runner = new QueryRunner("advanced")) | |
{ | |
var skinnies = runner.GetItems(searchParam); | |
foreach (var i in skinnies) | |
{ | |
var tempItemp = blog.Database.GetItem(i.ItemID); | |
if (tempItemp.TemplateName == "BlogEntry") | |
{ | |
result.Add(tempItemp); | |
} | |
} | |
} | |
/* Sitecore 7.x code */ | |
using (var context = ContentSearchManager.GetIndex("sitecore_web_index").CreateSearchContext()) | |
{ | |
var termSearch = PredicateBuilder.True<SearchResultItem>(); | |
foreach (var term in terms.Split(' ')) | |
{ | |
var newTerm = term; | |
termSearch = termSearch.And(t => t.Content.Contains(newTerm)); | |
} | |
var query = context | |
.GetQueryable<SearchResultItem>() | |
.Where(i => | |
i.TemplateName == "BlogEntry" | |
&& i.Path.StartsWith(blog.Paths.Path) | |
) | |
.Where(termSearch); | |
foreach (var item in query) | |
{ | |
var contentItem = blog.Database.GetItem(item.ItemId); | |
result.Add(contentItem); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
James,
Have you got any more code that will give it more context? ie. what is the type for blog?
Also, a readme file would be great.
Also, what is terms, it is not defined.
thanks
Russ