SearchScope 搜索文档

来源:互联网 发布:淘宝联盟官网 编辑:程序博客网 时间:2024/06/06 20:18

文档搜索时FileNet的一个重要功能。有这个功能让客户更加清晰的查看操作过得文档。此文是利用SearchScope进行搜索

 

查看FileNet的API文档关于SearchScope的介绍如下:

public final class SearchScope
extends java.lang.Object

Determines which repository or repositories are to be searched, and supplies methods to execute searches for properties, objects, and class metadata (class descriptions).

When multiple repositories are to be searched, use the SearchScope(ObjectStore[], MergeMode) constructor to specify whether the scope is the union or intersection of the object stores.

 

决定从一个存储或者多个存储中查询,并提供方法来执行搜索属性、对象和类的元数据(类描述)。
当多个存储库搜索,使用SearchScope(ObjectStore[],MergeMode)构造函数指定范围是否工会或相交的对象存储。

可以看到SearchScope是提供文档查询的一个Class,下面是代码示例

package CEJavaAPIEDU.Search;import java.util.Iterator;import CEJavaAPIEDU.CEConnectionEDU;import CEJavaAPIEDU.Configurations;import com.filenet.api.collection.DocumentSet;import com.filenet.api.collection.RepositoryRowSet;import com.filenet.api.constants.MergeMode;import com.filenet.api.core.*;import com.filenet.api.property.FilterElement;import com.filenet.api.property.PropertyFilter;import com.filenet.api.query.RepositoryRow;import com.filenet.api.query.SearchSQL;import com.filenet.api.query.SearchScope;public class ContentSearchEDU extends CEConnectionEDU {/** * @param args */public void testContentSearchEDU(ObjectStore os, String keyWord){    SearchScope search = new SearchScope(os);              //通过sql语句查询相应的数据       String mySQLString = "SELECT DocumentTitle, Name FROM Document d "    +"INNER JOIN VerityContentSearch v ON v.QueriedObject = d.This "    +"WHERE d.IsCurrentVersion = TRUE AND CONTAINS(d.*,'" + keyWord + "')";        SearchSQL sql = new SearchSQL(mySQLString);    DocumentSet documents = (DocumentSet) search.fetchObjects(sql,Integer.getInteger("50"),null, Boolean.valueOf(true));             com.filenet.api.core.Document doc;    Iterator it = documents.iterator();    while (it.hasNext())    {    doc = (Document)it.next();    System.out.println("document="+ doc.get_Name());    }}public static void main(String[] args) {// TODO Auto-generated method stubtry     {   ContentSearchEDU myInstance = new ContentSearchEDU();//与上一篇博文建立CE连接有关       Connection conn = myInstance.getCEConnectionEDU();  //获取连接       Domain domain = myInstance.getDomainEDU(conn); //取得域       ObjectStore store = myInstance.getObjectStoreEDU(domain, Configurations.DefalutOS1);       myInstance.testContentSearchEDU(store,"test");       System.out.println("Done");     }    catch (Exception e) {      e.printStackTrace();     }}}

fetchObjects(SearchSQL searchSQL, java.lang.Integer pageSize, PropertyFilter filter, java.lang.Boolean continuable)
Retrieves EngineObject objects from the repository or repositories specified for this instance.

searchSQL 可以理解为查询条件

pageSize也比较简单,就是查询出的记录数。

这个方法也比较简单通过查询相应的API可以迅速的使用,


下面把该方法的介绍和注意事项贴到下面,感兴趣的可以看一下,不过都是英文的

public IndependentObjectSet fetchObjects(SearchSQL searchSQL,                                         java.lang.Integer pageSize,                                         PropertyFilter filter,                                         java.lang.Boolean continuable)
Retrieves EngineObject objects from the repository or repositories specified for this instance.

The following property settings can affect this method:

  • ObjectStore.DefaultQueryTimeLimit
  • ObjectStore.MaxQueryTimeLimit
  • ServerCacheCofiguration.QueryPageMaxSize
  • ServerCacheCofiguration.QueryPageDefaultSize
  • ServerCacheCofiguration.NonPagedQueryMaxSize

You can optionally include a filter to control which properties to return with the object. If you pass innull for the filter parameter, this method returns values for all non-object properties and returns placeholders for all object-valued properties. For more information, see the description of thefilter parameter.

Parameters:
searchSQL - ASearchSQL instance containing the SQL statement to use for the search.
pageSize - An integer indicating the maximum number of objects per page to retrieve. This can benull. When unspecified, the default page size (ServerCacheCofiguration.QueryPageDefaultSize) is used.

Note: If thecontinuable parameter is false or null, thispageSize value is ignored.

The number you specify here determines what constitutes a page of query result data. This value, in conjunction with the (Boolean) value you specify for the continuable parameter, can impact retrieval performance.

filter - APropertyFilter object that represents information for controlling which property values (and with what level of detail and recursion) to return. Ifnull, this method returns values for all non-object properties and returns placeholders for all object-valued properties (PropertyEngineObject properties with a state ofPropertyState.UNEVALUATED or PropertyState.REFERENCE); any subsequent attempts to access an object-valued property will cause an automatic round-trip to the server to fetch its value.

The selection list in thesearchSQL parameter determines which top-level properties are returned. The property filter specified here determines the subproperties: the properties returned for the applicable top-level properties. For example, if a top-level property specified in the selection list (searchSQL parameter) is of type Object, the filter parameter will determine which properties are returned in that object.

continuable - ABoolean value. If false or null, the query is not paged, thepageSize parameter and the default page size in ServerCacheCofiguration.QueryPageDefaultSize are ignored, and the query will return a number of objects limited by the following values:
  • The "TOP" value (if specified) in the selection list.
  • The value of ServerCacheCofiguration.NonPagedQueryMaxSize.

If this continuable value istrue, the query can be continued. In this case, when the end of the first page is reached, a request for the next page ofEngineObject objects is issued. Page requests iterate until all of theEngineObject objects satisfying the query are retrieved.

Queries using continuation use ORDER BY in their implementation. If an ORDER BY clause is not specified in the SQL statement (thesearchSQL parameter), an ORDER BY Id clause is used. If an ORDER BY clause is specified in the SQL statement, but does not contain the Id property, the Id property (having a unique value) is appended to the end of the ORDER BY clause. You should to what extent adding the Id property to the ORDER BY clause increases resource consumption for your application. Do not use a continuable query if it would cause a severe performance reduction.

Returns:
An IndependentObjectSet collection object containing theEngineObject objects retrieved.
See Also:
SQL Syntax Reference

有了API查询还是比较简单的,不过如果负责的查询SQL语句还是关键的。sql语句是基础,把基础掌握好,其他的还是比较简单的,比如上面的方法如果会写sql语句,上面的API有了相应的介绍使用起来就很简单了。千万不要忽略基础的东西。