Search in sources :

Example 1 with SearchEntity

use of org.nzbhydra.searching.SearchEntity in project nzbhydra2 by theotherp.

the class History method getSearchDetails.

public SearchDetails getSearchDetails(int searchId) {
    SearchEntity search = searchRepository.findOne(searchId);
    Collection<IndexerSearchEntity> entities = indexerSearchRepository.findBySearchEntity(search);
    List<IndexerSearchTO> details = new ArrayList<>();
    for (IndexerSearchEntity entity : entities) {
        details.add(new IndexerSearchTO(entity.getIndexerEntity().getName(), entity.getSuccessful(), entity.getResultsCount()));
    }
    return new SearchDetails(search.getUsername(), search.getIp(), search.getUserAgent(), search.getSource().name(), details);
}
Also used : IndexerSearchEntity(org.nzbhydra.indexers.IndexerSearchEntity) SearchEntity(org.nzbhydra.searching.SearchEntity) IndexerSearchEntity(org.nzbhydra.indexers.IndexerSearchEntity)

Example 2 with SearchEntity

use of org.nzbhydra.searching.SearchEntity in project nzbhydra2 by theotherp.

the class SearchingResultsUiTest method testRepeatSearch.

@Test
public void testRepeatSearch() throws Exception {
    prepareFiveResultsFromTwoIndexers();
    SearchEntity entity = new SearchEntity();
    entity.setQuery("uitest");
    entity.setCategoryName("All");
    entity.setSource(SearchSource.INTERNAL);
    searchRepository.save(entity);
    webDriver.get(url);
    WebDriverWait wait = new WebDriverWait(webDriver, 10);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("history-dropdown-button")));
    SearchPO searchPO = factory.createPage(SearchPO.class);
    searchPO.historyDropdownButton().click();
    List<org.popper.fw.element.ILink> historyEntries = searchPO.searchHistoryEntries();
    assertThat(historyEntries.size()).isEqualTo(1);
    assertThat(historyEntries.get(0).text()).isEqualTo("Category: All, Query: uitest");
    historyEntries.get(0).click();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("search-results-table")));
    SearchResultsPO searchResultsPage = factory.createPage(SearchResultsPO.class);
    // Only indexer1 was preselected and that's the one used for the repeated search
    assertThat(searchResultsPage.searchResultRows().size()).isEqualTo(3);
    assertThat(searchResultsPage.titles()).containsExactlyInAnyOrder("indexer1-result1", "indexer1-result2", "indexer1-result3");
}
Also used : SearchEntity(org.nzbhydra.searching.SearchEntity) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) NzbhydraMockMvcTest(org.nzbhydra.tests.NzbhydraMockMvcTest) Test(org.junit.Test) AbstractConfigReplacingTest(org.nzbhydra.tests.AbstractConfigReplacingTest)

Example 3 with SearchEntity

use of org.nzbhydra.searching.SearchEntity in project nzbhydra2 by theotherp.

the class ThreadedTest method executeParallelSaves.

@Test
public void executeParallelSaves() throws Exception {
    ExecutorService pool = Executors.newFixedThreadPool(50);
    for (int i = 0; i < 50; i++) {
        pool.execute(() -> {
            Stopwatch stopwatch = Stopwatch.createStarted();
            for (int i1 = 0; i1 < 100; i1++) {
                SearchEntity searchEntity = new SearchEntity();
                searchEntity.setQuery("query");
                searchEntity.setSearchType(SearchType.SEARCH);
                searchEntity.setEpisode("123");
                searchEntity.setSeason(234);
                searchRepository.save(searchEntity);
            }
            System.out.println("Saving 100 took " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + "ms");
        });
    }
    pool.awaitTermination(10, TimeUnit.SECONDS);
}
Also used : SearchEntity(org.nzbhydra.searching.SearchEntity) ExecutorService(java.util.concurrent.ExecutorService) Stopwatch(com.google.common.base.Stopwatch) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with SearchEntity

use of org.nzbhydra.searching.SearchEntity in project nzbhydra2 by theotherp.

the class SqliteMigrationTest method shouldMigrateSearches.

