Filtering Documents

The Infinity Process Platform QueryService provides functionality to filter for DocumentQuery types, which can be used to search for documents.

For details on filtering Document Types, refer to section Searching for Document Types of chapter Managing Document Types.

Filtering on Document IDs

To define a filter on the document ID (ID) use the document Id as a predicate in a Document Query.

public static final FilterableAttribute ID = new Attribute("id");

Filtering on Document Names

To define a filter on the document name (NAME) use the document name as a predicate in a Document Query.

public static final FilterableAttribute NAME = new Attribute("name");

Filtering on Document Content Types

To define a filter on the document's content type (CONTENT_TYPE) use the document content type as a predicate in a Document Query.

public static final FilterableAttribute CONTENT_TYPE = new Attribute("contentType");

Example

The following example uses the DocumentQuery for finding documents with a specific content type by using the CONTENT_TYPE filter:

   private ServiceFactory sf = ServiceFactoryLocator.get("motu", "motu");

   private static final String CONTENT_TYPE1 = "text/plain";
   
   public void demoFindByContentType()
   {
      DocumentQuery query = DocumentQuery.findAll();
      query.where(DocumentQuery.CONTENT_TYPE.isEqual(CONTENT_TYPE1));

      Documents docs = sf.getQueryService().getAllDocuments(query);
   }

Filtering on Document Content

To define a filter on the document's content itself (CONTENT) use the document content as a predicate in a Document Query. Note note that only some document types (like plain text, PDF, Microsoft Office documents) support content indexing. Which document types are supported is implied by the concrete Document Management Service.

public static final FilterableAttribute CONTENT = new Attribute("content");

Filtering on Document Owners

To define a filter on the document's owner (OWNER) use the owner of the document as a predicate in a Document Query.

public static final FilterableAttribute OWNER = new Attribute("owner");

Filtering on Document Creation Date

To define a filter on the creation date of the document (DATE_CREATED) use this date as a predicate in a Document Query.

public static final FilterableAttribute DATE_CREATED = new Attribute("dateCreated");

Filtering on Last Modification Date of a Document

To define a filter on the last modification date of the document (DATE_LAST_MODIFIED) use this date as a predicate in a Document Query.

public static final FilterableAttribute DATE_LAST_MODIFIED = new Attribute(
         "dateLastModified");

Filtering on Document Meta Data Attributes

To define a filter on the meta-data attributes of the document (META_DATA) use the following method:

public static final MetadataFilterBuilder META_DATA = new MetadataFilterBuilder();

This method supports filters on any attribute (e.g. searching if there is any attribute containing a certain text fragment) or specific attributes (e.g. searching if there is an attribute with a given name, containing a certain text fragment).

Example with any attribute

In the following example, all documents containing any meta-data like a specified string are searched. Hereby the filter META_DATA is used.

   private ServiceFactory sf = ServiceFactoryLocator.get("motu", "motu");

   private static final String META_VALUE1 = "someMetaString";

   public void demoFindMetaDataAnyLike()
   {
      DocumentQuery query = DocumentQuery.findAll();

      query.where(DocumentQuery.META_DATA.any().like(META_VALUE1+"*"));
      
      Documents docs = sf.getQueryService().getAllDocuments(query);

   }

Example with a given name

In the following example, all documents containing meta-data with an attribute with a given name containing a text like a specified string are searched. Hereby the filter META_DATA is used.

   private ServiceFactory sf = ServiceFactoryLocator.get("motu", "motu");

   private static final String META_VALUE1 = "someMetaString";
   private static final String META_KEY1 = "name";

   public void demoFindMetaDataNamedStringLike()
   {
      DocumentQuery query = DocumentQuery.findAll();
      query.where(DocumentQuery.META_DATA.withName(META_KEY1).like(META_VALUE1+"*"));
      
      Documents docs = sf.getQueryService().getAllDocuments(query);
      printDocuments(docs);
      assertEquals("Documents", 1, docs.size());
   }

Finding all existing Documents

Use the method findAll() to create a query for finding all documents that currently exist.

   public static DocumentQuery findAll()
   {
      return new DocumentQuery();
   }