2

在我当前使用 Filenet P8 Content Platform Engine 5.2.1 和 WebSphere 8.5.5.3、Eclipse Mars 4.5.2 和 Apache Maven 3.3.1 的项目中

我正在尝试以编程方式在存储搜索中插入一些 where 条件属性值(从IBM 提供的这个示例开始),但我无法弄清楚添加它们的策略。以下是我使用的方法:

public void searchObjectsByStoredSearch(String storedSearchId, ObjectStore objectStore) {

        // Create a SearchScope instance. (Assumes you have the object store
        // object.)
        SearchScope search = new SearchScope(objectStore);

        // Get the StoredSearch object.
        StoredSearch ss = Factory.StoredSearch.fetchInstance(objectStore, new Id(storedSearchId), null);

        // Set the search parameters. Search template parameters only need to be
        // provided if the persisted stored search needs to be modified at
        // runtime.
        SearchTemplateParameters searchParams = new SearchTemplateParameters();
        searchParams.setContent(null);
        searchParams.setMaximumRecords(50);

        SearchTemplateWhereProperty whereProp = new SearchTemplateWhereProperty();
        whereProp.setLiteral("application/pdf");
        whereProp.setItemId("35");
        ArrayList alWhereProps = new ArrayList();
        alWhereProps.add(whereProp);
        searchParams.setWhereProperties(alWhereProps);

        SearchTemplateSelectProperty selectProp = new SearchTemplateSelectProperty();
        selectProp.setSymbolicName("DocumentTitle");
        selectProp.setItemId("1");
        selectProp.setSortLevel(0);
        selectProp.setSortOrder(SortOrder.DESCENDING);
        ArrayList alSelectProps = new ArrayList();
        alSelectProps.add(selectProp);
        searchParams.setSelectProperties(alSelectProps);

        // Set the page size (Long) to use for a page of query result data. This
        // value is passed
        // in the pageSize parameter. If null, this defaults to the value of
        // ServerCacheConfiguration.QueryPageDefaultSize.
        Integer myPageSize = new Integer(100);

        // Specify a property filter to use for the filter parameter, if needed.
        // This can be null if you are not filtering properties.
        PropertyFilter myFilter = new PropertyFilter();
        myFilter.setMaxRecursion(1);
        myFilter.addIncludeType(new FilterElement(null, null, null, FilteredPropertyType.SINGLETON_STRING, null));

        // Set the (Boolean) value for the continuable parameter. This indicates
        // whether to iterate requests for subsequent pages of result data when
        // the end of the
        // first page of results is reached. If null or false, only a single
        // page of results is
        // returned.
        Boolean continuable = Boolean.TRUE;

        // Execute the fetchObjects method using the specified parameters.
        IndependentObjectSet myObjects = search.fetchObjects(ss, "document", searchParams, myPageSize, myFilter,
                continuable);

        // You can then iterate through the collection of objects to access the
        // properties.
        Iterator iterObjects = myObjects.iterator();
        int cont = 0;
        while (iterObjects.hasNext()) {
            cont++;
            logger.info("Documento " + cont);
            logger.info("-------------------");
            IndependentObject object = (IndependentObject) iterObjects.next();
            Properties props = object.getProperties();
            Iterator iterProps = props.iterator();
            while (iterProps.hasNext()) {
                Property prop = (Property) iterProps.next();
                logger.info("Proprieta': " + prop.getPropertyName());
                if (prop.getObjectValue() != null)
                    logger.info("  Valore: " + prop.getObjectValue().toString());

                if (prop.getPropertyName().equalsIgnoreCase("FoldersFiledIn")) {
                    if (prop.getObjectValue() != null) {
                        FolderSet fs = (FolderSet) prop.getIndependentObjectSetValue();
                        Iterator iterFs = fs.iterator();
                        while (iterFs.hasNext()) {
                            Folder folder = (Folder) iterFs.next();
                            logger.info("\r\tFolder Name: " + folder.get_FolderName() + "   Folder Path: "
                                    + folder.get_PathName());
                        }
                    }
                }
            }
        }
        logger.info(" Documenti trovati:" + cont);

    }

我希望您专注于 SearchTemplateWhere 属性片段:

SearchTemplateWhereProperty whereProp = new SearchTemplateWhereProperty();
whereProp.setLiteral("application/pdf");
whereProp.setItemId("35");
ArrayList alWhereProps = new ArrayList();
alWhereProps.add(whereProp);
searchParams.setWhereProperties(alWhereProps);

似乎对于存储搜索,您无法定义自定义 SQL 语句,但您只能引用现有属性,为它们提供适当的值。

据我所知,存储搜索中的每个属性都有自己的 Id,我可以使用的唯一方法是设置值 (setLiteral) 和设置属性的 Id。

我尝试了一些 Id 值,但我得到了这个错误:

com.filenet.api.exception.EngineRuntimeException: FNRCA0109E: RETRIEVE_SEARCH_REQUIRED_MERGE_DATA_NOT_PRESENT:用于执行存储搜索的 SearchScope 方法的 templateData 参数无效。SearchTemplateParameters 实例在 SearchTemplateWhereProperty 对象中不包含所需的值 itemId。

我的问题是:我如何(以编程方式)找到存储搜索的属性 ID 以便给它们一个值?

编辑:在另一个问答网站上,我得到了查看存储搜索的 Content Element 属性的建议,该属性包含其 XML 定义,其中包含您可以找到这些 ItemID 的各种项目。如何以编程方式从此内容元素中获取这些 ItemId 属性?

4

0 回答 0