chromium/components/continuous_search/common/public/mojom/continuous_search.mojom

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module continuous_search.mojom;

import "mojo/public/mojom/base/string16.mojom";
import "url/mojom/url.mojom";

// This module contains data structures and an interface to extract search
// results from a Google Search Results Page.

// A single result from the page.
struct SearchResult {
  // Link for the result.
  url.mojom.Url link;

  // Title of the result.
  mojo_base.mojom.String16 title;
};

// The types of logically related groups of search results. E.g. organic
// search results, related searches, etc.
enum ResultType {
  // Organic search results (regular "10 blue links").
  kSearchResults,

  // Related searches.
  kRelatedSearches
};

// A logically related group of search results with a label. E.g. organic,
// news, etc.
struct ResultGroup {
  // The type for this group.
  ResultType type;

  // A list of results for this group.
  array<SearchResult> results;
};

// The result category for the search page. E.g. results, news, images, etc.
enum Category {
  // Empty result.
  kNone,

  // Organic search results (regular "10 blue links").
  kOrganic,
};

// All results from a particular category's page.
struct CategoryResults {
  // The URL of the document the data was extracted from.
  url.mojom.Url document_url;

  // The category the associated groups belong to.
  Category category_type = kNone;

  // Groups of results partitioned by a logical labels.
  array<ResultGroup> groups;
};

// Used to extract search results for a Google search page.
interface SearchResultExtractor {
  // The outcome of the extraction attempt.
  enum Status {
    // Extraction was successful.
    kSuccess,

    // No results were generated from the extraction.
    kNoResults,
  };

  // Performs a structured search of the DOM to extract results of given types
  // from the current search result page (with the currently selected category).
  // `result_types` is list of result types to extract. The extraction will fail
  // and no results will be generated if any of the types cannot be extracted.
  ExtractCurrentSearchResults(array<ResultType> result_types)
      => (Status status, CategoryResults results);
};