Skip to content

Commit

Permalink
feat(search_playground): default context to all source_fields
Browse files Browse the repository at this point in the history
  • Loading branch information
TattdCodeMonkey committed Feb 12, 2025
1 parent 015ad37 commit ed717eb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ describe('create_query', () => {
});

describe('getDefaultSourceFields', () => {
it('should return default source fields', () => {
it('should return source fields', () => {
const fieldDescriptors: IndicesQuerySourceFields = {
'search-search-labs': {
elser_query_fields: [],
Expand Down Expand Up @@ -922,7 +922,23 @@ describe('create_query', () => {
};

expect(getDefaultSourceFields(fieldDescriptors)).toEqual({
'search-search-labs': ['body_content'],
'search-search-labs': [
'additional_urls',
'title',
'links',
'id',
'url_host',
'url_path',
'url_path_dir3',
'body_content',
'domains',
'url',
'url_scheme',
'meta_description',
'headings',
'url_path_dir2',
'url_path_dir1',
],
});
});

Expand All @@ -944,23 +960,6 @@ describe('create_query', () => {
'search-search-labs': [undefined],
});
});

it('should return the first single field when no source fields', () => {
const fieldDescriptors: IndicesQuerySourceFields = {
'search-search-labs': {
elser_query_fields: [],
semantic_fields: [],
dense_vector_query_fields: [],
bm25_query_fields: [],
source_fields: ['non_suggested_field'],
skipped_fields: 0,
},
};

expect(getDefaultSourceFields(fieldDescriptors)).toEqual({
'search-search-labs': ['non_suggested_field'],
});
});
});

describe('getIndicesWithNoSourceFields', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ export const SUGGESTED_BM25_FIELDS = [

export const SUGGESTED_DENSE_VECTOR_FIELDS = ['content_vector.tokens'];

const SUGGESTED_SOURCE_FIELDS = [
'body_content',
'content',
'text',
'page_content_text',
'text_field',
];

const SEMANTIC_FIELD_TYPE = 'semantic';

interface Matches {
Expand Down Expand Up @@ -313,14 +305,6 @@ export function getDefaultSourceFields(fieldDescriptors: IndicesQuerySourceField
(acc: IndexFields, index: string) => {
const indexFieldDescriptors = fieldDescriptors[index];

// semantic_text fields are prioritized
if (indexFieldDescriptors.semantic_fields.length > 0) {
return {
...acc,
[index]: indexFieldDescriptors.semantic_fields.map((x) => x.field),
};
}

// if there are no source fields, we don't need to suggest anything
if (indexFieldDescriptors.source_fields.length === 0) {
return {
Expand All @@ -329,15 +313,9 @@ export function getDefaultSourceFields(fieldDescriptors: IndicesQuerySourceField
};
}

const suggested = indexFieldDescriptors.source_fields.filter((x) =>
SUGGESTED_SOURCE_FIELDS.includes(x)
);

const fields = suggested.length === 0 ? [indexFieldDescriptors.source_fields[0]] : suggested;

return {
...acc,
[index]: fields,
[index]: indexFieldDescriptors.source_fields,
};
},
{}
Expand Down

0 comments on commit ed717eb

Please sign in to comment.