Skip to content

Instantly share code, notes, and snippets.

@JamesSkemp
Last active December 31, 2015 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesSkemp/8056992 to your computer and use it in GitHub Desktop.
Save JamesSkemp/8056992 to your computer and use it in GitHub Desktop.
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
Copy link

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