ContentObject

ContentObject["string"]

gives a content object whose content is string.

ContentObject[File[]]

gives a content object whose content is stored in the specified file.

ContentObject["name1"val1,"name2"val2,]

gives a content object with a sequence of fields with names namei and values vali.

Details

  • Properties of content objects can be obtained using ContentObject[]["property"].
  • Possible properties can include:
  • "CreationDate"creation date for file or content object
    "FileByteCount"size of the content of the object on disk, in bytes
    "FileExtension"the file extension, e.g. ".txt"
    "FileName"original file name, excluding directory
    "FileSize"size as a Quantity object
    "Location"location of the original source as a string
    "ModificationDate"modification date for file or content object
    "Plaintext"content converted to a string
    "ReferenceLocation"cloud-accessible URL to use to reference this content
    "Score"score assigned to the content object in a search
    "Snippet"snippet of the content
    "SnippetSource"cloud-accessible document path for producing snippets
  • Some properties, such as "Snippet", are typically only computed when requested.
  • When a content object is created from a file, the "Plaintext" property will typically be computed by first importing the file.
  • ContentObject[] can be used in the input to CreateSearchIndex.

Examples

Basic Examples  (3)

TextSearch with "ContentObject" as third argument returns a list of content objects:

In[1]:=
Click for copyable input
Out[1]=

Get the file name of the first result:

In[2]:=
Click for copyable input
Out[2]=

Create an object containing some text:

In[1]:=
Click for copyable input
Out[1]=

Get only a snippet of the text:

In[2]:=
Click for copyable input
Out[2]=

It is also possible to use the Snippet function:

In[3]:=
Click for copyable input
Out[3]=

Get properties of the file:

In[4]:=
Click for copyable input
Out[4]=
In[5]:=
Click for copyable input
Out[5]=
In[6]:=
Click for copyable input
Out[6]=
In[7]:=
Click for copyable input
Out[7]=

A ContentObject can contain a string:

In[1]:=
Click for copyable input
Out[1]=

ContentObject contains metadata:

In[2]:=
Click for copyable input
Out[2]//InputForm=

"Location" and "FileName" are not available if the document is not saved on disk:

In[3]:=
Click for copyable input
Out[3]=
In[4]:=
Click for copyable input
Out[4]=

See Also

TextSearch  Snippet  File  URL  NotebookObject  ContentFieldOptions  ContentLocationFunction  ResourceObject

Introduced in 2015
(10.2)