| 1767 | } |
| 1768 | |
| 1769 | void Geocoder::EmitResult(BaseContext & ctx, FeatureID const & id, Model::Type type, TokenRange const & tokenRange, |
| 1770 | IntersectionResult const * geoParts, bool allTokensUsed, bool exactMatch) |
| 1771 | { |
| 1772 | double matchedFraction = 1.0; |
| 1773 | // For categorial requests |allTokensUsed| == true and matchedFraction can not be calculated from |ctx|. |
| 1774 | if (!allTokensUsed) |
| 1775 | { |
| 1776 | size_t length = 0; |
| 1777 | size_t matchedLength = 0; |
| 1778 | size_t const numTokens = ctx.NumTokens(); |
| 1779 | TokenSlice slice(m_params, TokenRange(0, numTokens)); |
| 1780 | for (size_t tokenIdx = 0; tokenIdx < numTokens; ++tokenIdx) |
| 1781 | { |
| 1782 | auto const tokenLength = slice.Get(tokenIdx).GetOriginal().size(); |
| 1783 | length += tokenLength; |
| 1784 | if (ctx.IsTokenUsed(tokenIdx)) |
| 1785 | matchedLength += tokenLength; |
| 1786 | } |
| 1787 | CHECK_NOT_EQUAL(length, 0, ()); |
| 1788 | |
| 1789 | matchedFraction = static_cast<double>(matchedLength) / static_cast<double>(length); |
| 1790 | } |
| 1791 | |
| 1792 | // In our samples the least value for matched fraction for relevant result is 0.116. |
| 1793 | // It is "Горнолыжный комплекс Ключи" feature for "Спортивно стрелковый комплекс Ключи |
| 1794 | // Новосибирск" query. It is relevant not found result (search does not find it, but it's |
| 1795 | // relevant). The least matched fraction for found relevant result is 0.241935, for found vital |
| 1796 | // result is 0.269231. |
| 1797 | if (matchedFraction <= 0.1) |
| 1798 | return; |
| 1799 | |
| 1800 | if (m_params.m_tracer) |
| 1801 | TraceResult(*m_params.m_tracer, ctx, id.m_mwmId, id.m_index, type, tokenRange); |
| 1802 | |
| 1803 | // Distance and rank will be filled at the end, for all results at once. |
| 1804 | // |
| 1805 | // TODO (@y, @m): need to skip zero rank features that are too |
| 1806 | // distant from the pivot when there are enough results close to the |
| 1807 | // pivot. |
| 1808 | PreRankingInfo info(type, tokenRange); |
| 1809 | |
| 1810 | info.m_isCommonMatchOnly = true; |
| 1811 | for (size_t i : tokenRange) |
| 1812 | { |
| 1813 | if (!m_params.IsCommonToken(i)) |
| 1814 | { |
| 1815 | info.m_isCommonMatchOnly = false; |
| 1816 | break; |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | for (auto const & layer : ctx.m_layers) |
| 1821 | info.m_tokenRanges[layer.m_type] = layer.m_tokenRange; |
| 1822 | |
| 1823 | for (auto const * region : ctx.m_regions) |
| 1824 | { |
| 1825 | auto const regionType = Region::ToModelType(region->m_type); |
| 1826 | ASSERT_NOT_EQUAL(regionType, Model::TYPE_COUNT, ()); |
nothing calls this directly
no test coverage detected