Search in sources :

Example 31 with Document

use of com.rbmhtechnology.vind.api.Document in project vind by RBMHTechnology.

the class TestServerTest method supportUnderscoredFieldNamesTest.

// MBDN-452
@Test
public void supportUnderscoredFieldNamesTest() {
    SingleValueFieldDescriptor<Float> numberField = new FieldDescriptorBuilder().buildNumericField("number_one", Float.class);
    FieldDescriptor<String> entityID = new FieldDescriptorBuilder().setLanguage(Language.English).buildTextField("entity_ID");
    SingleValueFieldDescriptor<Date> dateField = new FieldDescriptorBuilder().buildUtilDateField("date_field");
    DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(numberField).addField(dateField).addField(entityID).build();
    Document d1 = assets.createDoc("1").setValue(numberField, 24f).setValue(entityID, "123").setValue(dateField, new Date());
    Document d2 = assets.createDoc("2").setValue(numberField, 2f).setValue(entityID, "123").setValue(dateField, new Date());
    SearchServer server = testSearchServer.getSearchServer();
    server.index(d1);
    server.index(d2);
    server.commit();
    FulltextSearch searchAll = Search.fulltext();
    final SearchResult searchResult = server.execute(searchAll, assets);
    assertEquals("Number of results", 2, searchResult.getNumOfResults());
    assertEquals("Number_one field", 24f, searchResult.getResults().get(0).getValue("number_one"));
}
Also used : SearchServer(com.rbmhtechnology.vind.api.SearchServer) SearchResult(com.rbmhtechnology.vind.api.result.SearchResult) Document(com.rbmhtechnology.vind.api.Document) SolrInputDocument(org.apache.solr.common.SolrInputDocument) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Test(org.junit.Test)

Example 32 with Document

use of com.rbmhtechnology.vind.api.Document in project vind by RBMHTechnology.

the class TestServerTest method testSuggestions.

@Test
public void testSuggestions() {
    SearchServer server = testSearchServer.getSearchServer();
    ZonedDateTime now = ZonedDateTime.now();
    ZonedDateTime yesterday = ZonedDateTime.now().minus(1, ChronoUnit.DAYS);
    FieldDescriptor<String> title = new FieldDescriptorBuilder().setFullText(true).setFacet(true).setSuggest(true).buildTextField("title");
    SingleValueFieldDescriptor.DateFieldDescriptor<ZonedDateTime> created = new FieldDescriptorBuilder().setFacet(true).buildDateField("created");
    NumericFieldDescriptor<Long> category = new FieldDescriptorBuilder().setFacet(true).setSuggest(true).buildMultivaluedNumericField("category", Long.class);
    DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(title).addField(created).addField(category).build();
    Document d1 = assets.createDoc("1").setValue(title, "Hello 4 World").setValue(created, yesterday).setValues(category, Arrays.asList(1L, 2L, 4L));
    Document d2 = assets.createDoc("2").setValue(title, "Hello 4 Friends").setValue(created, now).addValue(category, 4L);
    SuggestionResult emptySuggestion = server.execute(Search.suggest().addField(title).filter(created.before(ZonedDateTime.now().minus(6, ChronoUnit.HOURS))).text("Hel"), assets);
    assertTrue(emptySuggestion.size() == 0);
    server.index(d1);
    server.index(d2);
    server.commit(true);
    SuggestionResult suggestion = server.execute(Search.suggest().fields(title, category).filter(created.before(ZonedDateTime.now().minus(6, ChronoUnit.HOURS))).text("4"), assets);
    assertTrue(suggestion.size() > 0);
    suggestion = server.execute(Search.suggest("helli").fields(title, category), assets);
    assertEquals("hello", suggestion.getSpellcheck());
}
Also used : SearchServer(com.rbmhtechnology.vind.api.SearchServer) Document(com.rbmhtechnology.vind.api.Document) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ZonedDateTime(java.time.ZonedDateTime) SuggestionResult(com.rbmhtechnology.vind.api.result.SuggestionResult) Test(org.junit.Test)

Example 33 with Document

use of com.rbmhtechnology.vind.api.Document in project vind by RBMHTechnology.

the class TestServerTest method binaryFieldTest.

