Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of how I converted Advanced Database Crawler functionality to Sitecore 7.
/* 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);
}
}
@russellmccloy

This comment has been minimized.

Copy link

russellmccloy commented Feb 9, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.