API Questions on Kentico API.
Version 6.x > API > Search API...am i doing this right? View modes: 
User avatar
Member
Member
imjames - 6/21/2012 4:15:46 PM
   
Search API...am i doing this right?
Hey there, im trying to use the smart search APIs to do a search however it never really returns anything through the API, however when i do the smart search preview in the Site Manager, it returns items..

Anyone got any ideas on what im doing wrong?
 // Get the search index
string culture = Functions.GetPreferredCulture();
CMSSiteProvider.SearchIndexInfo sii = CMSSiteProvider.SearchIndexInfoProvider.GetSearchIndexInfo(String.Format("hub.searchitems_{0}", culture));

int numberOfResults = 0;
List<dynamic> list = new List<dynamic>();
if (!string.IsNullOrEmpty(searchTerm))
{
// Get current search mode from query string
string searchMode = QueryHelper.GetString("searchmode", "");

CMS.ISearchEngine.SearchModeEnum searchModeEnum = CMS.ISearchEngine.SearchHelper.GetSearchModeEnum(searchMode);

// Get current index info object
// Check whether index info exists
if (sii != null)
{
// Keep search text in search textbox
//txtSearchFor.Text = searchText;

searchTerm = CMSSiteProvider.SearchHelper.CombineSearchCondition(searchTerm, null, searchModeEnum, CMSSiteProvider.SearchOptionsEnum.FullSearch, null, null, null, false);

// Get positions and ranges for search method
int startPosition = 0;
int numberOfProceeded = 110;
int displayResults = 10;

// Search
//DataSet results = CMSSiteProvider.SearchHelper.Search(searchTerm, null, null, null,CMSContext.CurrentUser.PreferredCultureCode, null, false, false, false, sii.IndexName, displayResults, startPosition, numberOfProceeded, (CMSSiteProvider.UserInfo)CMSContext.CurrentUser, out numberOfResults, null, null);
DataSet results = CMSSiteProvider.SearchHelper.Search(searchTerm, null, null, null, "##ALL##", null, false, false, false, sii.IndexName, displayResults, startPosition, numberOfProceeded, null, out numberOfResults, null, null);

// If found at least one item
if (numberOfResults > 0)
{

foreach (DataRow item in results.Tables[0].Rows)
{
dynamic p = new
{
url = CMS.Controls.TransformationHelper.HelperObject.SearchResultUrl(ValidationHelper.GetString(item["id"], string.Empty), ValidationHelper.GetString(item["type"], string.Empty), true),
imageUrl = GeneralHelper.GetAttachmentURL(ValidationHelper.GetGuid(item["Image"], new Guid()), CMSContext.CurrentSiteID),
name = ValidationHelper.GetString(item["Title"], string.Empty)
};

list.Add(p);
}
}
}
}

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 6/22/2012 9:29:03 AM
   
RE:Search API...am i doing this right?
Hello,

Could you please try to check if there are some significant differences between your code and the native Kentico code, which can be found in the file: ~CMSModules\SmartSearch\Controls\SearchResults.ascx.cs

Please check the Search() function around line 1140.

Additionally, could you please compare the parameters going into the Search method and your code?

Best regards,
Boris Pocatko

User avatar
Member
Member
imjames - 6/22/2012 10:28:55 AM
   
RE:Search API...am i doing this right?
Hey Boris,

Thats where i actually copied the code from initially. I've tried to make the parameters as close as possible to that as well, and while it seems to work sometimes, other times it does not. I was hoping there was some glaring issue i was missing. Any other ideas?

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 6/25/2012 3:22:29 AM
   
RE:Search API...am i doing this right?
Hello,

I couldn't spot any obvious issues. Please try to identify when your code is failing and what parameters are supplied in that case. You will have to run your site in debugging mode to identify the issue. If you will be able to tell me which parameters cause the code to fail, then I will be able to reproduce it on my side.

Best regards,
Boris Pocatko

User avatar
Member
Member
Chris P - 1/13/2013 6:21:52 PM
   
RE:Search API...am i doing this right?
Hi I'm also seeing results in the search preview section of smart search, but I'm not seeing the same results in the Smart search box on the site.

The search box is using 'Any word' in both places.

kentico v7.0

Is there something else I need to enable?

Thanks,
Chris

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 1/15/2013 4:37:17 AM
   
RE:Search API...am i doing this right?
Hello,

Are you using any custom code or are you referring to the out of the box web parts? If you are using some custom API, please post it here so I can check the code you are using. If you are using our web parts please double check your settings according to our documentation. Additionally, are you sure nothing is returned, or is the transformation not displaying any data? Try to paste some static text into the transformation you are using to see, if it gets rendered at all.

Best regards,
Boris Pocatko

User avatar
Member
Member
Chris P - 1/15/2013 4:16:17 PM
   
RE:Search API...am i doing this right?
Yeah we're using the web parts. We found how to do it by changing the smart search results page web part to display the same document types as the smart search index.

Cheers