• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yext / answers-search-ui / 13547664578

26 Feb 2025 03:38PM UTC coverage: 61.773% (-0.4%) from 62.179%
13547664578

push

github

web-flow
Version 1.18.0 (#1916)

This PR represents the work to add Generative Direct Answers support, both in basic searching functionality and analytics support, along with some vulnerability fixes.

* Add GDA Object Model

Similar to the existing DirectAnswer model, we will take in an
object from search-core (GenerativeDirectAnswerResponse in this
case) and use it to construct a model.

J=WAT-4592
TEST=auto
Ran unit tests

* Update package.json to beta version

* ksearch: Add flow for automatically calling into the GDA endpoint

In this change I added the following functionality:
- at the global config level, there will be a new property named
"useGenerativeDirectAnswers" that must be set to true in order
for GDA to work on the site
- When the universal results or vertical results change, that will
trigger a call into the GDA endpoint.

To accomplish the above, I have added two new storage keys - one
for the GDA itself, and one for the Search ID, which we need for
the request into GDA.

J=WAT-4593
TEST=auto, manual
Auto: Wrote new tests
Manual: Spun up local instance of the answers-search-ui + HH theme
and changed the vars to use a Prod Search config with GDA
configured. Saw the request being fired in the network tab when
the prop was set to true, and not fired when the prop was set to
false

* Automated update to THIRD-PARTY-NOTICES from github action's 3rd party notices check

* Include some results data in the GDA object constructed

* Remove console log

* Filter results in GDA model to only include those with name and matching uid in citations

* Add Result Component for Generative Direct Answers

This change includes the logic necessary to visualize a GDA response in
the UI via the answers-search-ui package. The component styled here
(styled using the Handlebars template and custom CSS) will be used if
there is not a custom card for GDA set (in the theme, we will create a
nearly identical, but still different, card visual).

The actual *logic* for get... (continued)

2029 of 3433 branches covered (59.1%)

Branch coverage included in aggregate %.

67 of 114 new or added lines in 6 files covered. (58.77%)

30 existing lines in 4 files now uncovered.

3483 of 5490 relevant lines covered (63.44%)

26.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.0
/src/core/models/generativedirectanswer.js
1
/** @module GenerativeDirectAnswer */
2

3
import SearchStates from '../storage/searchstates';
4
import RichTextFormatter from '../utils/richtextformatter';
5
import Searcher from '../models/searcher';
6

7
export default class GenerativeDirectAnswer {
8
  constructor (generativeDirectAnswer = {}) {
×
9
    Object.assign(this, { searchState: SearchStates.SEARCH_COMPLETE }, generativeDirectAnswer);
6✔
10
  }
11

12
  /**
13
   * Constructs an SDK GenerativeDirectAnswer from a search-core GenerativeDirectAnswerResponse
14
   *
15
   * @param {GenerativeDirectAnswerResponse} gdaResponse from search-core
16
   * @param {string} searcher whether this generative direct answer is from a "UNIVERSAL" or "VERTICAL" search
17
   * @param {VerticalResults[]} verticalResults list of search-core VerticalResults
18
   * @returns {GenerativeDirectAnswer}
19
   */
20
  static fromCore (gdaResponse, searcher, verticalResults) {
21
    if (!gdaResponse) {
2!
NEW
22
      return new GenerativeDirectAnswer();
×
23
    }
24

25
    const verticalKey = searcher === Searcher.UNIVERSAL ? '' : verticalResults[0].verticalKey;
2✔
26

27
    const citationsData = verticalResults
2✔
28
      .flatMap(vr => vr.results)
3✔
29
      .filter(result => result.rawData?.uid && result.id && result.name)
7✔
30
      .filter(result => gdaResponse.citations.includes(result.rawData.uid))
7✔
31
      .map(result => {
32
        return {
5✔
33
          id: result.id,
34
          name: result.name,
35
          description: result.description,
36
          link: result.link
37
        };
38
      });
39

40
    if (gdaResponse.directAnswer) {
2!
41
      const directAnswerAsHTML = RichTextFormatter.format(gdaResponse.directAnswer, 'gda-snippet');
2✔
42
      gdaResponse.directAnswer = directAnswerAsHTML;
2✔
43
    }
44
    const generativeDirectAnswerData = {
2✔
45
      ...gdaResponse,
46
      searcher,
47
      citationsData,
48
      verticalKey
49
    };
50
    return new GenerativeDirectAnswer(generativeDirectAnswerData);
2✔
51
  }
52

53
  /**
54
   * Construct a GenerativeDirectAnswer object representing loading result
55
   * @return {GenerativeDirectAnswer}
56
   */
57
  static searchLoading () {
58
    return new GenerativeDirectAnswer({ searchState: SearchStates.SEARCH_LOADING });
2✔
59
  }
60
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc