Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce number of terms for autocomplete and use single quote when bui… #102

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/QueryBuilder/elastic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type OrderByType = '_key' | '_term' | '_count'
function getTermsAgg(
fieldName: string,
size: number,
segment_size: number,
orderBy: OrderByType = "_key",
order: 'asc'|'desc' = 'asc'
): BucketAggregation {
Expand All @@ -20,6 +21,7 @@ function getTermsAgg(
field: fieldName,
settings:{
size: size.toString(),
segment_size: segment_size.toString(),
order: order,
orderBy: orderBy,
}
Expand All @@ -31,7 +33,8 @@ export function getDataQuery(queryDef: TermsQuery, refId: string): Elasticsearch
{id:"count1", type:'count'}
];

// Default behaviour is to order results by { _key: asc }
// Default behaviour is to order results by { _key: asc } and get 100 terms,
// segment_size is set to 100 to limit terms fetched by segment (by default it's 100 * 10).
// queryDef.order allows selection of asc/desc
// queryDef.orderBy allows selection of doc_count ordering (defaults desc)

Expand All @@ -55,7 +58,7 @@ export function getDataQuery(queryDef: TermsQuery, refId: string): Elasticsearch

const bucketAggs: BucketAggregation[] = [];
if (queryDef.field) {
bucketAggs.push(getTermsAgg(queryDef.field, 500, orderBy, order))
bucketAggs.push(getTermsAgg(queryDef.field, 100, 100, orderBy, order))
}

return {
Expand Down
1 change: 1 addition & 0 deletions src/dataquery.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface Terms extends BucketAggregationWithField {
settings?: {
order?: TermsOrder;
size?: string;
segment_size?: string;
min_doc_count?: string;
orderBy?: string;
missing?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/datasource/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ export function useDatasourceFields(datasource: BaseQuickwitDataSource) {
const getSuggestions = useCallback(async (word: string): Promise<Suggestion> => {
let suggestions: Suggestion = { from: 0, options: [] };

const wordIsField = word.match(/([^:\s]+):"?([^"\s]*)"?/);
const wordIsField = word.match(/([^:\s]+):'?([^'\s]*)'?/);
if (wordIsField?.length) {
const [_match, fieldName, _fieldValue] = wordIsField;
const candidateValues = await datasource.getTagValues({ key: fieldName });
suggestions.from = fieldName.length + 1; // Replace only the value part
suggestions.options = candidateValues.map(v => ({
type: 'text',
label: typeof v.text === 'number' ? `${v.text}` : `"${v.text}"`
label: typeof v.text === 'number' ? `${v.text}` : `'${v.text}'`
}));
} else {
const candidateFields = fields;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/lucene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class LuceneQuery {

key = escapeFilter(key);
value = escapeFilterValue(value);
const filter = `${modifier}${key}:"${value}"`;
const filter = `${modifier}${key}:'${value}'`;

return LuceneQuery.parse(concatenate(this.toString(), filter));
}
Expand Down
Loading