> ## Documentation Index
> Fetch the complete documentation index at: https://developers.phrase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Search translation memory (sync)

> 
**Overview**
- Searches a single translation memory using the primary TM scoring pipeline. The endpoint always returns up to 15 `SearchTMResponseDto` entries ordered by score.

**Modes**
- Standard segment search (default): normalize text, leverage penalties, thresholds, tag metadata, and context. This is the behavior when `phraseQuery=true`(default). The service calls the downstream `/search` endpoint with `wildcard=true` to allow combined exact/wildcard candidates in one pass.
- Legacy phrase-only mode: set `phraseQuery=false` to disable the wildcard branch (`wildcard=false`, `exactIfQuotes=false`, `combinedExact=false`). Use when you need strict normalized matches without wildcard processing.

**Request parameters**
- `query` (required): search text. If `trimQuery=true` (default) leading/trailing whitespace is removed before sending to TM service.
- `sourceLang` (required) and optional `targetLangs`: locales are normalized to BCP-47. When `targetLangs` is omitted the backend queries all TM targets.
- `previousSegment` / `nextSegment`: optional context strings; when provided, the backend raises 101% matches that align with the surrounding segments.
- `tagMetadata`: serialized inline tags; improves scoring and avoids dropping tag pairs.
- `trimQuery`: default `true`. Set to `false` to preserve leading/trailing spaces (rare).
- `phraseQuery`: default `true`. Controls whether wildcard/phrase helpers are enabled (see “Modes”).

**Scoring & ordering**
- Backend computes `grossScore` (raw similarity) and `score` (penalty-adjusted). 101% matches retain their priority even after penalties.
- Ordering priority (per downstream service): `score DESC`, `grossScore DESC`, context match priority DESC, segment key ASC, TM priority ASC, timestamp DESC, TU id DESC.
- Numeric replacements or uppercase normalization are not performed here (`replaceFigures=false`, `modifyTransText=false` in this controller).

**Limits & behavior**
- Returns maximum 15 matches; there is no `offset` or `totalFoundCount`.
- Threshold is fixed to `0`, so all results above penalties are returned until limit.
- Multiple target locales per TM are not supported, mirroring backend validation.
- Logical operators (AND/OR/NOT) and wildcard expressions in `query` are interpreted only when `phraseQuery=true` enables the wildcard path.

**Context & caching notes**
- Downstream service may consult its 60-second cache for identical search inputs (including context and penalties). Freshly imported matches might appear with a short delay if cached results are reused.
- If previous/next segments are omitted the search still runs, but 101% context boosts cannot trigger.

**Error handling**
- Invalid locales, blank `query`, or an inaccessible TM ID return `400`/`403`.
- Backend may throw when multiple target locales are submitted for a single TM; the controller surfaces that error unchanged.




## OpenAPI