// TODO tests are still for old json based sqlite migration, need to be adapted to actual sqlite access
@Test
@Ignore
public void shouldMigrateSearches() throws Exception {
    String searchesJson = Resources.toString(Resources.getResource(SqliteMigrationTest.class, "searches"), Charsets.UTF_8);
    List<Map<String, Object>> oldSearches = testee.objectMapper.readValue(searchesJson, testee.listOfMapsTypeReference);
    Map<Integer, SearchEntity> searchEntities = testee.migrateSearches();
    assertThat(searchEntities.size(), is(4));
    SearchEntity entityTv = searchEntities.get(3);
    assertThat(entityTv.getAuthor(), is(nullValue()));
    assertThat(entityTv.getUsername(), is(nullValue()));
    assertThat(entityTv.getSeason(), is(1));
    assertThat(entityTv.getEpisode(), is(2));
    assertThat(entityTv.getIdentifiers().size(), is(1));
    IdentifierKeyValuePair keyValuePair = entityTv.getIdentifiers().iterator().next();
    assertThat(keyValuePair.getIdentifierKey(), is(IdType.TVDB.name()));
    assertThat(keyValuePair.getIdentifierValue(), is("456"));
    assertThat(entityTv.getQuery(), is(nullValue()));
    assertThat(entityTv.getSearchType(), is(SearchType.TVSEARCH));
    assertThat(entityTv.getCategoryName(), is("TV"));
    SearchEntity entityAll = searchEntities.get(2);
    assertThat(entityAll.getAuthor(), is(nullValue()));
    assertThat(entityAll.getUsername(), is(nullValue()));
    assertThat(entityAll.getEpisode(), is(nullValue()));
    assertThat(entityAll.getSeason(), is(nullValue()));
    assertThat(entityAll.getIdentifiers(), is(empty()));
    assertThat(entityAll.getQuery(), is("aquery"));
    assertThat(entityAll.getSearchType(), is(SearchType.SEARCH));
    assertThat(entityAll.getCategoryName(), is("All"));
}
Also used : IdentifierKeyValuePair(org.nzbhydra.searching.IdentifierKeyValuePair) SearchEntity(org.nzbhydra.searching.SearchEntity) HashMap(java.util.HashMap) Map(java.util.Map) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with SearchEntity

use of org.nzbhydra.searching.SearchEntity in project nzbhydra2 by theotherp.

the class History method getHistoryForSearching.

public List<SearchEntity> getHistoryForSearching() {
    String currentUserName = SessionStorage.username.get();
    Page<SearchEntity> history = currentUserName == null ? searchRepository.findForUserSearchHistory(new PageRequest(0, 100)) : searchRepository.findForUserSearchHistory(currentUserName, new PageRequest(0, 100));
    List<SearchEntity> entities = new ArrayList<>();
    Set<Integer> contained = new HashSet<>();
    for (SearchEntity searchEntity : history.getContent()) {
        int hash = searchEntity.getComparingHash();
        if (contained.contains(hash)) {
            continue;
        }
        contained.add(hash);
        entities.add(searchEntity);
        if (entities.size() == 15) {
            break;
        }
    }
    return entities;
}
Also used : BigInteger(java.math.BigInteger) PageRequest(org.springframework.data.domain.PageRequest) IndexerSearchEntity(org.nzbhydra.indexers.IndexerSearchEntity) SearchEntity(org.nzbhydra.searching.SearchEntity)

Aggregations

SearchEntity (org.nzbhydra.searching.SearchEntity)5 Test (org.junit.Test)3 IndexerSearchEntity (org.nzbhydra.indexers.IndexerSearchEntity)2 Stopwatch (com.google.common.base.Stopwatch)1 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutorService (java.util.concurrent.ExecutorService)1 Ignore (org.junit.Ignore)1 IdentifierKeyValuePair (org.nzbhydra.searching.IdentifierKeyValuePair)1 AbstractConfigReplacingTest (org.nzbhydra.tests.AbstractConfigReplacingTest)1 NzbhydraMockMvcTest (org.nzbhydra.tests.NzbhydraMockMvcTest)1 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)1 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 PageRequest (org.springframework.data.domain.PageRequest)1