UNPKG

4.49 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.SearchRequest = exports.SearchScanConsistency = exports.HighlightStyle = exports.SearchResult = exports.SearchRow = exports.SearchMetaData = void 0;
4const errors_1 = require("./errors");
5const searchquery_1 = require("./searchquery");
6const vectorsearch_1 = require("./vectorsearch");
7/**
8 * SearchMetaData represents the meta-data available from a search query.
9 * This class is currently incomplete and must be casted to `any` in
10 * TypeScript to be used.
11 *
12 * @category Full Text Search
13 */
14class SearchMetaData {
15}
16exports.SearchMetaData = SearchMetaData;
17/**
18 * SearchRow represents the data available from a row of a search query.
19 * This class is currently incomplete and must be casted to `any` in
20 * TypeScript to be used.
21 *
22 * @category Full Text Search
23 */
24class SearchRow {
25}
26exports.SearchRow = SearchRow;
27/**
28 * Contains the results of a search query.
29 *
30 * @category Full Text Search
31 */
32class SearchResult {
33 /**
34 * @internal
35 */
36 constructor(data) {
37 this.rows = data.rows;
38 this.meta = data.meta;
39 }
40}
41exports.SearchResult = SearchResult;
42/**
43 * Specifies the highlight style that should be used for matches in the results.
44 *
45 * @category Full Text Search
46 */
47var HighlightStyle;
48(function (HighlightStyle) {
49 /**
50 * Indicates that matches should be highlighted using HTML tags in the result text.
51 */
52 HighlightStyle["HTML"] = "html";
53 /**
54 * Indicates that matches should be highlighted using ASCII coding in the result test.
55 */
56 HighlightStyle["ANSI"] = "ansi";
57})(HighlightStyle || (exports.HighlightStyle = HighlightStyle = {}));
58/**
59 * Represents the various scan consistency options that are available when
60 * querying against the query service.
61 *
62 * @category Full Text Search
63 */
64var SearchScanConsistency;
65(function (SearchScanConsistency) {
66 /**
67 * Indicates that no specific consistency is required, this is the fastest
68 * options, but results may not include the most recent operations which have
69 * been performed.
70 */
71 SearchScanConsistency["NotBounded"] = "not_bounded";
72})(SearchScanConsistency || (exports.SearchScanConsistency = SearchScanConsistency = {}));
73/**
74 * Represents a search query and/or vector search to execute via the Couchbase Full Text Search (FTS) service.
75 *
76 * @category Full Text Search
77 */
78class SearchRequest {
79 constructor(query) {
80 if (query instanceof searchquery_1.SearchQuery) {
81 this._searchQuery = query;
82 }
83 else if (query instanceof vectorsearch_1.VectorSearch) {
84 this._vectorSearch = query;
85 }
86 else {
87 throw new errors_1.InvalidArgumentError(new Error('Must provide either a SearchQuery or VectorSearch when creating SearchRequest.'));
88 }
89 }
90 /**
91 * @internal
92 */
93 get searchQuery() {
94 return this._searchQuery;
95 }
96 /**
97 * @internal
98 */
99 get vectorSearch() {
100 return this._vectorSearch;
101 }
102 /**
103 * Adds a search query to the request if the request does not already have a search query.
104 *
105 * @param query A SearchQuery to add to the request.
106 */
107 withSearchQuery(query) {
108 if (!(query instanceof searchquery_1.SearchQuery)) {
109 throw new errors_1.InvalidArgumentError(new Error('Must provide a SearchQuery.'));
110 }
111 if (this._searchQuery) {
112 throw new errors_1.InvalidArgumentError(new Error('Request already has a SearchQuery.'));
113 }
114 this._searchQuery = query;
115 return this;
116 }
117 /**
118 * Adds a vector search to the request if the request does not already have a vector search.
119 *
120 * @param search A VectorSearch to add to the request.
121 */
122 withVectorSearch(search) {
123 if (!(search instanceof vectorsearch_1.VectorSearch)) {
124 throw new errors_1.InvalidArgumentError(new Error('Must provide a VectorSearch.'));
125 }
126 if (this._vectorSearch) {
127 throw new errors_1.InvalidArgumentError(new Error('Request already has a VectorSearch.'));
128 }
129 this._vectorSearch = search;
130 return this;
131 }
132 /**
133 * Creates a search request.
134 *
135 * @param query Either a SearchQuery or VectorSearch to add to the search request.
136 */
137 static create(query) {
138 return new SearchRequest(query);
139 }
140}
141exports.SearchRequest = SearchRequest;