So I'm building my custom search parameters object and the Lucene string i'm building doesn't seem to be working.
I am attempting to filter results by DocumentType. Here is the code I have so far. Standard search works just fine. Attempting to add a Lucene condition fails to return any results. (Also, if anyone has a better way of getting a total count than running a second search with a much higher paged number, please let me know, its pretty messy this way.)
[Route("Search/Results/{page?}")]
public ActionResult Results(string q, string type, int page = 1)
{
int skip = 0;
int take = 10;
string finalQuery = "";
if (page > 1)
{
skip = ((page - 1) * take);
}
q = HttpUtility.UrlDecode(q);
if (String.IsNullOrWhiteSpace(q))
{
// Creates a model representing empty search results
SearchResultViewModel emptyModel = new SearchResultViewModel
{
Items = new List<SearchResultItem>(),
Query = String.Empty
};
return View(emptyModel);
}
if (!String.IsNullOrWhiteSpace(type))
{
finalQuery = q + " +DocumentType:" + type;
} else
{
finalQuery = q;
}
// Gets the search index
SearchIndexInfo index = SearchIndexInfoProvider.GetSearchIndexInfo("SiteIndex");
SearchResultViewModel model = new SearchResultViewModel();
string searchFor = finalQuery;
if (index != null)
{
/*These parameters just get a total count of the results for pagination (up to 1000)*/
SearchParameters countparameters = new SearchParameters()
{
SearchFor = searchFor,
SearchSort = "##SCORE##",
Path = "/%",
CurrentCulture = "EN-US",
DefaultCulture = CultureHelper.EnglishCulture.IetfLanguageTag,
CombineWithDefaultCulture = false,
CheckPermissions = false,
SearchInAttachments = false,
User = (UserInfo)MembershipContext.AuthenticatedUser,
SearchIndexes = index.IndexName,
StartingPosition = 0,
DisplayResults = 1000,
NumberOfProcessedResults = 1000,
NumberOfResults = 0,
AttachmentWhere = String.Empty,
AttachmentOrderBy = String.Empty,
ClassNames = ""
};
// Prepares the real search parameters
SearchParameters parameters = new SearchParameters()
{
SearchFor = searchFor,
SearchSort = "##SCORE##",
Path = "/%",
CurrentCulture = "EN-US",
DefaultCulture = CultureHelper.EnglishCulture.IetfLanguageTag,
CombineWithDefaultCulture = false,
CheckPermissions = false,
SearchInAttachments = false,
User = (UserInfo)MembershipContext.AuthenticatedUser,
SearchIndexes = index.IndexName,
StartingPosition = skip,
DisplayResults = 10,
NumberOfProcessedResults = 1000,
NumberOfResults = 0,
AttachmentWhere = String.Empty,
AttachmentOrderBy = String.Empty,
ClassNames = ""
};
// Performs the search and returns the matching results as a SearchResult object
SearchResult countResult = SearchHelper.Search(countparameters);
SearchResult results = SearchHelper.Search(parameters);
model.PageSize = 10;
model.CurrentPage = page;
model.TotalItems = countResult.Items.Count;
model.Items = results.Items;
model.Query = q;
}
return View(model);
}
So with a Document Type of "Condition" and a search query of "pediatric, my "searchFor" area ends up looking something like this:
"pediatric +DocumentType:Condition"
I've tried both using the Display name "Condition" or class name of "CMS.condition" and neither work. I'm at a loss here.