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: SdlSdl.LanguagePlatformTranslationMemory
Assembly: Sdl.LanguagePlatform.TranslationMemory.dll
Syntax
[DataContract]
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 |
---|---|
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 |
---|---|
string |
Properties
Count
Gets the number of results in this instance.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
DocumentPlaceables
Gets or sets the source segment placeables. The value is usually set by the search engine.
Declaration
[DataMember]
public List<Placeable> DocumentPlaceables { get; set; }
Property Value
Type | Description |
---|---|
ListPlaceable |
this[int]
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 |
---|---|---|
int | 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
[DataMember]
public bool MultipleTranslations { get; set; }
Property Value
Type | Description |
---|---|
bool |
Results
Gets or sets the sesarch results.
Declaration
[DataMember]
public List<SearchResult> Results { get; set; }
Property Value
Type | Description |
---|---|
ListSearchResult |
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
[DataMember]
public SortSpecification SortOrder { get; set; }
Property Value
Type | Description |
---|---|
SortSpecification |
SourceHash
Gets or sets the source segment's hash value.
Declaration
[DataMember]
public long SourceHash { get; set; }
Property Value
Type | Description |
---|---|
long |
SourceSegment
Gets or sets the document source segment for this instance. The value is set by the search engine.
Declaration
[DataMember]
public Segment SourceSegment { get; set; }
Property Value
Type | Description |
---|---|
Segment |
SourceWordCounts
Gets or sets the source word counts for this instance.
Declaration
[DataMember]
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 |
---|---|
bool | whether search results are equal |
Cap(int)
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 |
---|---|---|
int | 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 | |
ListSearchResult | searchResults |
Clear()
Removes all results.
Declaration
public void Clear()
CopyFrom(SearchResults)
Declaration
protected void CopyFrom(SearchResults r)
Parameters
Type | Name | Description |
---|---|---|
SearchResults | r |
HasTuId(int)
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 |
---|---|---|
int | id |
Returns
Type | Description |
---|---|
bool |
Merge(SearchResults, bool)
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. |
bool | 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<bool>, 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, bool) 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, bool) calls have been performed.
Declaration
public static void PostMergeFixup(IEnumerable<SearchResults> searchResultsPerSegment, IEnumerable<bool> searchMask, SearchSettings settings)
Parameters
Type | Name | Description |
---|---|---|
IEnumerableSearchResults | searchResultsPerSegment | The ordered list of SearchResults, one per document segment (including possible null values e.g. for masked segments) |
IEnumerablebool | searchMask | Any mask used when performing the search over document segments |
SearchSettings | settings | The settings used for performing the search |
Remarks
RemoveAll(Func<SearchResult, bool>)
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 |
---|---|---|
FuncSearchResultbool | predicate | the predicate to use |
Returns
Type | Description |
---|---|
int |
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 |
---|---|---|
FuncSearchResultSearchResultSearchResult | 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, 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. |
SearchResultsSearchResultComparer | 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 |
---|---|---|
string | sortOrder | The sort order, in its string representation. If null, the default sort order will be used. |