I'm trying to write a basic search, and part of the sort logic compares the captured keyword length against the returned results Substring based on the same length. So if the keyword is 9 characters, the logic then searches the first 9 characters of each returned result to find if the keyword matches the Substring.

The problem I get is that if I search against the keywords length, it claims that I am out of range on the Substring index of the data I'm comparing the keyword to, even though the only results returned will at the very least contain the captured keyword length and more. My code is below:

string KEYWORDS = !string.IsNullOrEmpty(Request.QueryString["keywords"]) ? Request.QueryString["keywords"] : string.Empty;

var query1 = Query.WhereFullTextContains(KEYWORDS, In.Column("Property_Title", 100), In.Column("MD_Course_UCASCode", 50));
var query2 = Query.WhereFullTextContains(KEYWORDS, In.Column("MD_Course_Departments", 50), In.Column("MD_Course_Departments2", 50));

var search = new NodeFinder().Find(query1);
var search2 = new NodeFinder().Find(query2);
int searchindex = KEYWORDS.Length;

var searchall = search.Union(search2).GroupBy(x => x.Title).Select(y => y.First());


  @foreach (ContentNode node in searchall) {

if (node.Title.Substring(0, searchindex) == "economics")

<div class="sys_subitem">
                        <h3><a href="@node.Path">@node.Title</a></h3>
                                                <dt>UCAS Code:</dt>

Any ideas what I might be doing wrong? Help would be appreciated!

Related posts

Recent Viewed