Umbraco Examine cant search for input with two words
Hello, my search works when an input like "testimonial" is searched for, but an input like "about us" returns 0 results. I've seen a forum post where people used "split" and "GroupedOr" but i cant get it to work in my code. Here's my code:
public string Term { get; set; } public int Count { get; set; }
protected void Page_Load(object sender, EventArgs e) { if (!String.IsNullOrEmpty(Request.QueryString["s"])) { Term = Request.QueryString["s"].ToString(); if (Term.Length > 1) { //Create search Criteria var sc = ExamineManager.Instance.CreateSearchCriteria();
I wonder if this is the same problem I've noted with the admin backend UI search (you know, the thing in the top-left corner) where you only get results if you search for a single word, but never get any results if you include two or more. Hmmm....
Umbraco Examine cant search for input with two words
Hello, my search works when an input like "testimonial" is searched for, but an input like "about us" returns 0 results. I've seen a forum post where people used "split" and "GroupedOr" but i cant get it to work in my code. Here's my code:
public string Term { get; set; }
public int Count { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(Request.QueryString["s"]))
{
Term = Request.QueryString["s"].ToString();
if (Term.Length > 1)
{
//Create search Criteria
var sc = ExamineManager.Instance.CreateSearchCriteria();
//define query
var query = sc.NodeName(Term.MultipleCharacterWildcard())
.Or()
.Field("block1", Term.MultipleCharacterWildcard())
.Or()
.Field("block2", Term.MultipleCharacterWildcard())
.Or()
.Field("block3", Term.MultipleCharacterWildcard())
.Or()
.Field("blockTitle1", Term.MultipleCharacterWildcard())
.Or()
.Field("blockTitle2", Term.MultipleCharacterWildcard())
.Or()
.Field("blockTitle3", Term.MultipleCharacterWildcard())
.Or()
.Field("siteName", Term.MultipleCharacterWildcard());
// .Or()
// .Field("summary", Term.MultipleCharacterWildcard());
//or search by keyword
var results = ExamineManager.Instance.SearchProviderCollection["WebsiteSearcher"].Search(Term, true);
rp_results.DataSource = results;
Count = results.Count();
rp_results.DataBind();
}
}
}
Thanks in advance.
babajide,
You need to do var terms = Term.split(' ');
foreach(var t in terms){
//use t as query input with Or
}
Regards
Ismail
Also why are you doing
var results = ExamineManager.Instance.SearchProviderCollection["WebsiteSearcher"].Search(Term, true);
if should be
var results = ExamineManager.Instance.SearchProviderCollection["WebsiteSearcher"].Search(query.Compile());
I wonder if this is the same problem I've noted with the admin backend UI search (you know, the thing in the top-left corner) where you only get results if you search for a single word, but never get any results if you include two or more. Hmmm....
is working on a reply...