/// <summary> /// Check and return the flat for the optimization state regarding the index used by /// </summary> /// <returns></returns> public DataResult <bool> IsIndexOptimized() { var result = new DataResult <bool>(); try { var path = GetLuceneIndexLocation(); var luceneResult = _luceneIndexService.IsIndexedOptimized(path); if (luceneResult.GetStatus() == LuceneIndexingStatus.Success) { result.SetSuccess("Retrieved index optimization state"); result.SetData(luceneResult.ResponseObject); } else { result.SetFailiure("Could not get lucene index optimization status"); } } catch (Exception ex) { result.SetException(ex, "Exception while checking index optimize status"); } return(result); }
/// <summary> /// Query the index used by the DSS Services for the number of indexed documents /// </summary> /// <returns>Data Result wrapping the number of indexed documents</returns> public DataResult <int> GetNumberOfIndexedDocuments() { var result = new DataResult <int>(); try { var directoryPaty = GetLuceneIndexLocation(); var luceneResult = _luceneIndexService.GetDocumentsNumber(directoryPaty); if (luceneResult.GetStatus() == LuceneIndexingStatus.Success) { result.SetSuccess("Succeeded in retrieving the lucene documents number"); result.SetData(luceneResult.ResponseObject); } else { result.SetFailiure("Failed to retrieve lucene index documents number"); } } catch (Exception ex) { result.SetException(ex, "Exception while checking the number of indexed documents"); } return(result); }
/// <summary> /// Update the information for a given document stored in the syste. /// </summary> /// <param name="documentData">The updated document information</param> /// <returns>Data Result containing the updated document information.</returns> public DataResult <Document> UpdateDocument(Document documentData) { var result = new DataResult <Document>(); try { var document = _documentRepository.Update(documentData); result.SetSuccess("Successfully updated document data"); result.SetData(document); } catch (Exception ex) { result.SetException(ex, "Exceptin occured while updating document information"); result.SetException(ex, "Exceptin occured while updating document information"); } return(result); }
/// <summary> /// Toggle the document state in the search index. /// </summary> /// <param name="documentId"> </param> /// <returns>Base result containing the results of the operation</returns> public DataResult <IndexedDocument> AddDocumentToIndex(Guid documentId) { var result = new DataResult <IndexedDocument>(); try { // use the repository to extarct the document for an uploaded document var document = _documentsRepository.Read(documentId); // create a lucene document from the given document var luceneDocument = GetLuceneDocumentFromDocument(document, true); // if there is no such document if (document == null) { result.SetFailiure("There is no document with the selected document id"); return(result); } // check if the document is already indexed if (document.IsIndexed) { result.SetSuccess("Document with the selected id is already indexed"); result.SetData(luceneDocument); return(result); } var luceneIndexLocation = GetLuceneIndexLocation(); // add it to the index var addToIndexResult = _luceneIndexService.AddToIndex(luceneIndexLocation, luceneDocument); if (addToIndexResult.GetStatus() == LuceneIndexingStatus.Success) { SetDocumentIndexStatus(document, true); // set success properties on the result result.SetSuccess("Successs in adding the document to the lucene index"); result.SetData(luceneDocument); } else { result.SetFailiure("Failed to add document to index"); } } catch (Exception ex) { result.SetException(ex, "Exception while adding document to the lucene index"); } return(result); }
/// <summary> /// For a given search request for a gien Document Search View Model returns a collection of /// Documents. /// /// If the skip parameter is provided it means we are using the same filter properties as the last /// request and only need to return additional documents. /// </summary> /// <param name="searchFilterModel"></param> /// <returns></returns> public DataResult <IList <Document> > ProcessSearchRequest(DocumentSearchFilterModel searchFilterModel) { var result = new DataResult <IList <Document> >(); try { var profiler = MiniProfiler.Current; IQueryable <Document> documentQuery; using (profiler.Step("Search Documents: Getting base query")) { documentQuery = _documentRepository.ReadAllAsQueryable(); } using (profiler.Step("Search Documents: Filtering")) { // do filtering documentQuery = DoFiltering(searchFilterModel, documentQuery); } using (profiler.Step("Search Documents: Ordering")) { // ordering documentQuery = documentQuery.OrderBy(ent => ent.Title); } using (profiler.Step("Search Documents: Paging")) { // skip and take documentQuery = documentQuery.Skip(searchFilterModel.Skip).Take(searchFilterModel.Take); } List <Document> documentList; using (profiler.Step("Search Documents: To List")) { // Set the result as success and set the data documentList = documentQuery.ToList(); } result.SetData(documentList); result.SetSuccess(); } catch (Exception ex) { result.SetException(ex, "Error when searching Documents"); } return(result); }
/// <summary> /// Remove a document from the Lucene indexing, making it unavaiable for searching of general user /// downloading /// </summary> /// <param name="documentId">The id of the document to be removed from the index</param> /// <returns>Data result containing document objet that was just removed from the index</returns> public DataResult <IndexedDocument> RemoveDocumentFromIndex(Guid documentId) { var result = new DataResult <IndexedDocument>(); try { var document = _documentsRepository.Read(documentId); var luceneDocument = GetLuceneDocumentFromDocument(document); if (document == null) { result.SetFailiure("There is no document with the given document id to remove from the index"); return(result); } if (!document.IsIndexed) { result.SetSuccess("Document is already removed from the index"); result.SetData(luceneDocument); return(result); } var lucenePath = GetLuceneIndexLocation(); // try and remove the document from the index var removalResult = _luceneIndexService.RemoveFromIndex(lucenePath, luceneDocument, true); if (removalResult.GetStatus() == LuceneIndexingStatus.Success) { SetDocumentIndexStatus(document, false); result.SetSuccess("Document Successfully removed from index"); result.SetData(luceneDocument); } else { result.SetFailiure("Failed to remove document from index"); } return(result); } catch (Exception ex) { result.SetException(ex, "Exception while trying to remove document from index"); return(result); } }
public DataResult <IList <Keyword> > GetAllKeywords() { var result = new DataResult <IList <Keyword> >(); try { var keywords = _keywordRepository.ReadAll().ToList(); result.SetSuccess("Successfully read all keywords"); result.SetData(keywords); } catch (Exception ex) { result.SetException(ex, "Exception when retrieving all the keywords"); } return(result); }
/// <summary> /// Return a DSS user for the given username. /// </summary> /// <param name="username">The username of the DSS user</param> /// <returns></returns> public DataResult <User> GetUserForUsername(string username) { var result = new DataResult <User>(); try { var userData = _userRepository.ReadAllAsQueryable().FirstOrDefault(x => x.Username == username); result.SetData(userData); result.SetSuccess("Retrieved userdata for the given username"); } catch (Exception ex) { result.SetException(ex, "Exception while trying to get DSS User for username"); } return(result); }
/// <summary> /// Returns a list of all the categories wrapped in a data result object. /// </summary> /// <returns><see cref="DataResult{T}"/> object wrapping the list of categories</returns> public DataResult <IList <Category> > GetAllCategories() { var result = new DataResult <IList <Category> >(); try { // get all the categories from the repository var allCategories = _categoryRepository.ReadAll().ToList(); result.SetSuccess("Success in retrieving all the categories"); result.SetData(allCategories); } catch (Exception ex) { result.SetException(ex, "Exception when retrieving all categories"); } return(result); }
/// <summary> /// Authenticate user credential information, the username and password, and return an authenticated user object /// </summary> /// <param name="username">The Users, username property used to distuingshi</param> /// <param name="password">The Users, password property used to authenticate users in the system</param> /// <returns></returns> public DataResult <User> AuthenticateUser(string username, string password) { var result = new DataResult <User>(); try { var usersForCredentials = _userRepository.GetUsersForCredentials(username, password); if (usersForCredentials.Count == 0) { result.SetFailiure("User Authentication failed. No user found."); } else if (usersForCredentials.Count > 1) { result.SetFailiure("User Authentication failed. More than one user found for given credentials"); } else { var user = usersForCredentials.FirstOrDefault(); if (user == null) { result.SetFailiure("First user result is null"); } else { result.SetSuccess("Retrieved user information"); result.SetData(user); } } } catch (Exception ex) { result.SetException(ex, "Exception while authenticating user"); } return(result); }