Unable to view search items even though they are apparently being indexed
I am currently working on implementing uBlogsy into a sight and have come across an issue with displaying search results. My scripts looks like the following:
// get item count
int count = int.Parse(@Parameter.ItemCount);
IEnumerable nodes;
// get tag, category, or author from query string
var tag = Request.QueryString["tag"];
var category = Request.QueryString["category"];
var author = Request.QueryString["author"];
var searchTerm = Request.QueryString["search"];
var commenter = Request.QueryString["commenter"];
int page = int.TryParse(Request.QueryString["page"], out page) ? page : 1;
IEnumerable posts = PostService.Instance.GetPosts(Model.Id, tag, category, author, searchTerm, commenter, page - 1, count);
// get landing node
var landing = DataService.Instance.GetLanding(Model.Id);
// only get posts where the path has the landing node's id.
posts = posts.Where(x => x.Path.Contains(landing.Id + ","));
nodes = posts.Take(count).ToList();
int postCount = PostService.Instance.GetPosts(Model.Id, tag, category, author, searchTerm, commenter, 0, int.MaxValue).Count;
// render search result count when this script is displaying search results
if (!string.IsNullOrEmpty(searchTerm))
{
@nodes.Count() Results for "@searchTerm.ToString()":
}
@foreach (DynamicNode n in nodes)
{
@{
var image = @n.GetProperty("blogImage");
if (image != null)
{
}
else
{
}
}
// For debugging Examine
IEnumerable results = ExamineManager.Instance.Search("diet", true);
Examine has @results.Count() indexes for "diet"
The output for the Examine test is "Examine has 4 indexes for "diet"". However when searching for the word "diet" (url: blog.aspx?search=diet) I am getting 0 results.
I have tried this script on another site with a fresh install of uBlogsy and it seems to work fine so I assume that it has something to do with the structure of my blog? I can't be certain as I can't see inside PostService.Instance.GetPosts(Model.Id, tag, category, author, searchTerm, commenter, page - 1, count); which keep returning 0 when I am debugging the code in VS.
Finally fixed the problem, it is when returning the sorted nodes from your DoSearch function. I found your source control online. Changing the return function to
Unable to view search items even though they are apparently being indexed
I am currently working on implementing uBlogsy into a sight and have come across an issue with displaying search results. My scripts looks like the following:
// get item count int count = int.Parse(@Parameter.ItemCount); IEnumerable nodes; // get tag, category, or author from query string var tag = Request.QueryString["tag"]; var category = Request.QueryString["category"]; var author = Request.QueryString["author"]; var searchTerm = Request.QueryString["search"]; var commenter = Request.QueryString["commenter"]; int page = int.TryParse(Request.QueryString["page"], out page) ? page : 1; IEnumerable posts = PostService.Instance.GetPosts(Model.Id, tag, category, author, searchTerm, commenter, page - 1, count); // get landing node var landing = DataService.Instance.GetLanding(Model.Id); // only get posts where the path has the landing node's id. posts = posts.Where(x => x.Path.Contains(landing.Id + ",")); nodes = posts.Take(count).ToList(); int postCount = PostService.Instance.GetPosts(Model.Id, tag, category, author, searchTerm, commenter, 0, int.MaxValue).Count; // render search result count when this script is displaying search results if (!string.IsNullOrEmpty(searchTerm)) {
@nodes.Count() Results for "@searchTerm.ToString()":
}
@foreach (DynamicNode n in nodes) {-
@{
var image = @n.GetProperty("blogImage");
if (image != null)
{
}
else
{
}
}
}
@*pagination*@ @RenderPagination(page, postCount, count)@n.GetProperty("uBlogsyPostDate").Value.FormatDateTime("dd/MM/yy")
@n.GetProperty("uBlogsyContentTitle").Value
@RenderPage("/macroScripts/uBlogsy/uBlogsyListCategories.cshtml", @n.Id)// For debugging Examine IEnumerable results = ExamineManager.Instance.Search("diet", true);
Examine has @results.Count() indexes for "diet"
The output for the Examine test is "Examine has 4 indexes for "diet"". However when searching for the word "diet" (url: blog.aspx?search=diet) I am getting 0 results.
Any help would be much appreciated.
Regards,
Mark
Ok it looks like the forum is broken, I can't edit that horrible post (XSLT Error...) here's a paste bin:
http://pastebin.com/xMKUKzKg
Also, @Parameter.Small always == "1" in my case, this is where I want to show results.
Should also note that I am using the uBlogsy(2.1.1.1) and Umbraco(4.11.3 (Assembly version: 1.0.4760.34993))
Regards,
Mark
Bumping as I am losing my mind over this. I do apologise for the messy post but it is too late to edit!
I have tried this script on another site with a fresh install of uBlogsy and it seems to work fine so I assume that it has something to do with the structure of my blog? I can't be certain as I can't see inside PostService.Instance.GetPosts(Model.Id, tag, category, author, searchTerm, commenter, page - 1, count); which keep returning 0 when I am debugging the code in VS.
Any help would be most appreciated.
Mark
Finally fixed the problem, it is when returning the sorted nodes from your DoSearch function. I found your source control online. Changing the return function to
return nodes.Distinct(new uBlogsy.BusinessLogic.Helpers.DynamicNodeEqualityComparer());
It is because my blog structure is slightly different. You may want to update your code to allow people to change this themselves.
Mark
is working on a reply...