/** * Creates a document for indexing. * * For this connector sample, the created document is domain public * searchable. The content is a simple text string. * * @param record The current CSV record to convert * @return the fully formed document ready for indexing */privateApiOperationbuildDocument(CSVRecordrecord){// Extract term and synonyms from recordStringterm=record.get(0);List<String>synonyms=StreamSupport.stream(record.spliterator(),false).skip(1)// Skip term.collect(Collectors.toList());Multimap<String,Object>structuredData=ArrayListMultimap.create();structuredData.put("_term",term);structuredData.putAll("_synonym",synonyms);if(Configuration.getBoolean("dictionary.attachedToSearchApp",false).get()){structuredData.put("_onlyApplicableForAttachedSearchApplications",true);}StringitemName=String.format("dictionary/%s",term);// Using the SDK item builder class to create the itemItemitem=IndexingItemBuilder.fromConfiguration(itemName).setItemType(IndexingItemBuilder.ItemType.CONTENT_ITEM).setObjectType("_dictionaryEntry").setValues(structuredData).setAcl(DOMAIN_PUBLIC_ACL).build();// Create the fully formed documentreturnnewRepositoryDoc.Builder().setItem(item).build();}
[null,null,["最后更新时间 (UTC):2025-08-29。"],[],[],null,["# Define synonyms\n\nIt's common for an organization to have unique terminology or multiple ways\nto refer to a concept or thing. You should define synonyms to establish\nequivalency of terms to helps users find items when searching.\n| **Note:** Custom synonyms can only be defined for third-party data sources; they can't be defined for Google Workspace data sources, such as Google Drive or Gmail.\n\nSynonyms are defined by indexing items with the `_dictionaryEntry` well-known\nschema.\n\nItems of type `_dictionaryEntry` can have the following properties:\n\n| Property | Type | Description | Required? |\n|------------------------------------------------|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------|\n| `_term` | string | The term to define. Recommended values are unhyphenated words or phrases without punctuation. | Required |\n| `_synonym` | string (repeated) | Alternate terms to be included in queries matching the string defined in `_term`. | Required |\n| `_onlyApplicableForAttachedSearchApplications` | boolean | Allows you to group synonyms by data source and search application. For further information, see [Define data source-specific synonyms](/workspace/cloud-search/docs/guides/synonyms#specific). | Optional |\n\n| **Note:** Items indexed with `_dictionaryEntry` schema don't count towards the data source limits in a search application.\n\nWhen a user includes the value of the `_term` property in a query,\nthe *effective* query becomes \"*term OR synonyms* .\" For example, if the\nterm \"scifi\" is defined with the synonym\n\"science fiction\" then a query\ncontaining the word \"scifi\" matches items containing\neither \"scifi\"\nor \"science fiction.\"\n\nSynonyms are not applied bidirectionally. If the query is instead for\n\"science fiction,\" Cloud Search\ndoesn't apply any synonyms to the query. The query only matches items containing\n\"science fiction.\" Items containing\n\"scifi\" are omitted.\n\nTo make all both terms interchangeable, define each term separately:\n\n| Term | Synonyms |\n|-----------------|-----------------|\n| scifi | science fiction |\n| science fiction | scifi |\n\nDuring query processing, hyphenation and other punctuation are removed prior\nto applying synonyms. The user query \"sci-fi\"\nmatches the `_term` \"sci fi.\"\nTo create synonyms for terms which may be hyphenated by users, first normalize\nthe `_term` to use whitespace instead of hyphens.\n\nContinuing the example, the following definitions match the user queries treat\n\"sci-fi,\" \"sci fi,\" \"scifi,\" and\n\"science fiction\" as interchangeable:\n\n| Term | Synonyms |\n|-----------------|-------------------------|\n| scifi | science fiction, sci fi |\n| sci fi | science fiction, scifi |\n| science fiction | scifi, sci fi |\n\n| **Note:** It may take up to 5 hours before synonyms are processed and are used to rewrite queries.\n\nBy default, synonyms in any data source apply across an entire domain.\nSpecifically, synonyms are applied across search applications for all searches\nregardless of the data source. If you want data source-specific synonyms, refer\nto [Define data source-specific synonyms](#specific).\n\nDefine global synonyms using the Cloud Search SDK\n-------------------------------------------------\n\nYou can use the Content Connector SDK to define terms and their synonyms. See\n[Create a content connector](/workspace/cloud-search/docs/guides/content-connector) for\ninstructions on building a connector.\n\nThe following snippet illustrates building a\n[`RepositoryDoc`](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/indexing/template/RepositoryDoc)\nrepresenting the term and synonym based on a CSV file record: \nDictionaryConnector.java \n[View on GitHub](https://github.com/googleworkspace/cloud-search-samples/blob/main/indexing/connector/sdk/dictionary-connector/src/main/java/com/google/cloudsearch/samples/DictionaryConnector.java) \n\n```java\n/**\n * Creates a document for indexing.\n *\n * For this connector sample, the created document is domain public\n * searchable. The content is a simple text string.\n *\n * @param record The current CSV record to convert\n * @return the fully formed document ready for indexing\n */\nprivate ApiOperation buildDocument(CSVRecord record) {\n // Extract term and synonyms from record\n String term = record.get(0);\n List\u003cString\u003e synonyms = StreamSupport.stream(record.spliterator(), false)\n .skip(1) // Skip term\n .collect(Collectors.toList());\n\n Multimap\u003cString, Object\u003e structuredData = ArrayListMultimap.create();\n structuredData.put(\"_term\", term);\n structuredData.putAll(\"_synonym\", synonyms);\n\n if (Configuration.getBoolean(\"dictionary.attachedToSearchApp\", false).get()) {\n structuredData.put(\"_onlyApplicableForAttachedSearchApplications\", true);\n }\n\n String itemName = String.format(\"dictionary/%s\", term);\n\n // Using the SDK item builder class to create the item\n Item item =\n IndexingItemBuilder.fromConfiguration(itemName)\n .setItemType(IndexingItemBuilder.ItemType.CONTENT_ITEM)\n .setObjectType(\"_dictionaryEntry\")\n .setValues(structuredData)\n .setAcl(DOMAIN_PUBLIC_ACL)\n .build();\n\n // Create the fully formed document\n return new RepositoryDoc.Builder()\n .setItem(item)\n .build();\n}\n```\n\nNote the following when defining synonyms:\n\n- Synonym entries are required to be domain public. In the previous example, this is accomplished by setting the ACL to `DOMAIN_PUBLIC_ACL`.\n- The following properties should not be defined for your configuration file because they override the domain public setting in your code:\n - `defaultAcl.mode=FALLBACK`\n - `defaultAcl.public=true`\n\nDefine search application-specific synonyms\n-------------------------------------------\n\nBy default, synonyms are applied to all data sources across all search\napplications.\n\nHowever, suppose your organization has separate engineering and sales teams, and\nyou want to provide each team with a different search experience, including\njob role-specific synonyms. In this case, you could create one search\napplication with an engineering-specific data source and synonyms and another\nsearch application with a sales-specific data source and synonyms. To accomplish\nthis goal, index each synonym in a specific data source\nusing `_onlyApplicableForAttachedSearchApplications=true`. This\nsetting limits the synonyms such that they are only applied to search\napplications that include a specific data source.\n\nFor example, adding the\nfollowing line of code to the previous code sample ensures the indexed synonyms\nare data source-specific: \n\n structuredData.put(\"_onlyApplicableForAttachedSearchApplications\", true);"]]