````yaml /openapi/phrase-tms-latest.json post /api2/v1/transMemories/{transMemoryUid}/search
openapi: 3.0.0
info:
  description: |-
    Welcome to Phrase's TMS API documentation. 

     Please visit our [help center](https://support.phrase.com/hc/en-us/sections/5709662083612) for more information about the APIs. 

     If you have any questions, please contact [Support](https://support.phrase.com/hc/requests/new). 

     Please, include the `User-Agent` header with the name of your application or project. It might be a good idea to include some sort of contact information as well, so that we can get in touch if necessary. Examples of excellent `User-Agent` headers:
     > User-Agent: Example mobile app (example@phrase.com) <br/> User-Agent: ACME Inc Java 1.8 Client (http://acmeinc.com/contact)
  version: Latest
  title: Phrase TMS API
servers:
  - url: https://cloud.memsource.com/web
security:
  - ApiToken: []
  - OAuth2: []
tags:
  - name: Additional Workflow Step
  - name: Analysis
  - name: Async Request
  - name: Authentication
  - name: Automations
  - name: Bilingual File
  - name: Business Unit
  - name: Buyer
  - name: Client
  - name: Connector
  - name: Conversations
  - name: Cost Center
  - name: Custom Fields
  - name: Custom File Type
  - name: Domain
  - name: Due Date Scheme
  - name: Email Template
  - name: File
  - name: Glossary
  - name: Import settings
  - name: Job
  - name: Language AI
  - name: Language Assets
  - name: Language Quality Assessment
  - name: Machine Translation
  - name: Machine Translation Settings
  - name: Mapping
  - name: Net Rate Scheme
  - name: Notifications
  - name: Price List
  - name: Project
  - name: Project Template
  - name: Provider
  - name: Quality Assurance
  - name: Quality Profile
  - name: Quote
  - name: Reference File
  - name: SCIM
  - name: Segment
  - name: Segmentation Rules
  - name: Service
  - name: Spell Check
  - name: SubDomain
  - name: Supported Languages
  - name: Term Base
  - name: Translation
  - name: Translation Memory
  - name: User
  - name: Vendor
  - name: Webhook
  - name: Workflow Step
  - name: Workflow changes
  - name: XML Assistant
paths:
  /api2/v1/transMemories/{transMemoryUid}/search:
    post:
      tags:
        - Translation Memory
      summary: Search translation memory (sync)
      description: >

        **Overview**

        - Searches a single translation memory using the primary TM scoring
        pipeline. The endpoint always returns up to 15 `SearchTMResponseDto`
        entries ordered by score.


        **Modes**

        - Standard segment search (default): normalize text, leverage penalties,
        thresholds, tag metadata, and context. This is the behavior when
        `phraseQuery=true`(default). The service calls the downstream `/search`
        endpoint with `wildcard=true` to allow combined exact/wildcard
        candidates in one pass.

        - Legacy phrase-only mode: set `phraseQuery=false` to disable the
        wildcard branch (`wildcard=false`, `exactIfQuotes=false`,
        `combinedExact=false`). Use when you need strict normalized matches
        without wildcard processing.


        **Request parameters**

        - `query` (required): search text. If `trimQuery=true` (default)
        leading/trailing whitespace is removed before sending to TM service.

        - `sourceLang` (required) and optional `targetLangs`: locales are
        normalized to BCP-47. When `targetLangs` is omitted the backend queries
        all TM targets.

        - `previousSegment` / `nextSegment`: optional context strings; when
        provided, the backend raises 101% matches that align with the
        surrounding segments.

        - `tagMetadata`: serialized inline tags; improves scoring and avoids
        dropping tag pairs.

        - `trimQuery`: default `true`. Set to `false` to preserve
        leading/trailing spaces (rare).

        - `phraseQuery`: default `true`. Controls whether wildcard/phrase
        helpers are enabled (see “Modes”).


        **Scoring & ordering**

        - Backend computes `grossScore` (raw similarity) and `score`
        (penalty-adjusted). 101% matches retain their priority even after
        penalties.

        - Ordering priority (per downstream service): `score DESC`, `grossScore
        DESC`, context match priority DESC, segment key ASC, TM priority ASC,
        timestamp DESC, TU id DESC.

        - Numeric replacements or uppercase normalization are not performed here
        (`replaceFigures=false`, `modifyTransText=false` in this controller).


        **Limits & behavior**

        - Returns maximum 15 matches; there is no `offset` or `totalFoundCount`.

        - Threshold is fixed to `0`, so all results above penalties are returned
        until limit.

        - Multiple target locales per TM are not supported, mirroring backend
        validation.

        - Logical operators (AND/OR/NOT) and wildcard expressions in `query` are
        interpreted only when `phraseQuery=true` enables the wildcard path.


        **Context & caching notes**

        - Downstream service may consult its 60-second cache for identical
        search inputs (including context and penalties). Freshly imported
        matches might appear with a short delay if cached results are reused.

        - If previous/next segments are omitted the search still runs, but 101%
        context boosts cannot trigger.


        **Error handling**

        - Invalid locales, blank `query`, or an inaccessible TM ID return
        `400`/`403`.

        - Backend may throw when multiple target locales are submitted for a
        single TM; the controller surfaces that error unchanged.
      operationId: search
      parameters:
        - name: transMemoryUid
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SearchRequestDtoV1'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResponseListTmDtoV1'
        '400':
          description: Bad request
        '401':
          description: Not authorized
        '403':
          description: Forbidden
        '404':
          description: Resource not found
        '405':
          description: Method not allowed
        '408':
          description: Timeout
        '410':
          description: Gone
        '415':
          description: Unsupported media type
        '429':
          description: Too many requests
        '500':
          description: Internal server error
        '501':
          description: Not implemented
components:
  schemas:
    SearchRequestDtoV1:
      type: object
      required:
        - query
        - sourceLang
      properties:
        nextSegment:
          type: string
        phraseQuery:
          type: boolean
          description: 'Return both wildcard and exact search results. Default: true'
        previousSegment:
          type: string
        query:
          type: string
        sourceLang:
          type: string
        tagMetadata:
          type: array
          items:
            $ref: '#/components/schemas/TagMetadataDtoV1'
        targetLangs:
          type: array
          items:
            type: string
        trimQuery:
          type: boolean
          description: 'Remove leading and trailing whitespace from query. Default: true'
    SearchResponseListTmDtoV1:
      type: object
      properties:
        searchResults:
          type: array
          items:
            $ref: '#/components/schemas/SearchTMResponseDtoV1'
    TagMetadataDtoV1:
      type: object
      properties:
        content:
          type: string
        id:
          type: string
        transAttributes:
          type: string
        type:
          type: string
    SearchTMResponseDtoV1:
      type: object
      properties:
        grossScore:
          type: number
          format: double
        score:
          type: number
          format: double
        segmentId:
          type: string
        source:
          $ref: '#/components/schemas/SearchTMResponseDtoSearchTMSegmentDtoV1'
        subSegment:
          type: boolean
        transMemory:
          $ref: '#/components/schemas/SearchTMResponseDtoSearchTMTransMemoryDtoV1'
        translations:
          type: array
          items:
            $ref: '#/components/schemas/SearchTMResponseDtoSearchTMSegmentDtoV1'
    SearchTMResponseDtoSearchTMSegmentDtoV1:
      type: object
      properties:
        client:
          $ref: '#/components/schemas/SearchTMResponseDtoSearchTMClientDtoV1'
        createdAt:
          type: integer
          format: int64
        createdBy:
          $ref: '#/components/schemas/UserReferenceV1'
        domain:
          $ref: '#/components/schemas/SearchTMResponseDtoSearchTMDomainDtoV1'
        filename:
          type: string
        id:
          type: string
        key:
          type: string
        lang:
          type: string
        modifiedAt:
          type: integer
          format: int64
        modifiedBy:
          $ref: '#/components/schemas/UserReferenceV1'
        nextSegment:
          type: string
        previousSegment:
          type: string
        project:
          $ref: '#/components/schemas/SearchTMResponseDtoSearchTMProjectDtoV1'
        rtl:
          type: boolean
        subDomain:
          $ref: '#/components/schemas/SearchTMResponseDtoSearchTMSubDomainDtoV1'
        tagMetadata:
          type: array
          items:
            $ref: '#/components/schemas/TagMetadata'
        text:
          type: string
    SearchTMResponseDtoSearchTMTransMemoryDtoV1:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        reverse:
          type: boolean
        uid:
          type: string
    SearchTMResponseDtoSearchTMClientDtoV1:
      type: object
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
    UserReferenceV1:
      type: object
      properties:
        email:
          type: string
        firstName:
          type: string
        id:
          type: string
        lastName:
          type: string
        role:
          type: string
          enum:
            - SYS_ADMIN
            - SYS_ADMIN_READ
            - ADMIN
            - PROJECT_MANAGER
            - LINGUIST
            - GUEST
            - SUBMITTER
            - PORTAL_MEMBER
            - BOT
        uid:
          type: string
        userName:
          type: string
    SearchTMResponseDtoSearchTMDomainDtoV1:
      type: object
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
    SearchTMResponseDtoSearchTMProjectDtoV1:
      type: object
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        uid:
          type: string
    SearchTMResponseDtoSearchTMSubDomainDtoV1:
      type: object
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
    TagMetadata:
      type: object
      properties:
        content:
          type: string
        id:
          type: string
        transAttributes:
          type: string
        type:
          type: string
  securitySchemes:
    ApiToken:
      description: >-
        Get a token from `auth/login` [endpoint](#operation/login) and then pass
        it in the `Authorization` HTTP header in every subsequent API call. For
        more information visit our [help
        center](https://support.phrase.com/hc/en-us/articles/5709662181404-API-Authentication-TMS-#token-0-0).
      type: apiKey
      name: Authorization
      in: header
    OAuth2:
      description: >-
        A standard OAuth 2.0 authorization code flow. For more information visit
        our [help
        center](https://support.phrase.com/hc/en-us/articles/5709662181404-API-Authentication-TMS-#oauth-2-0-0-1).
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: https://cloud.memsource.com/web/oauth/authorize
          tokenUrl: https://cloud.memsource.com/web/oauth/token
          scopes: {}

````