// MBDN-454
@Test
public void binaryFieldTest() {
    FieldDescriptor<String> title = new FieldDescriptorBuilder().setFullText(true).setFacet(true).buildTextField("title");
    SingleValueFieldDescriptor.DateFieldDescriptor<ZonedDateTime> created = new FieldDescriptorBuilder().setFacet(true).buildDateField("created");
    SingleValueFieldDescriptor.UtilDateFieldDescriptor<Date> modified = new FieldDescriptorBuilder().setFacet(true).buildUtilDateField("modified");
    NumericFieldDescriptor<Long> category = new FieldDescriptorBuilder().setFacet(true).buildMultivaluedNumericField("category", Long.class);
    SingleValueFieldDescriptor.BinaryFieldDescriptor<ByteBuffer> byteField = new FieldDescriptorBuilder().setStored(true).buildBinaryField("blob");
    DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(title).addField(created).addField(category).addField(modified).addField(byteField).build();
    Document d1 = assets.createDoc("1").setValue(title, "Hello World").setValue(modified, new Date()).setValue(byteField, ByteBuffer.wrap("ooalalalalala".getBytes())).setValues(category, Arrays.asList(1L, 2L));
    Document d2 = assets.createDoc("2").setValue(title, "Hello Friends").setValue(modified, new Date()).addValue(category, 4L).setValue(byteField, ByteBuffer.wrap("oolelelelele".getBytes()));
    SearchServer server = testSearchServer.getSearchServer();
    server.index(d1);
    server.index(d2);
    server.commit();
    FulltextSearch search = Search.fulltext();
    SearchResult result = server.execute(search, assets);
    assertEquals(2, result.getNumOfResults());
    assertEquals(2, result.getResults().size());
    assertTrue(ByteBuffer.class.isAssignableFrom(result.getResults().get(0).getValue("blob").getClass()));
    assertEquals("ooalalalalala", new String(((ByteBuffer) result.getResults().get(0).getValue("blob")).array()));
}
Also used : SearchServer(com.rbmhtechnology.vind.api.SearchServer) SearchResult(com.rbmhtechnology.vind.api.result.SearchResult) Document(com.rbmhtechnology.vind.api.Document) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ByteBuffer(java.nio.ByteBuffer) ZonedDateTime(java.time.ZonedDateTime) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Test(org.junit.Test)

Example 34 with Document

use of com.rbmhtechnology.vind.api.Document in project vind by RBMHTechnology.

the class TestServerTest method scopedFilterTest.

