Class SearchResults
Represents a set of results returned by the translation memory after a search operation for a given input (segment/translation unit/string).
Inherited Members
Namespace: Sdl.LanguagePlatform.TranslationMemory
Assembly: Sdl.LanguagePlatform.TranslationMemory.dll
Syntax
public class SearchResults : IEnumerable<SearchResult>, IEnumerable
Constructors
SearchResults()
Initializes a new instance with default values.
Declaration
public SearchResults()
SearchResults(SortSpecification)
Initializes a new instance with the specified sort order.
Declaration
public SearchResults(SortSpecification defaultSortOrder)
Parameters
Type | Name | Description |
---|---|---|
SortSpecification | defaultSortOrder | The default sort order. |
Fields
DefaultSortOrder
The default sort order, in string representation, for normal searches. The primary sort key is the score (descending), the secondary sort key is the use count (descending), and the tertiary sort key is the use date (descending).
Declaration
public static readonly string DefaultSortOrder
Field Value
Type | Description |
---|---|
System.String |
DefaultSortOrderConcordance
The default sort order, in string representation, for concordance searches. The primary sort key is the score (descending), the secondary sort key is the change date (descending), and the tertiary sort key is the use count (descending).
Declaration
public static readonly string DefaultSortOrderConcordance
Field Value
Type | Description |
---|---|
System.String |
Properties
Count
Gets the number of results in this instance.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
DocumentPlaceables
Gets or sets the source segment placeables. The value is usually set by the search engine.
Declaration
public List<Placeable> DocumentPlaceables { get; set; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.List<Placeable> |
Item[Int32]
Gets or sets the search results at the specified index in the collection.
Declaration
public SearchResult this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index. |
Property Value
Type | Description |
---|---|
SearchResult | The SearchResult at the specified index. |
MultipleTranslations
Gets or sets the flag whether there exist multiple exact matches in the result set. Note that there also is a MultipleTranslationsPenalty in each match result. However, the penalty will only be set if the malus is > 0, but the MultipleTrnaslations flag will be set independently.
Declaration
public bool MultipleTranslations { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Results
Gets or sets the sesarch results.
Declaration
public List<SearchResult> Results { get; set; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.List<SearchResult> |
SortOrder
Gets or sets the sort order. The search results are not re-sorted if this field is set. To re-sort, call Sort() after setting the value.
Declaration
public SortSpecification SortOrder { get; set; }
Property Value
Type | Description |
---|---|
SortSpecification |
SourceHash
Gets or sets the source segment's hash value.
Declaration
public long SourceHash { get; set; }
Property Value
Type | Description |
---|---|
System.Int64 |
SourceSegment
Gets or sets the document source segment for this instance. The value is set by the search engine.
Declaration
public Segment SourceSegment { get; set; }
Property Value
Type | Description |
---|---|
Segment |
SourceWordCounts
Gets or sets the source word counts for this instance.
Declaration
public WordCounts SourceWordCounts { get; set; }
Property Value
Type | Description |
---|---|
WordCounts |
Methods
Add(SearchResult)
Adds a new search result to the collection.
Declaration
public virtual void Add(SearchResult result)
Parameters
Type | Name | Description |
---|---|---|
SearchResult | result |
AreEqual(SearchResult, SearchResult)
Determines whether two search results are equal, by comparing the segments of the memory translation units.
Declaration
public static bool AreEqual(SearchResult result1, SearchResult result2)
Parameters
Type | Name | Description |
---|---|---|
SearchResult | result1 | result1 |
SearchResult | result2 | results2 |
Returns
Type | Description |
---|---|
System.Boolean | whether search results are equal |
Cap(Int32)
Caps the number of search results to at most maxCapacity
elements. If the object holds
less than the maximum number, this method has no effect.
Declaration
public void Cap(int maxCapacity)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | maxCapacity |
CheckForMultipleTranslations(SearchSettings)
Count the number of exact matches in the result and set the MultipleTranslations flag and penalty accordingly. This is only valid for normal searches; nothing will be changed for concordance searches.
Declaration
public void CheckForMultipleTranslations(SearchSettings settings)
Parameters
Type | Name | Description |
---|---|---|
SearchSettings | settings |
CheckForMultipleTranslations(SearchSettings, List<SearchResult>)
Count the number of exact matches in the result and set the MultipleTranslations flag and penalty accordingly. This is only valid for normal searches; nothing will be changed for concordance searches.
Declaration
public void CheckForMultipleTranslations(SearchSettings settings, List<SearchResult> searchResults)
Parameters
Type | Name | Description |
---|---|---|
SearchSettings | settings | |
System.Collections.Generic.List<SearchResult> | searchResults |
Clear()
Removes all results.
Declaration
public void Clear()
CopyFrom(SearchResults)
Declaration
protected void CopyFrom(SearchResults r)
Parameters
Type | Name | Description |
---|---|---|
SearchResults | r |
HasTuId(Int32)
Returns true if any SearchResult in Results has a MemoryTranslationUnit whose ID matches the one provided
Declaration
public bool HasTuId(int id)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id |
Returns
Type | Description |
---|---|
System.Boolean |
Merge(SearchResults, Boolean)
Appends addtional search results to the current list of search results. Note that other fields, such as the source tokens or the source word count, are not merged (although they may differ for cross-TM searches).
Declaration
public void Merge(SearchResults other, bool removeDuplicates)
Parameters
Type | Name | Description |
---|---|---|
SearchResults | other | The search results to merge with the current results. |
System.Boolean | removeDuplicates | If true, a heuristics is applied to remove duplicates. The original sort order is preserved, but the multiple translations information is re-evaluated. |
PostMergeFixup(IEnumerable<SearchResults>, IEnumerable<Boolean>, SearchSettings)
When a search is performed on a batch of document segments for a single TM, TM search logic deals with any logic spanning multiple segments, e.g. context match rules. However, when results from multiple TMs are merged together, Merge(SearchResults, Boolean) is generally used, once per document segment, which does not allow for that logic to be applied. This function should be used on a list of document segment SearchResults once all Merge(SearchResults, Boolean) calls have been performed.
Declaration
public static void PostMergeFixup(IEnumerable<SearchResults> searchResultsPerSegment, IEnumerable<bool> searchMask, SearchSettings settings)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<SearchResults> | searchResultsPerSegment | The ordered list of SearchResults, one per document segment (including possible null values e.g. for masked segments) |
System.Collections.Generic.IEnumerable<System.Boolean> | searchMask | Any mask used when performing the search over document segments |
SearchSettings | settings | The settings used for performing the search |
Remarks
RemoveAll(Func<SearchResult, Boolean>)
Removes all the elements that match the condition defined by the specified predicate
Declaration
public int RemoveAll(Func<SearchResult, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
System.Func<SearchResult, System.Boolean> | predicate | the predicate to use |
Returns
Type | Description |
---|---|
System.Int32 |
RemoveDuplicates()
Removes any duplicate search results. The duplicate with the lowest index is kept, and other duplicates are removed.
Declaration
public void RemoveDuplicates()
RemoveDuplicates(Func<SearchResult, SearchResult, SearchResult>)
Removes any duplicate search results.
Declaration
public void RemoveDuplicates(Func<SearchResult, SearchResult, SearchResult> GetSearchResultToRemove)
Parameters
Type | Name | Description |
---|---|---|
System.Func<SearchResult, SearchResult, SearchResult> | GetSearchResultToRemove | determines which search result to remove; null should be passed if neither search result should be removed |
Sort()
Sorts the results in this instance using the currently set sort order (see SortOrder), or the default sort order if no sort order is set.
Declaration
public void Sort()
Sort(SortSpecification)
Sorts the results in this instance based on the specified sort order.
Declaration
public void Sort(SortSpecification sortOrder)
Parameters
Type | Name | Description |
---|---|---|
SortSpecification | sortOrder | The sort order. If null, the default sort order will be used. |
Sort(SortSpecification, SearchResults.SearchResultComparer)
Sorts the results in this instance based on the specified sort order.
Declaration
public void Sort(SortSpecification sortOrder, SearchResults.SearchResultComparer disambiguator)
Parameters
Type | Name | Description |
---|---|---|
SortSpecification | sortOrder | The sort order. If null, the default sort order will be used. |
SearchResults.SearchResultComparer | disambiguator | An optional, caller-defined delegate which will be called to disambiguate the sort order of two search results in case their sort order is not fully determined by the normal sort criteria. |
Sort(String)
Sorts the results in this instance based on the specified sort order.
Declaration
public void Sort(string sortOrder)
Parameters
Type | Name | Description |
---|---|---|
System.String | sortOrder | The sort order, in its string representation. If null, the default sort order will be used. |
Explicit Interface Implementations
IEnumerable<SearchResult>.GetEnumerator()
Returns an enumerator to iterate through the list of search results.
Declaration
IEnumerator<SearchResult> IEnumerable<SearchResult>.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<SearchResult> |
IEnumerable.GetEnumerator()
Returns an enumerator to iterate through the list of search results.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator |