Search in sources :

Example 1 with SuggestionResult

use of com.rbmhtechnology.vind.api.result.SuggestionResult in project vind by RBMHTechnology.

the class TestServerTest method testSuggestionFiltering.

@Test
public void testSuggestionFiltering() {
    SearchServer server = testSearchServer.getSearchServer();
    SingleValueFieldDescriptor<String> value = new FieldDescriptorBuilder<String>().setSuggest(true).buildTextField("value");
    DocumentFactory documentFactory = new DocumentFactoryBuilder("doc").setUpdatable(true).addField(value).build();
    server.index(documentFactory.createDoc("1").setValue(value, "hello world"));
    server.commit();
    SuggestionResult suggestionResult = server.execute(Search.suggest("he").addField(value), documentFactory);
    SearchResult searchResult = server.execute(Search.fulltext().filter(eq(value, "hello world")), documentFactory);
    Assert.assertEquals(1, searchResult.getNumOfResults());
}
Also used : SuggestionResult(com.rbmhtechnology.vind.api.result.SuggestionResult) SearchServer(com.rbmhtechnology.vind.api.SearchServer) SearchResult(com.rbmhtechnology.vind.api.result.SearchResult) Test(org.junit.Test)

Example 2 with SuggestionResult

use of com.rbmhtechnology.vind.api.result.SuggestionResult in project vind by RBMHTechnology.

the class SolrSearchServerTest method testExecute.

@Test
public void testExecute() throws Exception {
    Asset asset = new Asset();
    // FIXME: Asset has no @Id field
    server.indexBean(asset);
    // query
    BeanSearchResult<Asset> result = server.execute(Search.fulltext("hello world").filter(eq("category", "test")), Asset.class);
    // suggestion
    SuggestionResult suggestions = server.execute(Search.suggest("he").fields("category"), Asset.class);
    FieldDescriptor<String> title = new FieldDescriptorBuilder().setBoost(2).setLanguage(Language.German).buildTextField("title");
    // complex
    DocumentFactory factory = new DocumentFactoryBuilder("asset").addField(title).build();
    Document document = factory.createDoc("1234");
    server.index(document);
    // suggestion
    SuggestionResult suggestionsFromFactory = server.execute(Search.suggest("he").fields("title"), factory);
}
Also used : DocumentFactory(com.rbmhtechnology.vind.model.DocumentFactory) SuggestionResult(com.rbmhtechnology.vind.api.result.SuggestionResult) Asset(com.rbmhtechnology.vind.solr.backend.utils.Asset) Document(com.rbmhtechnology.vind.api.Document) FieldDescriptorBuilder(com.rbmhtechnology.vind.model.FieldDescriptorBuilder) DocumentFactoryBuilder(com.rbmhtechnology.vind.model.DocumentFactoryBuilder) Test(org.junit.Test)

Example 3 with SuggestionResult

use of com.rbmhtechnology.vind.api.result.SuggestionResult in project vind by RBMHTechnology.

the class SearchApplication method main.

public static void main(String... args) {
    log.info("Building Field-Descriptors");
    final FieldDescriptor<String> title = new FieldDescriptorBuilder().setFullText(true).setSuggest(true).buildTextField("title");
    final MultiValueFieldDescriptor.TextFieldDescriptor<String> category = new FieldDescriptorBuilder().setFullText(false).setSuggest(true).setFacet(true).buildMultivaluedTextField("category");
    log.info("Building DocumentFactory");
    final DocumentFactory news = new DocumentFactoryBuilder("news").addField(title).addField(category).build();
    // get an instance of a server (in this case a embedded solr server)
    try (SearchServer server = SearchServer.getInstance()) {
        final MonitoringWriter writer = new LogWriter();
        final MonitoringSearchServer monitoringSearchServer = new MonitoringSearchServer(server, writer);
        log.info("Indexing some data");
        server.index(news.createDoc("1").setValue(title, "Headline 1").setValues(category, "Sport", "Economic"));
        server.index(news.createDoc("2").setValue(title, "Headline 2").setValues(category, "Arts"));
        server.commit();
        final SuggestionResult fullSuggest = monitoringSearchServer.execute(Search.suggest().fields(title, category), news);
        log.info("Suggestion: {}", fullSuggest.get(title));
        log.info("Suggestion: {}", fullSuggest.get(category));
        final SuggestionResult titleSuggestions = monitoringSearchServer.execute(Search.suggest().text("Ar").fields(title, category), news);
        log.info("Suggestion: {}", titleSuggestions.get(title));
    }
}
Also used : LogWriter(com.rbmhtechnology.vind.monitoring.log.writer.LogWriter) SuggestionResult(com.rbmhtechnology.vind.api.result.SuggestionResult) MonitoringSearchServer(com.rbmhtechnology.vind.monitoring.MonitoringSearchServer) MonitoringWriter(com.rbmhtechnology.vind.monitoring.logger.MonitoringWriter) MonitoringSearchServer(com.rbmhtechnology.vind.monitoring.MonitoringSearchServer) SearchServer(com.rbmhtechnology.vind.api.SearchServer)