// MBDN-487
@Test
public void scopedFilterTest() {
    MultiValuedComplexField.TextComplexField<Taxonomy, String, String> multiComplexField = new ComplexFieldDescriptorBuilder<Taxonomy, String, String>().setFacet(true, tx -> Arrays.asList(tx.getLabel())).setStored(true, tx -> tx.getTerm()).setAdvanceFilter(true, tx -> Arrays.asList(tx.getTerm())).buildMultivaluedTextComplexField("multiTextTaxonomy", Taxonomy.class, String.class, String.class);
    SingleValuedComplexField.TextComplexField<Taxonomy, String, String> textComplexField = new ComplexFieldDescriptorBuilder<Taxonomy, String, String>().setFacet(true, tx -> Arrays.asList(tx.getLabel())).setAdvanceFilter(true, tx -> Arrays.asList(tx.getTerm())).buildTextComplexField("textFacetTaxonomy", Taxonomy.class, String.class, String.class);
    DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(textComplexField).addField(multiComplexField).build();
    Document d1 = assets.createDoc("1").setValue(textComplexField, new Taxonomy("uno", 1, "Label", ZonedDateTime.now())).setValues(multiComplexField, new Taxonomy("uno", 1, "Label", ZonedDateTime.now()), new Taxonomy("dos", 2, "Label dos", ZonedDateTime.now()));
    Document d2 = assets.createDoc("2").setValue(textComplexField, new Taxonomy("dos", 2, "Label", ZonedDateTime.now())).setValues(multiComplexField, new Taxonomy("dos . uno", 1, "Label", ZonedDateTime.now()), new Taxonomy("dos . dos", 1, "Label", ZonedDateTime.now()));
    SearchServer server = testSearchServer.getSearchServer();
    server.index(d1);
    server.index(d2);
    server.commit();
    SearchResult result = server.execute(Search.fulltext().filter(textComplexField.equals("uno", Scope.Filter)), assets);
    Assert.assertEquals(1, result.getNumOfResults());
    Assert.assertEquals("1", result.getResults().get(0).getId());
    result = server.execute(Search.fulltext().filter(multiComplexField.equals("uno", Scope.Filter)), assets);
    Assert.assertEquals(1, result.getNumOfResults());
    Assert.assertEquals("1", result.getResults().get(0).getId());
}
Also used : Interval(com.rbmhtechnology.vind.api.query.facet.Interval) PageResult(com.rbmhtechnology.vind.api.result.PageResult) java.util(java.util) Delete(com.rbmhtechnology.vind.api.query.delete.Delete) Matchers.isA(org.hamcrest.Matchers.isA) ZonedDateTime(java.time.ZonedDateTime) Function(java.util.function.Function) ByteBuffer(java.nio.ByteBuffer) SolrServerException(org.apache.solr.client.solrj.SolrServerException) Sort.desc(com.rbmhtechnology.vind.api.query.sort.Sort.desc) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) FacetMapper(com.rbmhtechnology.vind.utils.mam.FacetMapper) Duration(java.time.Duration) NumericFieldDescriptor(com.rbmhtechnology.vind.model.MultiValueFieldDescriptor.NumericFieldDescriptor) DateMathExpression(com.rbmhtechnology.vind.api.query.datemath.DateMathExpression) ExpectedException(org.junit.rules.ExpectedException) SearchServer(com.rbmhtechnology.vind.api.SearchServer) Language(com.rbmhtechnology.vind.annotations.language.Language) TermFacetResult(com.rbmhtechnology.vind.api.result.facet.TermFacetResult) SearchConfiguration(com.rbmhtechnology.vind.configure.SearchConfiguration) Facets(com.rbmhtechnology.vind.api.query.facet.Facets) SearchResult(com.rbmhtechnology.vind.api.result.SearchResult) LatLng(com.rbmhtechnology.vind.model.value.LatLng) RangeFacetResult(com.rbmhtechnology.vind.api.result.facet.RangeFacetResult) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) MultiValueFieldDescriptor(com.rbmhtechnology.vind.model.MultiValueFieldDescriptor) Sort(com.rbmhtechnology.vind.api.query.sort.Sort) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) IOException(java.io.IOException) GetResult(com.rbmhtechnology.vind.api.result.GetResult) com.rbmhtechnology.vind.model(com.rbmhtechnology.vind.model) ZoneId(java.time.ZoneId) Document(com.rbmhtechnology.vind.api.Document) SuggestionResult(com.rbmhtechnology.vind.api.result.SuggestionResult) SolrClient(org.apache.solr.client.solrj.SolrClient) TimeUnit(java.util.concurrent.TimeUnit) TimeUnit(com.rbmhtechnology.vind.api.query.datemath.DateMathExpression.TimeUnit) Search(com.rbmhtechnology.vind.api.query.Search) Rule(org.junit.Rule) ChronoUnit(java.time.temporal.ChronoUnit) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Filter(com.rbmhtechnology.vind.api.query.filter.Filter) Assert(org.junit.Assert) Sort.asc(com.rbmhtechnology.vind.api.query.sort.Sort.asc) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SearchServer(com.rbmhtechnology.vind.api.SearchServer) SearchResult(com.rbmhtechnology.vind.api.result.SearchResult) Document(com.rbmhtechnology.vind.api.Document) SolrInputDocument(org.apache.solr.common.SolrInputDocument) Test(org.junit.Test)

Example 35 with Document

use of com.rbmhtechnology.vind.api.Document in project vind by RBMHTechnology.

the class TestServerTest method testDeleteByQuery.

/*
    @Test
    public void testZKConnection() {

        SearchConfiguration.set(SearchConfiguration.SERVER_SOLR_PROVIDER, "RemoteSolrServerProvider");
        SearchConfiguration.set(SearchConfiguration.SERVER_SOLR_CLOUD, true);
        SearchConfiguration.set(SearchConfiguration.SERVER_SOLR_HOST, "zkServerA:2181,zkServerB:2181,zkServerC:2181");
        SearchConfiguration.set(SearchConfiguration.SERVER_SOLR_COLLECTION, "my_collection");

        SearchServer server = SearchServer.getInstance();

        DocumentFactory assets = new DocumentFactoryBuilder("asset").build();
        SearchResult result = server.execute(Search.fulltext(), assets);

    }
    */
