Suggestion (help needed): refine search by content type
First of all, let me say this is a great project! It has been a piece of cake to configure to our look and feel. I <3 it!
However, I'd like to take it a step forward and I'm struggling to achieve what I want to do, mostly due to my complete inexperience in .net, let alone MVC (pretty sure cleverer people could have done it in 5 mins...).
Anyway, here's my need. I'd like to offer our users the ability to refine the search by content type.
Once they are on the search page, we'd like to provide a dropdown listing different content types to search against, so the returned results are only of that specific content type.
It would be great if somewhere in the code we also could manipulate the values returned from the querystring. For example, we have 2 content type "guide" (GuideMultiPart and QuickGuide). So, really, when the user is selecting "Guides", the search should look at X different content types
Something along the lines of:
SearchType = CleanseSearchTerm(("" + Request["content-type"]).ToLower(CultureInfo.InvariantCulture));
If (SearchType == "Guide"){
//do the search only on these nodes:
model.Parent.Guide && model.QuickGuide
...
}
It does indeed make sense. I don't think it is something I'd look to build into ezSearch on the whole, as the idea behind ezSearch is to do simple searching well, nothing more, nothing less. That being said, I do make sure that all the source for this is available within the package so that you can make these kinds of changes yourself.
So, lets see if we can find a solution to your problem.
As I'm sure you know, all the logic for searching can be found within the ezSearch.cshtml partial file. What this does is actually build a raw Lucene query to run against the general content index. To do what you want to do then, we'll need to update this to take into account a specific doctype. Now, in Lucene, the doc type alias should be stored in a field called __NodeTypeAlias, with that in mind I would imagine you could do something like the following.
In ezSearch.cshtml, around line 67 (just after we define the "query" Stringbuilder variable) add the following:
var contentType = CleanseSearchTerm(("" + Request["content-type"]).ToLower(CultureInfo.InvariantCulture));
if (!string.IsNullOrWhiteSpace(contentType) && contentType != "all") {
if (contentType == "guide") {
// "guide" is an alias that should resolve to multiple doc types
// so handle it specifically.
query.Append("+((__NodeTypeAlias:guidemultipart) (__NodeTypeAlias:quickguide))");
} else {
// for anything other than a guide document, just assume the contentType value
// is the alias of a doc type
query.AppendFormat("+(__NodeTypeAlias:{0})", contentType);
}
}
(NB: This is all written freehand, so may have mistakes).
This should should take into account any "content-type" variable passed into it, and filter the results accordingly.
Suggestion (help needed): refine search by content type
First of all, let me say this is a great project! It has been a piece of cake to configure to our look and feel. I <3 it!
However, I'd like to take it a step forward and I'm struggling to achieve what I want to do, mostly due to my complete inexperience in .net, let alone MVC (pretty sure cleverer people could have done it in 5 mins...).
Anyway, here's my need. I'd like to offer our users the ability to refine the search by content type.
Once they are on the search page, we'd like to provide a dropdown listing different content types to search against, so the returned results are only of that specific content type.
It would be great if somewhere in the code we also could manipulate the values returned from the querystring. For example, we have 2 content type "guide" (GuideMultiPart and QuickGuide). So, really, when the user is selecting "Guides", the search should look at X different content types
Something along the lines of:
Does it make sense? :]
Hi Franz,
It does indeed make sense. I don't think it is something I'd look to build into ezSearch on the whole, as the idea behind ezSearch is to do simple searching well, nothing more, nothing less. That being said, I do make sure that all the source for this is available within the package so that you can make these kinds of changes yourself.
So, lets see if we can find a solution to your problem.
As I'm sure you know, all the logic for searching can be found within the ezSearch.cshtml partial file. What this does is actually build a raw Lucene query to run against the general content index. To do what you want to do then, we'll need to update this to take into account a specific doctype. Now, in Lucene, the doc type alias should be stored in a field called __NodeTypeAlias, with that in mind I would imagine you could do something like the following.
In ezSearch.cshtml, around line 67 (just after we define the "query" Stringbuilder variable) add the following:
(NB: This is all written freehand, so may have mistakes).
This should should take into account any "content-type" variable passed into it, and filter the results accordingly.
Give it a try, and let me know how you get on.
many thanks
Matt
Hello Matt,
Thank you so much for your reply and your suggestion. I will play around with it and let you know. \o/
You, Sir, are a genius! It works and it does exactly what we needed to do. Grazie mille! :D
Great stuff.
Glad I could help :)
Matt
is working on a reply...