Search in sources :

Example 11 with DocumentFactory

use of com.rbmhtechnology.vind.model.DocumentFactory in project vind by RBMHTechnology.

the class SolrSearchServerTest method testExecuteReal.

// is ignored because tests (and therefor requires) a remote solr server
@Test
@Ignore
public void testExecuteReal() throws Exception {
    SearchConfiguration.set(SearchConfiguration.SERVER_HOST, "http://localhost:8983/solr/searchindex");
    SearchServer server = SearchServer.getInstance();
    FieldDescriptor<String> title = new FieldDescriptorBuilder().setBoost(2).setLanguage(Language.German).buildTextField("title");
    DocumentFactory factory = new DocumentFactoryBuilder("asset").addField(title).build();
    server.index(factory.createDoc("1").setValue(title, "Hello World"));
    server.commit();
    assertEquals(1, server.execute(Search.fulltext(), factory).getNumOfResults());
}
Also used : DocumentFactory(com.rbmhtechnology.vind.model.DocumentFactory) SolrSearchServer(com.rbmhtechnology.vind.solr.backend.SolrSearchServer) SearchServer(com.rbmhtechnology.vind.api.SearchServer) FieldDescriptorBuilder(com.rbmhtechnology.vind.model.FieldDescriptorBuilder) DocumentFactoryBuilder(com.rbmhtechnology.vind.model.DocumentFactoryBuilder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 12 with DocumentFactory

use of com.rbmhtechnology.vind.model.DocumentFactory in project vind by RBMHTechnology.

the class SuggestionTest method testSpellcheck.

@Test
public void testSpellcheck() {
    SolrClient client = Mockito.mock(SolrClient.class);
    SolrSearchServer server = new SolrSearchServer(client, false);
    FieldDescriptor descriptor = Mockito.mock(FieldDescriptor.class);
    when(descriptor.getType()).thenReturn(String.class);
    when(descriptor.isSuggest()).thenReturn(true);
    DocumentFactory factory = Mockito.mock(DocumentFactory.class);
    when(factory.getField(any())).thenReturn(descriptor);
    ExecutableSuggestionSearch search = Search.suggest("abc").fields("field");
    SolrQuery query = server.buildSolrQuery(search, factory, null);
    assertEquals("abc", query.get("q"));
    assertEquals("dynamic_single_suggest_string_null", query.get("suggestion.field"));
    assertEquals(SolrSearchServer.SUGGESTION_DF_FIELD, query.get("suggestion.df"));
    assertEquals("10", query.get("suggestion.limit"));
    search.setLimit(100);
    query = server.buildSolrQuery(search, factory, null);
    assertEquals("100", query.get("suggestion.limit"));
    ExecutableSuggestionSearch search2 = Search.suggest("abc").fields(descriptor).clearFilter();
    query = server.buildSolrQuery(search2, factory, null);
    assertEquals("10", query.get("suggestion.limit"));
}
Also used : DocumentFactory(com.rbmhtechnology.vind.model.DocumentFactory) SolrClient(org.apache.solr.client.solrj.SolrClient) SolrSearchServer(com.rbmhtechnology.vind.solr.backend.SolrSearchServer) ExecutableSuggestionSearch(com.rbmhtechnology.vind.api.query.suggestion.ExecutableSuggestionSearch) SolrQuery(org.apache.solr.client.solrj.SolrQuery) FieldDescriptor(com.rbmhtechnology.vind.model.FieldDescriptor) Test(org.junit.Test)

Example 13 with DocumentFactory

use of com.rbmhtechnology.vind.model.DocumentFactory in project vind by RBMHTechnology.

the class MonitoringSearchServerTest method testSuggestionQueryMonitoringWithSessionAndLogger.

@Test
public void testSuggestionQueryMonitoringWithSessionAndLogger() throws IOException {
    TestMonitoringWriter logger = new TestMonitoringWriter();
    MonitoringSearchServer server = new MonitoringSearchServer(testSearchServer.getSearchServer(), new SimpleApplication("app"), new SimpleSession("123"), logger);
    final SingleValueFieldDescriptor.TextFieldDescriptor<String> textField = new FieldDescriptorBuilder<String>().setFacet(true).buildTextField("textField");
    final DocumentFactory factory = new DocumentFactoryBuilder("asset").addField(textField).build();
    server.execute(Search.fulltext(), factory);
    server.setSession(new SimpleSession("456"));
    server.execute(Search.fulltext("Hello World").filter(or(eq(textField, "testFilter"), not(prefix("textField", "pref")))).facet(textField).sort(Sort.desc(textField)), factory);
    // logger.logs.get(1).toJson();
    assertEquals(2, logger.logs.size());
    assertEquals("app", ((SimpleApplication) logger.logs.get(0).getApplication()).getId());
    assertEquals("123", logger.logs.get(0).getSession().getSessionId());
    assertEquals("*", ((FullTextEntry) logger.logs.get(0)).getRequest().getQuery());
    assertEquals("456", logger.logs.get(1).getSession().getSessionId());
    assertEquals("*", ((FullTextEntry) logger.logs.get(0)).getRequest().getQuery());
}
Also used : FullTextEntry(com.rbmhtechnology.vind.monitoring.logger.entry.FullTextEntry) DocumentFactory(com.rbmhtechnology.vind.model.DocumentFactory) SingleValueFieldDescriptor(com.rbmhtechnology.vind.model.SingleValueFieldDescriptor) SimpleApplication(com.rbmhtechnology.vind.monitoring.model.application.SimpleApplication) SimpleSession(com.rbmhtechnology.vind.monitoring.model.session.SimpleSession) FieldDescriptorBuilder(com.rbmhtechnology.vind.model.FieldDescriptorBuilder) DocumentFactoryBuilder(com.rbmhtechnology.vind.model.DocumentFactoryBuilder) Test(org.junit.Test)

Example 14 with DocumentFactory

use of com.rbmhtechnology.vind.model.DocumentFactory in project vind by RBMHTechnology.

the class SolrSearchServer method getRawQuery.

@Override
public <T> String getRawQuery(ExecutableSuggestionSearch search, Class<T> c) {
    final DocumentFactory factory = AnnotationUtil.createDocumentFactory(c);
    final SolrQuery query = buildSolrQuery(search, factory, null);
    return query.toString();
}
Also used : DocumentFactory(com.rbmhtechnology.vind.model.DocumentFactory) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 15 with DocumentFactory

use of com.rbmhtechnology.vind.model.DocumentFactory in project vind by RBMHTechnology.

the class SolrSearchServer method execute.

@Override
public <T> BeanSearchResult<T> execute(FulltextSearch search, Class<T> c) {
    final DocumentFactory factory = AnnotationUtil.createDocumentFactory(c);
    final SearchResult docResult = this.execute(search, factory);
    return docResult.toPojoResult(docResult, c);
}
Also used : DocumentFactory(com.rbmhtechnology.vind.model.DocumentFactory)

Aggregations

DocumentFactory (com.rbmhtechnology.vind.model.DocumentFactory)15 SolrQuery (org.apache.solr.client.solrj.SolrQuery)8 Document (com.rbmhtechnology.vind.api.Document)7 SolrClient (org.apache.solr.client.solrj.SolrClient)6 Test (org.junit.Test)6 SearchServer (com.rbmhtechnology.vind.api.SearchServer)5 ExecutableSuggestionSearch (com.rbmhtechnology.vind.api.query.suggestion.ExecutableSuggestionSearch)5 FieldDescriptor (com.rbmhtechnology.vind.model.FieldDescriptor)5 Resources (com.google.common.io.Resources)4 SearchServerException (com.rbmhtechnology.vind.SearchServerException)4 AnnotationUtil (com.rbmhtechnology.vind.annotations.AnnotationUtil)4 ServiceProvider (com.rbmhtechnology.vind.api.ServiceProvider)4 com.rbmhtechnology.vind.api.query (com.rbmhtechnology.vind.api.query)4 Delete (com.rbmhtechnology.vind.api.query.delete.Delete)4 Page (com.rbmhtechnology.vind.api.query.division.Page)4 Slice (com.rbmhtechnology.vind.api.query.division.Slice)4 Facet (com.rbmhtechnology.vind.api.query.facet.Facet)4 Interval (com.rbmhtechnology.vind.api.query.facet.Interval)4 RealTimeGet (com.rbmhtechnology.vind.api.query.get.RealTimeGet)4 DescriptorSuggestionSearch (com.rbmhtechnology.vind.api.query.suggestion.DescriptorSuggestionSearch)4