// MBDN-431
@Test
public void testDeleteByQuery() {
    ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
    ZonedDateTime yesterday = ZonedDateTime.now(ZoneId.of("UTC")).minus(1, ChronoUnit.DAYS);
    ZonedDateTime oneHourAgo = ZonedDateTime.now(ZoneId.of("UTC")).minus(1, ChronoUnit.HOURS);
    FieldDescriptor<String> title = new FieldDescriptorBuilder().setFullText(true).setFacet(true).buildTextField("title");
    SingleValueFieldDescriptor.DateFieldDescriptor<ZonedDateTime> created = new FieldDescriptorBuilder().setFacet(true).buildDateField("created");
    SingleValueFieldDescriptor.UtilDateFieldDescriptor<Date> modified = new FieldDescriptorBuilder().setFacet(true).buildUtilDateField("modified");
    NumericFieldDescriptor<Long> category = new FieldDescriptorBuilder().setFacet(true).buildMultivaluedNumericField("category", Long.class);
    DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(title).addField(created).addField(category).addField(modified).build();
    Document d1 = assets.createDoc("1").setValue(title, "Hello World").setValue(created, yesterday).setValue(modified, new Date()).setValues(category, Arrays.asList(1L, 2L));
    Document d2 = assets.createDoc("2").setValue(title, "Hello Friends").setValue(created, now).setValue(modified, new Date()).addValue(category, 4L);
    SearchServer server = testSearchServer.getSearchServer();
    server.index(d1);
    server.index(d2);
    server.commit();
    FulltextSearch searchAll = Search.fulltext();
    final SearchResult searchResult = server.execute(searchAll, assets);
    assertEquals("No of results", 2, searchResult.getNumOfResults());
    final Document result = searchResult.getResults().get(0);
    assertThat("Doc-Title", result.getValue(title), Matchers.equalTo("Hello World"));
    Delete deleteBeforeOneHourAgo = new Delete(Filter.before("created", oneHourAgo));
    server.execute(deleteBeforeOneHourAgo, assets);
    server.commit();
    final SearchResult searchAfterDeleteResult = server.execute(searchAll, assets);
    assertEquals("No of results", 1, searchAfterDeleteResult.getNumOfResults());
    final Document nonDeletedResult = searchAfterDeleteResult.getResults().get(0);
    assertThat("Doc-Title", nonDeletedResult.getValue(title), Matchers.equalTo("Hello Friends"));
    Delete deleteByTitle = new Delete(Filter.eq(title, "Hello Friends"));
    server.execute(deleteByTitle, assets);
    server.commit();
    final SearchResult searchAfterTitleDeletionResult = server.execute(searchAll, assets);
    assertEquals("No of results", 0, searchAfterTitleDeletionResult.getNumOfResults());
}
Also used : Delete(com.rbmhtechnology.vind.api.query.delete.Delete) SearchServer(com.rbmhtechnology.vind.api.SearchServer) SearchResult(com.rbmhtechnology.vind.api.result.SearchResult) Document(com.rbmhtechnology.vind.api.Document) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ZonedDateTime(java.time.ZonedDateTime) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Test(org.junit.Test)

Aggregations

Document (com.rbmhtechnology.vind.api.Document)50 Test (org.junit.Test)40 SolrInputDocument (org.apache.solr.common.SolrInputDocument)36 SearchServer (com.rbmhtechnology.vind.api.SearchServer)33 SearchResult (com.rbmhtechnology.vind.api.result.SearchResult)27 FulltextSearch (com.rbmhtechnology.vind.api.query.FulltextSearch)23 ZonedDateTime (java.time.ZonedDateTime)20 Interval (com.rbmhtechnology.vind.api.query.facet.Interval)13 Delete (com.rbmhtechnology.vind.api.query.delete.Delete)12 MultiValueFieldDescriptor (com.rbmhtechnology.vind.model.MultiValueFieldDescriptor)12 PageResult (com.rbmhtechnology.vind.api.result.PageResult)11 LatLng (com.rbmhtechnology.vind.model.value.LatLng)11 IOException (java.io.IOException)11 SolrQuery (org.apache.solr.client.solrj.SolrQuery)11 SolrServerException (org.apache.solr.client.solrj.SolrServerException)11 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)11 SuggestionResult (com.rbmhtechnology.vind.api.result.SuggestionResult)10 SearchConfiguration (com.rbmhtechnology.vind.configure.SearchConfiguration)10 java.util (java.util)10 SolrClient (org.apache.solr.client.solrj.SolrClient)10