Example 4 with SuggestionResult

use of com.rbmhtechnology.vind.api.result.SuggestionResult in project vind by RBMHTechnology.

the class SearchApplication method main.

public static void main(String[] args) {
    // get an instance of a server (in this case a embedded solr server)
    SearchServer server = SearchServer.getInstance();
    final MonitoringWriter writer = new LogWriter();
    final InterfaceApplication application = new InterfaceApplication("Application name", "0.0.0", new Interface("sugar-love", "0.0.0"));
    final MonitoringSearchServer monitoringSearchServer = new MonitoringSearchServer(server, application, writer);
    monitoringSearchServer.setSession(new UserSession("session-ID-1234567", new User("user 2", "user-ID-2")));
    // index 2 news items
    NewsItem i1 = new NewsItem("1", "New Vind instance needed", ZonedDateTime.now().minusMonths(3), "article", "coding");
    NewsItem i2 = new NewsItem("2", "Vind instance available", ZonedDateTime.now(), "blog", "coding", "release");
    server.indexBean(i1);
    server.indexBean(i2);
    server.commit();
    // this search should retrieve news items that should match the search term best
    FulltextSearch search = Search.fulltext("vind release");
    BeanSearchResult<NewsItem> result = monitoringSearchServer.execute(search, NewsItem.class);
    // lets log the results
    System.out.println("\n--- Search 1: Fulltext ---");
    result.getResults().forEach(System.out::println);
    System.out.println();
    // now we want to have also the facets for category and kind.
    // additionally we change the query
    search.text("vind");
    search.facet("category", "kind");
    result = monitoringSearchServer.execute(search, NewsItem.class);
    System.out.println("\n--- Search 2.1: Category Facets ---");
    result.getFacetResults().getTermFacet("category", String.class).getValues().forEach(System.out::println);
    System.out.println();
    System.out.println("--- Search 2.2: Kind Facets ---");
    result.getFacetResults().getTermFacet("kind", String.class).getValues().forEach(System.out::println);
    System.out.println();
    monitoringSearchServer.setSession(new UserSession("session-ID-12345678", new User("user 3", "user-ID-3")));
    // new we define a search order based on the 'created ' field
    search.sort(desc("created"));
    result = monitoringSearchServer.execute(search, NewsItem.class);
    System.out.println("\n--- Search 3: Sort by created descending ---");
    result.getResults().forEach(System.out::println);
    System.out.println();
    // now we want to filter for all items with the kind 'blog'.
    result = monitoringSearchServer.execute(Search.fulltext().filter(eq("kind", "blog")), NewsItem.class);
    System.out.println("\n--- Search 4: Filtered by kind=blog ---");
    result.getResults().forEach(System.out::println);
    System.out.println();
    // this search should retrieve news items
    // we set the page to 1 and the pagesize to 1
    result = monitoringSearchServer.execute(Search.fulltext().page(1, 1), NewsItem.class);
    // lets log the results
    System.out.println("\n--- Search 5.1: Paging (Page 1) ---");
    result.getResults().forEach(System.out::println);
    System.out.println();
    // the result itself supports paging, so we can loop the pages
    while (((BeanPageResult) result).hasNextPage()) {
        result = ((BeanPageResult) result).nextPage();
        System.out.println("\n--- Search 5.2: Paging (Page " + ((BeanPageResult) result).getPage() + ") ---");
        result.getResults().forEach(System.out::println);
        System.out.println();
    }
    // suggest
    SuggestionResult suggestions = monitoringSearchServer.execute(Search.suggest("c").fields("category"), NewsItem.class);
    System.out.println("\n--- Suggestions: ---");
    System.out.println(suggestions.get("category").getValues());
    System.out.println();
    // close the server
    server.close();
}
Also used : InterfaceApplication(com.rbmhtechnology.vind.monitoring.model.application.InterfaceApplication) User(com.rbmhtechnology.vind.monitoring.model.user.User) MonitoringSearchServer(com.rbmhtechnology.vind.monitoring.MonitoringSearchServer) MonitoringSearchServer(com.rbmhtechnology.vind.monitoring.MonitoringSearchServer) SearchServer(com.rbmhtechnology.vind.api.SearchServer) BeanPageResult(com.rbmhtechnology.vind.api.result.BeanPageResult) LogWriter(com.rbmhtechnology.vind.monitoring.log.writer.LogWriter) SuggestionResult(com.rbmhtechnology.vind.api.result.SuggestionResult) MonitoringWriter(com.rbmhtechnology.vind.monitoring.logger.MonitoringWriter) UserSession(com.rbmhtechnology.vind.monitoring.model.session.UserSession) Interface(com.rbmhtechnology.vind.monitoring.model.Interface.Interface) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) NewsItem(com.rbmhtechnology.vind.demo.step2.model.NewsItem)

