Skip to content

Exports ​

TIP

JavaScript snippets on this page should go in a custom JS file. See here and the tutorial here.

Show / Hide ​

Show or hide the export button

js
vuexModules.ui.actions.results.shared.exportEnabled(false);

Exported Data ​

js
// Which annotations are included in the export
vuexModules.ui.actions.results.shared.detailedAnnotationIds(['word', 'lemma', 'pos_full']);
// Which metadata fields are included in the export
vuexModules.ui.actions.results.shared.detailedMetadataIds(['title', 'author']);

Description in Export File ​

Customize the description at the top of the export file. This is useful for providing context or instructions for the exported data.

js
frontend.customize(corpus => {
	/** @param {BLSearchSummary} blSummary */
	corpus.results.csvDescription = function(blSummary, fieldDisplayNameFunc: (name, baseFieldName) => string) {
		return `Exported from ${corpus._corpus.displayName} on ${new Date().toLocaleDateString()}.\n\n` +
			`This export includes the following fields:\n` +
			`- ${fieldDisplayNameFunc('title', 'title')}\n` +
			`- ${fieldDisplayNameFunc('author', 'author')}\n` +
			`- ${fieldDisplayNameFunc('date', 'date')}\n\n` +
			`For more information, visit our documentation.`;
	}
})
ts

type BLSearchSummarySampleV4 =
	| {}
	| {
			samplePercentage: number;
			sampleSeed: number;
	  }
	| {
			sampleSeed: number;
			sampleSize: number;
	  };

/** Match info definition in summary */
export type BLSummaryMatchInfo = {
	type: 'span' | 'tag' | 'relation' | 'list';
	/** field this capture is in (if not default field) */
	fieldName?: string;
	/** field the relation target is in (if not default field) */
	targetField?: string;
};

export type BLSearchSummaryV4 = {
	actualWindowSize: number;
	countTime?: number;
	/** These fields have a special meaning in the BLDocResult.docInfo */
	docFields: BLDocFieldsV4;
	requestedWindowSize: number;
	searchParam: BLSearchParameters;
	searchTime: number;
	/** Only available when request was sent with includetokencount: true */
	tokensInMatchingDocuments?: number;
	windowFirstResult: number;
	windowHasNext: boolean;
	windowHasPrevious: boolean;

	/** Total documents across all counted (not retrieved) hits, -1 if some error occured */
	numberOfDocs: number;
	/** Total documents across all retrieved hits */
	numberOfDocsRetrieved: number;
	/** Is any counting ongoing, generally true unless blacklab finished counting all results or results exceed the count limit (stoppedCountingHits = true) */
	stillCounting: boolean;
} & BLSearchSummarySampleV4;

type BLSearchSummaryWindowV5 = {
	firstResult: number;
	requestedSize: number;
	actualSize: number;
	hasPrevious: boolean;
	hasNext: boolean;
};

export type BLSearchResultsStatsV5 = {
	/** When status === finished, see stoppedBecauseTooMany for the reason */
	status: 'finished' | 'working';
	hits: number | undefined; // when no pattern, no hits.
	documents: number;
	timeMs: number;
	/** Always present, but never true unless status === 'finished' (even then - only when there were more results but BlackLab stopped the search due to configured limits) */
	stoppedBecauseTooMany: boolean;
};

export type BLSubcorpusSize = {
	documents: number;
	tokens: number;
	annotatedFields?: Array<{
		fieldName: string;
		documents: number;
		tokens: number;
	}>;
};

export type BLSearchSummaryV5 = {
	params: BLSearchParameters;
	pattern?: BLSearchSummaryPatternInfo;
	results: {
		window?: BLSearchSummaryWindowV5;
		stats: {
			processed: BLSearchResultsStatsV5;
			counted: BLSearchResultsStatsV5;
			/** Subcorpus across the whole query; i.e. what would be matched if pattern wasn't present */
			subcorpusSize?: BLSubcorpusSize;
		} & ({ numberOfGroups?: never; largestGroupSize?: never } | { numberOfGroups: number; largestGroupSize: number });

		sample?:
			| {
					size: number;
					seed: number;
			  }
			| {
					percentage: number;
					seed: number;
			  }
			| {
					percentage: undefined;
					seed: undefined;
					sample: undefined;
			  };
	};
};

type BLSearchSummaryPatternInfoV4 = {
	/** The serialization of the query object BlackLab actually executed. */
	bcql: string;
	/** The main annotatedField that was searched. This is the full name of the field e.g. "contents__en" */
	fieldName: string;
	/** Any other annotatedFields involved in the search (in case of parallel corpora). These are the full names e.g. ["contents__en"] */
	otherFields?: string[];
	/** Json representation of the query. Not present when requesting results as xml output. */
	json?: unknown;
	/* MatchInfos only available when hits are returned (i.e. not a docs request, not grouped) */
	matchInfos?: {
		[key: string]: BLSummaryMatchInfo;
	};
};

export type BLSearchSummaryPatternInfo = BLSearchSummaryPatternInfoV4;

/**
 * Properties in the search summary that are only available if a pattern was passed.
 * Irrespective of whether docs or hits were requested.
 * If a pattern was passed, the summary will contain a pattern object with these properties.
 */
export type BLSearchSummaryPatternV4 = {
	/** Only for queries with a pattern. */
	pattern: BLSearchSummaryPatternInfoV4;
	/** Total number of counted hits (so far), -1 if some error occured */
	numberOfHits: number;
	/** Total number of retrieved hits (so far) */
	numberOfHitsRetrieved: number;
	/** Did the query hit the default count limit (defaultMaxHitsToCount) */
	stoppedCountingHits: boolean;
	/** Did the query hit the default retrieval limit (defaultMaxHitsToRetrieve) */
	stoppedRetrievingHits: boolean;
	subcorpusSize?: {
		documents: number;
		tokens: number;
		annotatedFields?: {
			fieldName: string;
			documents: number;
			tokens: number;
		}[];
	};
};

/** Only when results have been grouped. */
export interface BLSearchSummaryGroupedV4 {
	largestGroupSize: number;
	numberOfGroups: number;

	/**
	 * Contains the size of the entire searched subcorpus (e.g. number of docs and tokens found by the same query without a cql pattern).
	 *
	 * When results ARE grouped based on document metadata, is also present in the individual HitGroups instead,
	 * representing sum of all docs that match the metadata of the group + the main query's lucene filter.
	 */
	subcorpusSize: {
		/** NOTE: may be 0 in rare cases, when specifying a search for the empty value for all metadata fields */
		documents: number;
		/** NOTE: may be 0 in rare cases, when specifying a search for the empty value for all metadata fields */
		tokens: number;
	};
}

Apache license 2.0