public string FindMatter(RequestObject requestObject, Client client, SearchObject searchObject) { string result = string.Empty; if (null != requestObject && null != client & null != searchObject && ValidationHelperFunctions.CheckRequestValidatorToken()) { try { // Encode all fields which are coming from js SearchHelperFunctions.EncodeSearchDetails(searchObject.Filters, true); // Encode Search Term searchObject.SearchTerm = (null != searchObject.SearchTerm) ? Encoder.HtmlEncode(searchObject.SearchTerm).Replace(ConstantStrings.ENCODEDDOUBLEQUOTES, ConstantStrings.DoubleQuote) : string.Empty; using (ClientContext clientContext = ServiceUtility.GetClientContext(requestObject.SPAppToken, new Uri(client.Url), requestObject.RefreshToken)) { KeywordQuery keywordQuery = new KeywordQuery(clientContext); if (string.IsNullOrWhiteSpace(searchObject.SearchTerm)) { searchObject.SearchTerm = ConstantStrings.Asterisk; } if (null != searchObject.Filters) { if (1 == searchObject.Filters.FilterByMe) { ////Get logged in user alias Users currentUserDetail = UIUtility.GetLoggedInUserDetails(clientContext); string userTitle = currentUserDetail.Name; searchObject.SearchTerm = string.Concat(searchObject.SearchTerm, ConstantStrings.Space, ConstantStrings.OperatorAnd, ConstantStrings.Space, ConstantStrings.OpeningBracket, SearchConstants.ManagedPropertyResponsibleAttorney, ConstantStrings.COLON, ConstantStrings.Space, ConstantStrings.DoubleQuote, userTitle, ConstantStrings.DoubleQuote, ConstantStrings.Space, ConstantStrings.OperatorOR, ConstantStrings.Space, SearchConstants.ManagedPropertyTeamMembers, ConstantStrings.COLON, ConstantStrings.Space, ConstantStrings.DoubleQuote, userTitle, ConstantStrings.DoubleQuote, ConstantStrings.Space, ConstantStrings.ClosingBracket); } keywordQuery = SearchHelperFunctions.FilterMatters(searchObject, keywordQuery); } keywordQuery = SearchHelperFunctions.KeywordQueryMetrics(client, searchObject, keywordQuery, ConstantStrings.DocumentLibraryFilterCondition, SearchConstants.ManagedPropertyIsMatter, true); // Create a list of managed properties which are required to be present in search results List <string> managedProperties = new List <string>(); managedProperties.Add(SearchConstants.ManagedPropertyTitle); managedProperties.Add(SearchConstants.ManagedPropertyName); managedProperties.Add(SearchConstants.ManagedPropertyDescription); managedProperties.Add(SearchConstants.ManagedPropertySiteName); managedProperties.Add(SearchConstants.ManagedPropertyLastModifiedTime); managedProperties.Add(SearchConstants.ManagedPropertyPracticeGroup); managedProperties.Add(SearchConstants.ManagedPropertyAreaOfLaw); managedProperties.Add(SearchConstants.ManagedPropertySubAreaOfLaw); managedProperties.Add(SearchConstants.ManagedPropertyMatterId); managedProperties.Add(SearchConstants.ManagedPropertyCustomTitle); managedProperties.Add(SearchConstants.ManagedPropertyPath); managedProperties.Add(SearchConstants.ManagedPropertyMatterName); managedProperties.Add(SearchConstants.ManagedPropertyOpenDate); managedProperties.Add(SearchConstants.ManagedPropertyClientName); managedProperties.Add(SearchConstants.ManagedPropertyBlockedUploadUsers); managedProperties.Add(SearchConstants.ManagedPropertyResponsibleAttorney); managedProperties.Add(SearchConstants.ManagedPropertyClientID); managedProperties.Add(SearchConstants.ManagedPropertyMatterGuid); //Filter on Result source to fetch only Matter Center specific results keywordQuery.SourceId = new Guid(SearchConstants.SearchResultSourceID); keywordQuery = SearchHelperFunctions.AssignKeywordQueryValues(keywordQuery, managedProperties); keywordQuery.BypassResultTypes = true; result = SearchHelperFunctions.FillResultData(clientContext, keywordQuery, searchObject, true, managedProperties); } } catch (Exception exception) { result = Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName); } } else { result = string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, string.Empty, TextConstants.MessageNoInputs); } return(result); }
public string FindDocument(RequestObject requestObject, Client client, SearchObject searchObject) { string result = string.Empty; if (null != requestObject && null != client & null != searchObject && ValidationHelperFunctions.CheckRequestValidatorToken()) { try { // Encode all fields which are coming from js SearchHelperFunctions.EncodeSearchDetails(searchObject.Filters, false); // Encode Search Term searchObject.SearchTerm = (null != searchObject.SearchTerm) ? Encoder.HtmlEncode(searchObject.SearchTerm).Replace(ConstantStrings.ENCODEDDOUBLEQUOTES, ConstantStrings.DoubleQuote) : string.Empty; using (ClientContext clientContext = ServiceUtility.GetClientContext(requestObject.SPAppToken, new Uri(client.Url), requestObject.RefreshToken)) { KeywordQuery keywordQuery = new KeywordQuery(clientContext); if (string.IsNullOrWhiteSpace(searchObject.SearchTerm)) { searchObject.SearchTerm = ConstantStrings.Asterisk; } if (null != searchObject.Filters) { if (1 == searchObject.Filters.FilterByMe) { // Get the current logged in User clientContext.Load(clientContext.Web.CurrentUser); clientContext.ExecuteQuery(); string currentLoggedInUser = clientContext.Web.CurrentUser.Title; searchObject.SearchTerm = String.Concat(searchObject.SearchTerm, ConstantStrings.Space, ConstantStrings.OperatorAnd, ConstantStrings.Space, SearchConstants.ManagedPropertyAuthor, ConstantStrings.COLON, currentLoggedInUser); } keywordQuery = SearchHelperFunctions.FilterDocuments(searchObject, keywordQuery); } keywordQuery = SearchHelperFunctions.KeywordQueryMetrics(client, searchObject, keywordQuery, ConstantStrings.DocumentItemFilterCondition, SearchConstants.ManagedPropertyIsDocument, false); //// Create a list of managed properties which are required to be present in search results List <string> managedProperties = new List <string>(); managedProperties.Add(SearchConstants.ManagedPropertyFileName); managedProperties.Add(SearchConstants.ManagedPropertyTitle); managedProperties.Add(SearchConstants.ManagedPropertyCreated); managedProperties.Add(SearchConstants.ManagedPropertyUIVersionStringOWSTEXT); managedProperties.Add(SearchConstants.ManagedPropertyServerRelativeUrl); managedProperties.Add(SearchConstants.ManagedPropertyFileExtension); managedProperties.Add(SearchConstants.ManagedPropertyDocumentMatterId); managedProperties.Add(SearchConstants.ManagedPropertyDocumentLastModifiedTime); managedProperties.Add(SearchConstants.ManagedPropertySiteTitle); managedProperties.Add(SearchConstants.ManagedPropertyDocumentClientId); managedProperties.Add(SearchConstants.ManagedPropertyDocumentClientName); managedProperties.Add(SearchConstants.ManagedPropertyDocumentMatterName); managedProperties.Add(SearchConstants.ManagedPropertyDocumentId); managedProperties.Add(SearchConstants.ManagedPropertyCheckOutByUser); managedProperties.Add(SearchConstants.ManagedPropertySiteName); managedProperties.Add(SearchConstants.ManagedPropertySPWebUrl); managedProperties.Add(SearchConstants.ManagedPropertyDocumentVersion); managedProperties.Add(SearchConstants.ManagedPropertyDocumentCheckOutUser); managedProperties.Add(SearchConstants.ManagedPropertySPWebUrl); managedProperties.Add(SearchConstants.ManagedPropertyAuthor); //Filter on Result source to fetch only Matter Center specific results keywordQuery.SourceId = new Guid(SearchConstants.SearchResultSourceID); keywordQuery = SearchHelperFunctions.AssignKeywordQueryValues(keywordQuery, managedProperties); result = SearchHelperFunctions.FillResultData(clientContext, keywordQuery, searchObject, false, managedProperties); } } catch (Exception exception) { result = Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName); } } else { result = TextConstants.MessageNoInputs; } return(result); }