Example 5 with SuggestionResult

use of com.rbmhtechnology.vind.api.result.SuggestionResult in project vind by RBMHTechnology.

the class SuggestionSearchIT method childrenSuggestionTest.

@Test
public void childrenSuggestionTest() {
    SuggestionResult suggestionSearch = server.execute(Search.suggest("gree").fields(child_value), parent, child);
    assertEquals(1, suggestionSearch.get(child_value).getValues().size());
    assertEquals("green", suggestionSearch.get(child_value).getValues().get(0).getValue());
    assertEquals(1, suggestionSearch.get(child_value).getValues().get(0).getCount());
    suggestionSearch = server.execute(Search.suggest("blu").fields(child_value), parent, child);
    assertEquals(1, suggestionSearch.get(child_value).getValues().size());
    assertEquals("blue", suggestionSearch.get(child_value).getValues().get(0).getValue());
    assertEquals(2, suggestionSearch.get(child_value).getValues().get(0).getCount());
    suggestionSearch = server.execute(Search.suggest("blu").fields(parent_value), parent, child);
    assertEquals(1, suggestionSearch.get(parent_value).getValues().size());
    assertEquals("blue", suggestionSearch.get(parent_value).getValues().get(0).getValue());
    assertEquals(1, suggestionSearch.get(parent_value).getValues().get(0).getCount());
    suggestionSearch = server.execute(Search.suggest("bl").fields(shared_value), parent, child);
    assertEquals(1, suggestionSearch.get(shared_value).getValues().size());
    assertEquals("black", suggestionSearch.get(shared_value).getValues().get(0).getValue());
    assertEquals(3, suggestionSearch.get(shared_value).getValues().get(0).getCount());
    suggestionSearch = server.execute(Search.suggest("bl").fields(shared_value, parent_value), parent, child);
    assertEquals(1, suggestionSearch.get(shared_value).getValues().size());
    assertEquals("black", suggestionSearch.get(shared_value).getValues().get(0).getValue());
    assertEquals(3, suggestionSearch.get(shared_value).getValues().get(0).getCount());
    assertEquals(2, suggestionSearch.get(parent_value).getValues().size());
    assertEquals("black", suggestionSearch.get(parent_value).getValues().get(0).getValue());
    assertEquals(1, suggestionSearch.get(parent_value).getValues().get(0).getCount());
    suggestionSearch = server.execute(Search.suggest("bl").fields(shared_value, parent_value).filter(Filter.eq(parent_value, "orange")), parent, child);
    assertEquals(1, suggestionSearch.get(shared_value).getValues().size());
    assertEquals("black", suggestionSearch.get(shared_value).getValues().get(0).getValue());
    assertEquals(2, suggestionSearch.get(shared_value).getValues().get(0).getCount());
}
Also used : SuggestionResult(com.rbmhtechnology.vind.api.result.SuggestionResult) Test(org.junit.Test)

Aggregations

SuggestionResult (com.rbmhtechnology.vind.api.result.SuggestionResult)9 SearchServer (com.rbmhtechnology.vind.api.SearchServer)7 Test (org.junit.Test)7 Document (com.rbmhtechnology.vind.api.Document)4 FulltextSearch (com.rbmhtechnology.vind.api.query.FulltextSearch)3 SearchResult (com.rbmhtechnology.vind.api.result.SearchResult)3 SolrInputDocument (org.apache.solr.common.SolrInputDocument)3 Delete (com.rbmhtechnology.vind.api.query.delete.Delete)2 MultiValueFieldDescriptor (com.rbmhtechnology.vind.model.MultiValueFieldDescriptor)2 MonitoringSearchServer (com.rbmhtechnology.vind.monitoring.MonitoringSearchServer)2 LogWriter (com.rbmhtechnology.vind.monitoring.log.writer.LogWriter)2 MonitoringWriter (com.rbmhtechnology.vind.monitoring.logger.MonitoringWriter)2 ZonedDateTime (java.time.ZonedDateTime)2 Language (com.rbmhtechnology.vind.annotations.language.Language)1 Search (com.rbmhtechnology.vind.api.query.Search)1 DateMathExpression (com.rbmhtechnology.vind.api.query.datemath.DateMathExpression)1 TimeUnit (com.rbmhtechnology.vind.api.query.datemath.DateMathExpression.TimeUnit)1 Facets (com.rbmhtechnology.vind.api.query.facet.Facets)1 Interval (com.rbmhtechnology.vind.api.query.facet.Interval)1 Filter (com.rbmhtechnology.vind.api.query.filter.Filter)1