コード例 #1
0
ファイル: processor_test.cpp プロジェクト: hendrowa/omim
UNIT_CLASS_TEST(ProcessorTest, DisableSuggests)
{
  TestCity london1(m2::PointD(1, 1), "London", "en", 100 /* rank */);
  TestCity london2(m2::PointD(-1, -1), "London", "en", 100 /* rank */);

  auto worldId = BuildWorld([&](TestMwmBuilder & builder)
                            {
                              builder.Add(london1);
                              builder.Add(london2);
                            });

  SetViewport(m2::RectD(m2::PointD(0.5, 0.5), m2::PointD(1.5, 1.5)));
  {
    SearchParams params;
    params.m_query = "londo";
    params.m_inputLocale = "en";
    params.SetMode(Mode::World);
    params.SetSuggestsEnabled(false);

    TestSearchRequest request(m_engine, params, m_viewport);
    request.Wait();
    TRules rules = {ExactMatch(worldId, london1), ExactMatch(worldId, london2)};

    TEST(MatchResults(rules, request.Results()), ());
  }
}
コード例 #2
0
ファイル: test_search_request.cpp プロジェクト: 65apps/omim
TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, string const & query,
                                     string const & locale, Mode mode, m2::RectD const & viewport)
{
    SearchParams params;
    params.m_query = query;
    params.m_inputLocale = locale;
    params.SetMode(mode);
    SetUpCallbacks(params);
    engine.Search(params, viewport);
}
コード例 #3
0
ファイル: mediaview.cpp プロジェクト: flaviotordini/minitube
void MediaView::findVideoParts() {
    Video *video = playlistModel->activeVideo();
    if (!video) return;

    QString query = video->getTitle();

    const QLatin1String optionalSpace("\\s*");
    const QLatin1String staticCounterSeparators("[\\/\\-]");
    const QString counterSeparators =
            QLatin1String("( of | ") + tr("of", "Used in video parts, as in '2 of 3'") +
            QLatin1String(" |") + staticCounterSeparators + QLatin1String(")");

    // numbers from 1 to 15
    const QLatin1String counterNumber("([1-9]|1[0-5])");

    // query.remove(QRegExp(counterSeparators + optionalSpace + counterNumber));
    query.remove(QRegExp(counterNumber + optionalSpace + counterSeparators + optionalSpace +
                         counterNumber));
    query.remove(wordRE("pr?t\\.?" + optionalSpace + counterNumber));
    query.remove(wordRE("ep\\.?" + optionalSpace + counterNumber));
    query.remove(wordRE("part" + optionalSpace + counterNumber));
    query.remove(wordRE("episode" + optionalSpace + counterNumber));
    query.remove(wordRE(tr("part", "This is for video parts, as in 'Cool video - part 1'") +
                        optionalSpace + counterNumber));
    query.remove(wordRE(tr("episode", "This is for video parts, as in 'Cool series - episode 1'") +
                        optionalSpace + counterNumber));
    query.remove(QRegExp("[\\(\\)\\[\\]]"));

#define NUMBERS "one|two|three|four|five|six|seven|eight|nine|ten"

    QRegExp englishNumberRE = QRegExp(QLatin1String(".*(") + NUMBERS + ").*", Qt::CaseInsensitive);
    // bool numberAsWords = englishNumberRE.exactMatch(query);
    query.remove(englishNumberRE);

    QRegExp localizedNumberRE =
            QRegExp(QLatin1String(".*(") + tr(NUMBERS) + ").*", Qt::CaseInsensitive);
    // if (!numberAsWords) numberAsWords = localizedNumberRE.exactMatch(query);
    query.remove(localizedNumberRE);

    SearchParams *searchParams = new SearchParams();
    searchParams->setTransient(true);
    searchParams->setKeywords(query);
    searchParams->setChannelId(video->getChannelId());

    /*
    if (!numberAsWords) {
        qDebug() << "We don't have number as words";
        // searchParams->setSortBy(SearchParams::SortByNewest);
        // TODO searchParams->setReverseOrder(true);
        // TODO searchParams->setMax(50);
    }
    */

    search(searchParams);
}
コード例 #4
0
ファイル: mediaview.cpp プロジェクト: flaviotordini/minitube
void MediaView::onAuthorPushed(QModelIndex index) {
    Video *video = playlistModel->videoAt(index.row());
    if (!video) return;

    QString channelId = video->getChannelId();
    // if (channelId.isEmpty()) channelId = video->channelTitle();
    if (channelId.isEmpty()) return;

    SearchParams *searchParams = new SearchParams();
    searchParams->setChannelId(channelId);
    searchParams->setSortBy(SearchParams::SortByNewest);

    // go!
    search(searchParams);
}
コード例 #5
0
void SendStatistics(SearchParams const & params, m2::RectD const & viewport, Results const & res)
{
  size_t const kMaxNumResultsToSend = 10;

  size_t const numResultsToSend = min(kMaxNumResultsToSend, res.GetCount());
  string resultString = strings::to_string(numResultsToSend);
  for (size_t i = 0; i < numResultsToSend; ++i)
    resultString.append("\t" + res.GetResult(i).ToStringForStats());

  string posX, posY;
  if (params.IsValidPosition())
  {
    posX = strings::to_string(MercatorBounds::LonToX(params.m_lon));
    posY = strings::to_string(MercatorBounds::LatToY(params.m_lat));
  }

  alohalytics::TStringMap const stats = {
      {"posX", posX},
      {"posY", posY},
      {"viewportMinX", strings::to_string(viewport.minX())},
      {"viewportMinY", strings::to_string(viewport.minY())},
      {"viewportMaxX", strings::to_string(viewport.maxX())},
      {"viewportMaxY", strings::to_string(viewport.maxY())},
      {"query", params.m_query},
      {"locale", params.m_inputLocale},
      {"results", resultString},
  };
  alohalytics::LogEvent("searchEmitResultsAndCoords", stats);
}
コード例 #6
0
ファイル: mediaview.cpp プロジェクト: flaviotordini/minitube
void MediaView::setVideoSource(VideoSource *videoSource, bool addToHistory, bool back) {
    Q_UNUSED(back);
    stopped = false;
    errorTimer->stop();

    // qDebug() << "Adding VideoSource" << videoSource->getName() << videoSource;

    if (addToHistory) {
        int currentIndex = getHistoryIndex();
        if (currentIndex >= 0 && currentIndex < history.size() - 1) {
            while (history.size() > currentIndex + 1) {
                VideoSource *vs = history.takeLast();
                if (!vs->parent()) {
                    qDebug() << "Deleting VideoSource" << vs->getName() << vs;
                    vs->deleteLater();
                }
            }
        }
        history.append(videoSource);
    }

#ifdef APP_EXTRA
    if (history.size() > 1)
        Extra::slideTransition(playlistView->viewport(), playlistView->viewport(), back);
#endif

    playlistModel->setVideoSource(videoSource);

    if (media->state() == Media::StoppedState) {
        QSettings settings;
        if (settings.value("manualplay", false).toBool()) {
            videoAreaWidget->showPickMessage();
        }
    }

    sidebar->showPlaylist();
    sidebar->getRefineSearchWidget()->setSearchParams(getSearchParams());
    sidebar->hideSuggestions();
    sidebar->getHeader()->updateInfo();

    SearchParams *searchParams = getSearchParams();
    bool isChannel = searchParams && !searchParams->channelId().isEmpty();
    playlistView->setClickableAuthors(!isChannel);
}
コード例 #7
0
ファイル: search_engine.cpp プロジェクト: 65apps/omim
void Engine::SetRankPivot(SearchParams const & params, m2::RectD const & viewport,
                          bool viewportSearch, Query & processor)
{
  if (!viewportSearch && params.IsValidPosition())
  {
    m2::PointD const pos = MercatorBounds::FromLatLon(params.m_lat, params.m_lon);
    if (m2::Inflate(viewport, viewport.SizeX() / 4.0, viewport.SizeY() / 4.0).IsPointInside(pos))
    {
      processor.SetRankPivot(pos);
      return;
    }
  }

  processor.SetRankPivot(viewport.Center());
}
コード例 #8
0
ファイル: engine.cpp プロジェクト: rokuz/omim
void Engine::DoSearch(SearchParams const & params, m2::RectD const & viewport,
                      shared_ptr<ProcessorHandle> handle, Processor & processor)
{
  bool const viewportSearch = params.m_mode == Mode::Viewport;

  processor.Reset();
  processor.Init(viewportSearch);
  handle->Attach(processor);
  MY_SCOPE_GUARD(detach, [&handle]
                 {
                   handle->Detach();
                 });

  // Early exit when query processing is cancelled.
  if (processor.IsCancelled())
  {
    Results results;
    results.SetEndMarker(true /* isCancelled */);
    params.m_onResults(results);
    return;
  }

  processor.Search(params, viewport);
}
コード例 #9
0
ファイル: search_engine.cpp プロジェクト: 65apps/omim
void Engine::DoSearch(SearchParams const & params, m2::RectD const & viewport,
                      shared_ptr<QueryHandle> handle, Query & processor)
{
  bool const viewportSearch = params.GetMode() == Mode::Viewport;

  // Initialize query processor.
  processor.Init(viewportSearch);
  handle->Attach(processor);
  MY_SCOPE_GUARD(detach, [&handle] { handle->Detach(); });

  // Early exit when query processing is cancelled.
  if (processor.IsCancelled())
  {
    params.m_onResults(Results::GetEndMarker(true /* isCancelled */));
    return;
  }

  SetRankPivot(params, viewport, viewportSearch, processor);

  if (params.IsValidPosition())
    processor.SetPosition(MercatorBounds::FromLatLon(params.m_lat, params.m_lon));
  else
    processor.SetPosition(viewport.Center());

  processor.SetMode(params.GetMode());
  processor.SetSuggestsEnabled(params.GetSuggestsEnabled());

  // This flag is needed for consistency with old search algorithm
  // only. It will be gone when we remove old search code.
  processor.SetSearchInWorld(true);

  processor.SetInputLocale(params.m_inputLocale);

  ASSERT(!params.m_query.empty(), ());
  processor.SetQuery(params.m_query);

  Results res;

  processor.SearchCoordinates(res);

  try
  {
    if (params.m_onStarted)
      params.m_onStarted();

    processor.SetViewport(viewport, true /* forceUpdate */);
    if (viewportSearch)
      processor.SearchViewportPoints(res);
    else
      processor.Search(res, kResultsCount);

    if (!processor.IsCancelled())
      EmitResults(params, res);
  }
  catch (Query::CancelException const &)
  {
    LOG(LDEBUG, ("Search has been cancelled."));
  }

  if (!viewportSearch && !processor.IsCancelled())
    SendStatistics(params, viewport, res);

  // Emit finish marker to client.
  params.m_onResults(Results::GetEndMarker(processor.IsCancelled()));
}
コード例 #10
0
ファイル: search_engine.cpp プロジェクト: 65apps/omim
void Engine::EmitResults(SearchParams const & params, Results const & res)
{
  params.m_onResults(res);
}
コード例 #11
0
ファイル: cache.cpp プロジェクト: raimarHD/lcec
 // SearchParamsをキャッシュする。
 void Cache::CacheSearchParams(const SearchParams& params) {
   COPY_ARRAY(material_, params.material());
   enable_quiesce_search_ = params.enable_quiesce_search();
   enable_repetition_check_ = params.enable_repetition_check();
   enable_check_extension_ = params.enable_check_extension();
   ybwc_limit_depth_ = params.ybwc_limit_depth();
   ybwc_invalid_moves_ = params.ybwc_invalid_moves();
   enable_aspiration_windows_ = params.enable_aspiration_windows();
   aspiration_windows_limit_depth_ = params.aspiration_windows_limit_depth();
   aspiration_windows_delta_ = params.aspiration_windows_delta();
   enable_see_ = params.enable_see();
   enable_history_ = params.enable_history();
   enable_killer_ = params.enable_killer();
   enable_ttable_ = params.enable_ttable();
   enable_iid_ = params.enable_iid();
   iid_limit_depth_ = params.iid_limit_depth();
   iid_search_depth_ = params.iid_search_depth();
   enable_nmr_ = params.enable_nmr();
   nmr_limit_depth_ = params.nmr_limit_depth();
   nmr_search_reduction_ = params.nmr_search_reduction();
   nmr_reduction_ = params.nmr_reduction();
   enable_probcut_ = params.enable_probcut();
   probcut_limit_depth_ = params.probcut_limit_depth();
   probcut_margin_ = params.probcut_margin();
   probcut_search_reduction_ = params.probcut_search_reduction();
   if (params.enable_history()) {
     enable_history_pruning_ = params.enable_history_pruning();
   } else {
     enable_history_pruning_ = false;
   }
   history_pruning_limit_depth_ = params.history_pruning_limit_depth();
   for (unsigned int num_moves = 0; num_moves < (MAX_CANDIDATES + 1);
   ++num_moves) {
     history_pruning_invalid_moves_[num_moves] =
     Util::GetMax(params.history_pruning_invalid_moves(),
     static_cast<int>(params.history_pruning_move_threshold() * num_moves));
   }
   history_pruning_threshold_ = params.history_pruning_threshold() * 256.0;
   history_pruning_reduction_ = params.history_pruning_reduction();
   enable_lmr_ = params.enable_lmr();
   lmr_limit_depth_ = params.lmr_limit_depth();
   for (unsigned int num_moves = 0; num_moves < (MAX_CANDIDATES + 1);
   ++num_moves) {
     lmr_invalid_moves_[num_moves] = Util::GetMax(params.lmr_invalid_moves(),
     static_cast<int>(params.lmr_move_threshold() * num_moves));
   }
   lmr_search_reduction_ = params.lmr_search_reduction();
   enable_futility_pruning_ = params.enable_futility_pruning();
   futility_pruning_depth_ = params.futility_pruning_depth();
   for (int depth = 0; depth < static_cast<int>(MAX_PLYS + 1); ++depth) {
     if (enable_futility_pruning_) {
       if (depth <= futility_pruning_depth_) {
         if (depth <= 0) {
           futility_pruning_margin_[depth] = params.futility_pruning_margin();
         } else {
           futility_pruning_margin_[depth] =
           params.futility_pruning_margin() * depth;
         }
       } else {
         futility_pruning_margin_[depth] = 3 * SCORE_WIN;
       }
     } else {
       futility_pruning_margin_[depth] = 3 * SCORE_WIN;
     }
   }
 }