Acrobat Search Plug-in¶
This chapter describes IAC support for the Acrobat Search plug-in, which allows users to perform text searches in PDF documents. It adds menus, menu items, toolbar buttons, and a Search panel to the Acrobat application. The Search plug-in exports a host function table (HFT) containing several methods that can be used by other Plugins.
Search supports interapplication communication in the form of DDE messages in Windows and Apple events in Mac OS. These messages and events allow remote clients to submit search queries and manipulate a list of indexes (the list of indexes is referred to as the shelf).
For more information, see the PDF Library documentation.
Search plug-in using DDE¶
A client can connect to the Search plug-in with DDE using the service name "Acrobat Search"
and the topic name "Acrobat Search"
.
DdeInitialize(&id, &DDE_ProcessMessage, APPCMD_CLIENTONLY, 0);
hszServerName = DdeCreateStringHandle(id, "Acrobat Search", 0);
hszTopicName = DdeCreateStringHandle(id, "Acrobat Search", 0);
hConv = DdeConnect(id, hszServerName, hszTopicName, NULL);
After a connection has been made, a single poke transaction will submit a search query. Two types of queries are supported: simple query and query.
Simple query item¶
A simple query has the item name “SimpleQuery"
. When using a simple query, pass only a string that contains the query, using the ASQL query parser’s format (see QLangType_CQL
in the table Query language type constants). It is not possible to choose another parser or to set word options using the simple query item.
Query item¶
A query has the item name “Query
“. When using query, a QueryData
structure is used. This structure contains the query, as well as specifying the query parser to use and additional options.
hszItemName = DdeCreateStringHandle(id, "Query", 0);
DdeClientTransaction(qd, nLen, hConv, hszItemName, CF_TEXT, XTYP_POKE,
1000, &dwResult);
DdeDisconnect(hConv)
The global data handle (qd
) passed to the server must be in the following format:
typedef struct _QueryData {
eQLangType qlt;
boolean bOverrideWordOptions;
uns32 nWordOptions;
uns16 nMaxDocs;
uns16 nQueryOffset;
uns16 nNumSorts; //deprecated in Acrobat 6.0
uns16 nSortOffset[QP_MAX_SORT_FIELDS]; //deprecated in Acrobat 6.0
boolean bSortWays[QP_MAX_SORT_FIELDS]; //deprecated in Acrobat 6.0
unsigned char cData[1];
} QueryData;
Query options¶
Parameter |
Description |
---|---|
qlt |
The query language type. Must be one of the values shown in Query language type constants. |
bOverrideWordOptions |
Indicates that the client wishes to use different word options than those currently set by the user. |
nWordOptions |
The word options. Must be an |
nMaxDocs |
If non-zero, the client wishes to use a different limit for the maximum number of documents than the limit currently set by the user. |
nSortOffsets |
A list of offsets into the |
nQueryOffset |
An offset into the |
nNumSorts |
The number of fields in the sort spec. If this number is |
bSortWays |
A list of sort order flags, one for each sort field. |
Query language type constants¶
Parameter |
Description |
---|---|
QLangType_Simple |
Allows only simple phrase searches; does not allow Boolean searching. This query type does not work in the DDE interface of the Search plug-in shipped with version 2.0 of Acrobat. |
QLangType_CQL |
Allows Boolean searches using |
QLangType_Passthrough |
The Verity BooleanPlus query language. Contact Verity for further information on this language. |
Word option bit-flag constants¶
Parameter |
Description |
---|---|
QPON_Case |
The search is case-sensitive. |
QPON_Stemming |
Find not only the specified word, but other words that have the same stem. For example, run and ran have the same stem. |
QPON_SoundsLike |
Find not only the specified word, but other words that sound like it. |
QPON_Thesaurus |
Find not only the specified word, but other words that have the same meaning. |
QPON_Proximity |
Consider the proximity of results when using the |
QPON_Refine |
Do not search the entire list of indexes, but only the documents that matched the previous search. This is used to refine the results of the previous search. |
To create and populate this structure correctly, the client must know the sum of the lengths of each sort field (sls
), the length of the query (lq
), and the size of the QueryData
structure. The client then allocates memory as follows:
nSize = sizeof(QueryData) + sls + lq;
qd = (QueryData *)malloc(nSize);
For example, if the query was “Adobe” and the sort spec was “Title” ascending and “Score” descending then the structure would be packed as follows:
memset(qd, 0, nSize);
qd->nQueryOffset = 0;
strcpy(&cData[0], "Adobe");
qd->nNumSort = 2;
qd->nSortOffset[0] = strlen("Adobe") + 1;
qd->bSortWays[0] = TRUE;
strcpy(&cData[qd->nSortOffset[0]], "Title");
qd->bSortWays[1] = FALSE;
qd->nSortOffset[1] = qd->nSortOffset[0] + strlen("Title") + 1;
strcpy(&cData[qd->nSortOffset[1]], "Score");
Manipulating indexes through DDE¶
After a connection has been made, a single poke transaction can add, delete, add, or remove indexes. The item name to use is “Index".
hszItemName = DdeCreateStringHandle(id, "Index", 0);
DdeClientTransaction(qd, nLen, hConv, hszItemName, CF_TEXT, XTYP_POKE,
1000, &dwResult);
DdeDisconnect(hConv);
The global data handle (gd
) passed to the server must be in the following format:
typedef struct _IndexData {
IndexActionType eAction;
int16 nIndexOffset;
int16 nTempNameOffset;
unsigned char cData[1];
} IndexData;
Options¶
Parameter |
Description |
---|---|
eAction |
The operation to be performed on the index. Must be one of values listed in Index operation selectors. |
nIndexOffset |
An offset into the |
nTempNameOffset |
An offset into |
Index operation selectors¶
Parameter |
Description |
---|---|
IndexAction_Add |
Adds an index to the shelf. |
IndexAction_Remove |
Removes an index from the shelf. |
IndexAction_Enable |
Enables an index on the shelf. |
IndexAction_Disable |
Disables an index on the shelf. |
To create and populate this structure correctly, the client must know the sum of the lengths of the Index (li
) and Temp names (lt
) (including NULL
-terminating characters), and the size of the IndexData
structure.
The client then allocates memory as follows:
nSize = sizeof(IndexData) + li + lt;
id = (IndexData *)malloc(nSize);
For example, to add the index C:FOO.PDX to the Search plug-in’s shelf:
memset(id, 0, nSize);
id->eAction = IndexAction_Add;
id->nIndexOffset = 0;
strcpy(&id->cData[0], "C:FOO.PDX");
id->nTempNameOffset = strlen("C:FOO.PDX") + 1;
strcpy(&id->cData[id->nTempNameOffset],
"My Favorite Index");
Search plug-in using Apple events¶
The Search plug-in supports the Apple events described in this section.
SearchAddIndex¶
Adds a specified index to the shelf.
Apple event ID
kSearchAddIndex ('addx')
Parameters
Parameter |
Description |
---|---|
kIndexListTag (‘SilP’), typeLongInteger |
An opaque |
kPathTag (‘Path’), typeChar |
Mac OS full path representing an index, of the form: |
kFlagTag (‘Flag’), typeLongInteger |
Index flags. See SearchGetIndexFlags for a description. The |
Returns
kIndexTag ('SixP'), typeLongInteger
An opaque void*
representing an index. Returns NULL
if failure.
Returns
#define kIndexExists ((SearchIndexPtr)-1)
if the index already exists in the index list. If the index already exists, you can retrieve it using SearchGetIndexByPath.
SearchCountIndexList¶
Gets the number of indexes currently on the shelf.
Apple event ID
kSearchCountIndexList ('cidx')
Parameters
Parameter |
Description |
---|---|
kIndexListTag (‘SilP’), typeLongInteger |
An opaque |
Returns
kIndexListTag ('SilP'), typeLongInteger
Number of indexes on the shelf (kIndexListTag
here is not semantically correct, but works).
SearchDoQuery¶
Executes a specified query, using the set of indexes currently on the shelf. The search results are displayed in the Acrobat Search plug-in’s Results window.
Apple event ID
kSearchDoQuery ('kwry')
Parameters
Parameter |
Description |
---|---|
kQueryStringTag (‘Quryv), typeChar |
The query string, a |
kParserTag (‘Prsr’), typeShortInteger |
The query parser to use; may be one of (see SrchType.h): |
kSortSpecTag (‘Sort’), typeAEList |
A list of C strings representing fields to sort by. The first element is the first level sort, the second is the second level sort, and so forth. Each string may be any field that appears in the index, plus |
kWordOptionsTag (‘WOpt’), typeLongInteger |
A bit field of word options. Must be a logical OR of the values listed below in Word options for Apple events. The manner in which the options are used depends on the value associated with |
kOptionsOverrideTag (‘WOer’), typeShortInteger |
Flag that indicates whether the word options are |
kMaxDocsTag (‘MaxD’), typeShortInteger |
The maximum number of documents to display in the Results window. If more documents than this have hits, only the first |
Word options for Apple events¶
kWordOptionCase |
The search is case-sensitive. |
---|---|
kWordOptionStemming |
Find not only the specified word, but other words that have the same stem (for example, run and ran have the same stem). |
kWordOptionSoundsLike |
Find not only the specified word, but other words that sound like it. |
kWordOptionThesaurus |
Find not only the specified word, but other words that have the same meaning. |
kWordOptionProximity |
Consider the proximity of results when using the |
kWordOptionRefine |
Do not search the entire list of indexes, but only the documents that matched the previous search. This is used to refine the results of the previous search. |
SearchGetIndexByPath¶
Gets the index that has the specified path. The index must already be on the shelf. The index can be passed to other Search Apple events to remove it from the shelf, obtain its title, and so forth.
Apple event ID
kSearchGetIndexByPath ('fpdx')
Parameters
Parameter |
Description |
---|---|
kIndexListTag (‘SilP’), typeLongInteger |
An opaque |
kPathTag (‘Path’), typeChar |
Mac OS full path representing an index, of the form: |
Returns
kIndexTag ('SixP'), typeLongInteger
An opaque void*
representing an index. Returns NULL
if the specified index is gone.
SearchGetIndexFlags¶
Get the flags for an index.
Apple event ID
kSearchGetIndexFlags ('gfdx')
Parameters
Parameter |
Description |
---|---|
kIndexTag (‘SixP’), typeLongInteger |
An opaque |
Returns
kFlagTag ('Flag'), typeLongInteger
A logical OR
of the following:
kIndexAvailableFlag (1L << 0)
: Set if the index is available for searching.kIndexSelectedFlag (1L << 1)
: Set if the index appears with a check mark in the Search plug-in’s user interface.kIndexPtrInvalidFlag (1L << 31)
: Set if the index is not valid or is no longer valid.
SearchGetIndexList¶
Gets a list of the indexes currently on the shelf.
Apple event ID
kSearchGetIndexList ('gidx')
Returns
kIndexListTag ('SilP'), typeLongInteger
An opaque void*
representing the list of indexes currently on the shelf. This value can subsequently be used by other search Apple events to obtain information about a specific index, the number of indexes on the shelf, and so forth.
SearchGetIndexPath¶
Gets the full path to an index.
Apple event ID
kSearchGetIndexPath ('gpdx')
Parameters
Parameter |
Description |
---|---|
kIndexTag (‘SixP’), typeLongInteger |
An opaque |
Returns
kPathTag ('Path'), typeChar
A NULL
-terminated character string representing the full path of the index . Returns an empty string if the requested index is not valid.
SearchGetIndexTitle¶
Gets the title of an index.
Apple event ID
kSearchGetIndexTitle ('gtdx')
Parameters
Parameter |
Description |
---|---|
kIndexTag (‘SixP’), typeLongInteger |
An opaque |
Returns
kTitleTag ('Title'), typeChar
A NULL
-terminated character string representing the title of the index. If there is no title, it returns the index’s path . Returns an empty string if the requested index is not valid.
SearchGetNthIndex¶
Gets the n th index on the shelf. The index can be passed to other Search Apple events to remove it from the shelf, obtain its title, and so forth.
Apple event ID
kSearchGetNthIndex ('fndx')
Parameters
Parameter |
Description |
---|---|
kIndexListTag (‘SilP’), typeLongInteger |
An opaque |
kNthIndexTag (‘Enth’), typeLongInteger |
The index to get. The first index on the shelf is index zero. |
Returns
kIndexTag ('SixP'), typeLongInteger
An opaque void*
representing an index . Returns NULL
if the n th index is gone.
SearchRemoveIndex¶
Removes the specified index from the shelf.
Apple event ID
kSearchRemoveIndex ('rmdx')
Parameters
Parameter |
Description |
---|---|
kIndexListTag (‘SilP’), typeLongInteger |
An opaque |
kIndexTag (‘SixP’), typeLongInteger |
An opaque |
SearchSetIndexFlags¶
Sets the flags for an index.
Apple event ID
kSearchSetIndexFlags ('sfdx')
Parameters
Parameter |
Description |
---|---|
kIndexTag (‘SixP’), typeLongInteger |
An opaque |
kFlagTag (‘Flag’),typeLongInteger |
Index flags. See the description in SearchGetIndexFlags. In practice, |
Returns
kFlagTag ('Flag'), typeLongInteger
Index flags. See the description in SearchGetIndexFlags. This value is returned because it is possible for a request to set a flag to fail.
Search lists¶
The Search plug-in adds a new menu, menu items, and toolbar buttons to the Acrobat application.
">Menu names
The Search plug-in adds the following menu to Acrobat.
Menu name |
Description |
---|---|
AcroSrch:ToolsSubMenu |
Acrobat Search submenu of Edit menu |
Toolbar button names¶
The Search plug-in adds the following buttons to the Acrobat toolbar.
Button name |
Description |
---|---|
AcroSrch:Separator |
Separator (not visible). |
AcroSrch:Query |
Displays the Acrobat Search plug-in’s query dialog box. |
AcroSrch:Results |
Displays the Acrobat Search plug-in’s search results dialog box. |
AcroSrch:Prev |
Goes to the previous hit in the Acrobat Search plug-in’s results list. |
AcroSrch:Next |
Goes to the next hit in the Acrobat Search plug-in’s results list. |