I have been making a CAML query search webpart, which already provides the cascaded search on the documents through out the directory using CAML on Columns as metadata to search.
For now I have the dropdown to make cascading search work. But now I want it to behave like Google Search no criteria defined just a text box to search:
Type anything relevant and the CAML should be so that it searches all the columns against the documents in the library and return those which matches anywhere. Somewhere we call it "full text search", mind it I am not desiring Content Search for now and not using SharePoint Search Services.
Solution Approach 1: Just a thought I concatenate all the metadata values against each document and apply pattern matching logic (somewhat like KMP algorithm) on this concatenated set with the search statement entered in the search text box. I dont know should I go for it or not and how will I achieve it because it might need permutation and combination of the concatenated metadata values?
Any solutions?
Current code for cascading:
private string GetCamlQuery()
{
string queryString = string.Empty;
string searchQueryString = string.Empty;
string sortQueryString = string.Empty;
StringBuilder querySB = new StringBuilder();
List<SearchCriteria> searchCriteriaList = null;
if (ViewState["SearchCriteriaList"] != null)
{
searchCriteriaList = ViewState["SearchCriteriaList"] as List<SearchCriteria>;
}
else
{
searchCriteriaList = new List<SearchCriteria>();
searchCriteriaList.Add(new SearchCriteria("ContentType", "Document"));
}
if (ddlDocument.SelectedIndex > 0 && txtSearchTag.Text.Trim() != string.Empty)
{
if (ddlDocument.SelectedItem.Text == "Area" || ddlDocument.SelectedItem.Text == "Document Type" || ddlDocument.SelectedItem.Text == "Tags" || ddlDocument.SelectedItem.Text == "Document Category" || ddlDocument.SelectedItem.Text == "Customer")
searchCriteriaList.Add(new SearchCriteria(ddlDocument.SelectedItem.Text, txtSearchTag.Text.Trim()));
}
List<string> conditions = new List<string>();
foreach (SearchCriteria item in searchCriteriaList)
{
if (item.Key == "ContentType")
conditions.Add("<Eq><FieldRef Name='ContentType'/><Value Type='Text'>" + item.Values + "</Value></Eq>");
else if (item.Key == "Area")
conditions.Add("<Contains><FieldRef Name='Area'/><Value Type='Text'>" + item.Values + "</Value></Contains>");
else if (item.Key == "Document Type")
conditions.Add("<Contains><FieldRef Name='TypeOfDoc' /><Value Type='Text'>" + item.Values + "</Value></Contains>");
else if (item.Key == "Tags")
{
conditions.Add("<Contains><FieldRef Name='Tags' /><Value Type='Text'>" + item.Values + "</Value></Contains>");
}
else if (item.Key == "Document Category")
{
conditions.Add("<Contains><FieldRef Name='Category' /><Value Type='Text'>" + item.Values + "</Value></Contains>");
}
else if (item.Key == "Customer")
{
conditions.Add("<Contains><FieldRef Name='CustomerName' /><Value Type='Text'>" + item.Values + "</Value></Contains>");
}
}
querySB.Append("<Where>");
string merged = MergeCAMLConditions(conditions, MergeType.And);
querySB.Append(merged);
querySB.Append("</Where>");
searchQueryString = querySB.ToString();
ViewState["SearchCriteriaList"] = searchCriteriaList;
ViewState["SearchQueryString"] = searchQueryString;
queryString = searchQueryString;
ViewState["queryString"] = queryString;
return queryString;
}