Esempio n. 1
0
        //public IEnumerable<DocumentModel> SimplePassthroughQueryDocumentWithPath(string filename, string subject)
        //{

        //    List<DocumentModel> documentModels = new List<DocumentModel>();
        //    QueryResult queryResult;
        //    try
        //    {
        //        string queryString = "select dm_document.r_object_id, dm_document.subject, dm_document.a_content_type,dm_document.object_name,dm_format.dos_extension from dm_document,dm_format where  dm_document.a_content_type = dm_format.name";

        //        if ((!String.IsNullOrEmpty(filename)) && (!String.IsNullOrEmpty(subject)))
        //        {
        //            queryString = queryString + " and upper(object_name) like '%" + filename.ToUpper() + "%' and upper(subject) like '%" + subject.ToUpper() + "%'";
        //        }
        //        if ((!String.IsNullOrEmpty(filename)) && (String.IsNullOrEmpty(subject)))
        //        {
        //            queryString = queryString + " and upper(object_name) like '%" + filename.ToUpper() + "%'";
        //        }
        //        if ((String.IsNullOrEmpty(filename)) && (!String.IsNullOrEmpty(subject)))
        //        {
        //            queryString = queryString + " and upper(subject) like '%" + subject.ToUpper() + "%'";
        //        }
        //        int startingIndex = 0;
        //        int maxResults = 60;
        //        int maxResultsPerSource = 20;

        //        PassthroughQuery q = new PassthroughQuery();
        //        q.QueryString = queryString;
        //        q.AddRepository(DefaultRepository);

        //        QueryExecution queryExec = new QueryExecution(startingIndex,
        //                                                      maxResults,
        //                                                      maxResultsPerSource);
        //        queryExec.CacheStrategyType = CacheStrategyType.NO_CACHE_STRATEGY;

        //        queryResult = searchService.Execute(q, queryExec, null);

        //        QueryStatus queryStatus = queryResult.QueryStatus;
        //        RepositoryStatusInfo repStatusInfo = queryStatus.RepositoryStatusInfos[0];
        //        if (repStatusInfo.Status == Status.FAILURE)
        //        {
        //            //  Console.WriteLine(repStatusInfo.ErrorTrace);
        //            documentModels.Add(new DocumentModel() { ObjectId = "0", ObjectName = repStatusInfo.ErrorMessage, Subject = repStatusInfo.ErrorTrace });
        //        }
        //        //Console.WriteLine("Query returned result successfully.");
        //        DataPackage dp = queryResult.DataPackage;
        //        //Console.WriteLine("DataPackage contains " + dp.DataObjects.Count + " objects.");
        //        foreach (DataObject dObj in dp.DataObjects)
        //        {
        //            PropertySet docProperties = dObj.Properties;
        //            String objectId = dObj.Identity.GetValueAsString();
        //            String docName = docProperties.Get("object_name").GetValueAsString();
        //            String Extension = docProperties.Get("dos_extension").GetValueAsString();
        //            string repName = dObj.Identity.RepositoryName;
        //            string docsubject = docProperties.Get("subject").GetValueAsString();
        //            //Console.WriteLine("RepositoryName: " + repName + " ,Document: " + objectId + " ,Name:" + docName + " ,Subject:" + docsubject);

        //            documentModels.Add(new DocumentModel() { ObjectId = objectId, ObjectName = docName+"."+Extension , Subject = docsubject });

        //        }
        //    }
        //    catch (Exception ex)
        //    {

        //        documentModels.Add(new DocumentModel() { ObjectId = "1", ObjectName = "SampleFile.txt", Subject = "This is a Sample" });
        //    }

        //    return documentModels;
        //}
        public void SimpleStructuredQuery(String docName)
        {
            String repoName = DefaultRepository;

            Console.WriteLine("Called SimpleStructuredQuery - " + DefaultRepository);
            PropertyProfile propertyProfile = new PropertyProfile();

            propertyProfile.FilterMode = PropertyFilterMode.IMPLIED;
            OperationOptions operationOptions = new OperationOptions();

            operationOptions.Profiles.Add(propertyProfile);

            // Create query
            StructuredQuery q = new StructuredQuery();

            q.AddRepository(repoName);
            q.ObjectType       = "dm_document";
            q.IsIncludeHidden  = true;
            q.IsDatabaseSearch = true;
            ExpressionSet expressionSet = new ExpressionSet();

            expressionSet.AddExpression(new PropertyExpression("object_name",
                                                               Condition.CONTAINS,
                                                               docName));
            q.RootExpressionSet = expressionSet;

            // Execute Query
            int            startingIndex       = 0;
            int            maxResults          = 60;
            int            maxResultsPerSource = 20;
            QueryExecution queryExec           = new QueryExecution(startingIndex,
                                                                    maxResults,
                                                                    maxResultsPerSource);
            QueryResult queryResult = searchService.Execute(q, queryExec, operationOptions);

            QueryStatus          queryStatus   = queryResult.QueryStatus;
            RepositoryStatusInfo repStatusInfo = queryStatus.RepositoryStatusInfos[0];

            if (repStatusInfo.Status == Status.FAILURE)
            {
                Console.WriteLine(repStatusInfo.ErrorTrace);
                throw new Exception("Query failed to return result.");
            }
            Console.WriteLine("Query returned result successfully.");

            // print results
            Console.WriteLine("DataPackage contains " + queryResult.DataObjects.Count + " objects.");
            foreach (DataObject dataObject in queryResult.DataObjects)
            {
                Console.WriteLine(dataObject.Identity.GetValueAsString());
            }
        }
        public void SimpleStructuredQuery(String docName)
        {
            String repoName = DefaultRepository;

            PropertyProfile propertyProfile = new PropertyProfile();
            propertyProfile.FilterMode = PropertyFilterMode.IMPLIED;
            OperationOptions operationOptions = new OperationOptions();
            operationOptions.Profiles.Add(propertyProfile);

            // Create query
            StructuredQuery q = new StructuredQuery();
            q.AddRepository(repoName);
            q.ObjectType = "dm_document";
            q.IsIncludeHidden = true;
            q.IsDatabaseSearch = true;
            ExpressionSet expressionSet = new ExpressionSet();
            expressionSet.AddExpression(new PropertyExpression("object_name",
                                                               Condition.CONTAINS,
                                                               docName));
            q.RootExpressionSet = expressionSet;

            // Execute Query
            int startingIndex = 0;
            int maxResults = 60;
            int maxResultsPerSource = 20;
            QueryExecution queryExec = new QueryExecution(startingIndex,
                                                          maxResults,
                                                          maxResultsPerSource);
            QueryResult queryResult = searchService.Execute(q, queryExec, operationOptions);

            QueryStatus queryStatus = queryResult.QueryStatus;
            RepositoryStatusInfo repStatusInfo = queryStatus.RepositoryStatusInfos[0];
            if (repStatusInfo.Status == Status.FAILURE)
            {
                Console.WriteLine(repStatusInfo.ErrorTrace);
                throw new Exception("Query failed to return result.");
            }
            Console.WriteLine("Query returned result successfully.");

            // print results
            Console.WriteLine("DataPackage contains " + queryResult.DataObjects.Count + " objects.");
            foreach (DataObject dataObject in queryResult.DataObjects)
            {
                Console.WriteLine(dataObject.Identity.GetValueAsString());
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Ricerca fulltext nell'oggetto document
        ///
        /// nb: da fare anche ricerca allegati
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public ArrayList FullTextSearch(ref FullTextSearchContext context)
        {
            ArrayList result = new ArrayList();

            try
            {
                List <string> fullTextResult = null;

                if (context.SearchResultList != null && context.SearchResultList.Length > 0)
                {
                    // Ricerca già effettuata, reperimento dall'oggetto di contesto
                    // dei risultati precedenti evitando così una dispendiosa
                    // chiamata al sistema documentale
                    fullTextResult = new List <string>(context.SearchResultList);
                }
                else
                {
                    StructuredQuery strQuery = new StructuredQuery();

                    strQuery.AddRepository(DctmConfigurations.GetRepositoryName());
                    strQuery.ObjectType = ObjectTypes.DOCUMENTO;

                    strQuery.IsDatabaseSearch     = false;
                    strQuery.IsIncludeAllVersions = false;
                    strQuery.IsIncludeHidden      = false;

                    // Inserisce nella ricerca il solo cabinet dell'amministrazione
                    RepositoryScope repositoryScope = new RepositoryScope();
                    repositoryScope.RepositoryName = DctmConfigurations.GetRepositoryName();
                    repositoryScope.LocationPath   = DocsPaAdminCabinet.getRootAmministrazione(this.InfoUtente);
                    repositoryScope.IsDescend      = true;
                    strQuery.Scopes.Add(repositoryScope);

                    ExpressionSet set = new ExpressionSet();
                    set.AddExpression(new FullTextExpression(context.TextToSearch));
                    strQuery.RootExpressionSet = set;

                    // Query execution
                    int            startIndex = (context.RequestedPageNumber * PAGE_SIZE) - PAGE_SIZE;
                    int            maxResults = this.GetMaxRowCount();
                    QueryExecution queryExec  = new QueryExecution(startIndex, maxResults, maxResults);

                    ISearchService searchService = DctmServiceFactory.GetServiceInstance <ISearchService>(this.InfoUtente.dst);
                    QueryResult    queryResult   = searchService.Execute(strQuery, queryExec, null);

                    QueryStatus          queryStatus   = queryResult.QueryStatus;
                    RepositoryStatusInfo repStatusInfo = queryResult.QueryStatus.RepositoryStatusInfos[0];

                    if (repStatusInfo.Status == Status.FAILURE)
                    {
                        throw new ApplicationException("QueryResult: Status.FAILURE");
                    }

                    fullTextResult = new List <string>();

                    foreach (DataObject dataObject in queryResult.DataObjects)
                    {
                        // Reperimento docnumber
                        string docNumber = dataObject.Properties.Get(TypeDocumento.DOC_NUMBER).GetValueAsString();

                        if (!fullTextResult.Contains(docNumber)) // Eliminazione dei risultati duplicati
                        {
                            fullTextResult.Add(docNumber);
                        }
                    }

                    context.SearchResultList = fullTextResult.ToArray();
                    context.TotalPageNumber  = (fullTextResult.Count / PAGE_SIZE);
                    context.TotalRecordCount = fullTextResult.Count;
                }

                // Paginazione dei risultati
                if (fullTextResult != null && fullTextResult.Count > 0)
                {
                    int startIndex = (context.RequestedPageNumber * PAGE_SIZE) - PAGE_SIZE;
                    int count      = PAGE_SIZE;
                    if (fullTextResult.Count < count)
                    {
                        count = fullTextResult.Count;
                    }
                    List <string> pageContent = fullTextResult.GetRange(startIndex, count);
                    result = this.GetDocuments(pageContent.ToArray(), InfoUtente);
                }
            }
            catch (Exception ex)
            {
                result.Clear();
                logger.Debug(string.Format("Errore in Documentum.FullTextSearch:\n{0}", ex.ToString()));
            }

            return(result);
        }
Esempio n. 4
0
        public IList<DataObject> FindDataObjects(string objectType, List<PropertyExpression> searchCriteria, bool getContent)
        {
            Log.Verbose("DataObjectRepository FindDataObjects criteria {@searchCriteria}", searchCriteria);

            var propertyProfile = new PropertyProfile {FilterMode = PropertyFilterMode.IMPLIED};
            var operationOptions = new OperationOptions();
            operationOptions.Profiles.Add(propertyProfile);

            // Create query
            var query = new StructuredQuery();
            query.AddRepository(dfsConfiguration.Repository);
            query.ObjectType = objectType;
            query.IsIncludeHidden = true;
            query.IsDatabaseSearch = true;

            if (searchCriteria != null && searchCriteria.Count > 0)
            {
                query.RootExpressionSet = new ExpressionSet();
                foreach (var expression in searchCriteria)
                {
                    query.RootExpressionSet.AddExpression(expression);
                }
            }

            // Execute Query 
            const int StartingIndex = 0;
            int maxResults = dfsConfiguration.MaxQueryResults;
            var queryExec = new QueryExecution(StartingIndex, maxResults, maxResults);
            var queryResult = dfsContext.SearchService.Execute(query, queryExec, operationOptions);

            var queryStatus = queryResult.QueryStatus;
            var repStatusInfo = queryStatus.RepositoryStatusInfos[0];
            if (repStatusInfo.Status == Status.FAILURE)
            {
                Log.Debug("FindDataObjects failed {@searchCriteria}", searchCriteria);
                return null;
            }

            Log.Debug("FindDataObjects found {0} objects", queryResult.DataObjects.Count);

            //TODO see if there is a better way to get the contents from a search
            return queryResult.DataObjects
                .Select(dataObject => getContent 
                    ? GetDataObjectWithContentsObjectId(dataObject.Identity.GetValueAsString()) 
                    : GetDataObjectByObjectId(dataObject.Identity.GetValueAsString()))
                .ToList();
        }