Search in sources :

Example 1 with NumericFieldDescriptor

use of com.rbmhtechnology.vind.model.MultiValueFieldDescriptor.NumericFieldDescriptor in project vind by RBMHTechnology.

the class TestServerTest method testSortableMultiValuedFields.

// MBDN-430
@Test
public void testSortableMultiValuedFields() {
    final TextFieldDescriptor textMulti = new FieldDescriptorBuilder().buildMultivaluedTextField("textMulti");
    final NumericFieldDescriptor<Integer> numMulti = new FieldDescriptorBuilder().buildMultivaluedNumericField("numMulti", Integer.class);
    final Function<Collection<ZonedDateTime>, ZonedDateTime> dateSortFunction = txs -> txs.stream().max(Comparator.<ZonedDateTime>naturalOrder()).get();
    final DateFieldDescriptor dateMulti = new FieldDescriptorBuilder().buildSortableMultivaluedDateField("dateMulti", dateSortFunction);
    final SingleValuedComplexField.UtilDateComplexField<Taxonomy, Date, Date> dateSingle = new ComplexFieldDescriptorBuilder<Taxonomy, Date, Date>().setStored(true, tx -> tx.getUtilDate()).buildUtilDateComplexField("singleDate", Taxonomy.class, Date.class, Date.class);
    final MultiValuedComplexField.DateComplexField<Taxonomy, ZonedDateTime, ZonedDateTime> dateComplexMulti = new ComplexFieldDescriptorBuilder<Taxonomy, ZonedDateTime, ZonedDateTime>().setStored(true, tx -> tx.getDate()).buildMultivaluedDateComplexField("dateComplexMulti", Taxonomy.class, ZonedDateTime.class, ZonedDateTime.class);
    final DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(textMulti).addField(numMulti).addField(dateMulti).addField(dateSingle).addField(dateComplexMulti).build();
    final Document doc1 = assets.createDoc("1").setValues(textMulti, "text 1.1", "text 1.2").setValues(numMulti, 6, 7, 8).setValue(dateSingle, new Taxonomy("today", 2, "todays date", ZonedDateTime.now())).setValues(dateComplexMulti, new Taxonomy("today", 2, "todays date", ZonedDateTime.now()), new Taxonomy("today", 2, "todays date", ZonedDateTime.now().minusDays(1))).setValues(dateMulti, ZonedDateTime.now().minusMonths(3));
    final Document doc2 = assets.createDoc("2").setValues(textMulti, "text 2.1", "text 2.2").setValues(numMulti, 1, 2, 3).setValue(dateSingle, new Taxonomy("today", 1, "todays date", ZonedDateTime.now().plusDays(1))).setValues(dateComplexMulti, new Taxonomy("today", 2, "todays date", ZonedDateTime.now().plusDays(2)), new Taxonomy("today", 2, "todays date", ZonedDateTime.now().minusDays(1))).setValues(dateMulti, ZonedDateTime.now().plusMonths(1));
    final Document doc3 = assets.createDoc("3").addValue(textMulti, null);
    final SearchServer server = testSearchServer.getSearchServer();
    server.index(doc1);
    server.index(doc2);
    server.index(doc3);
    server.commit();
    // test empty filter in single valued field
    FulltextSearch searchAll = Search.fulltext().sort(asc(textMulti));
    SearchResult searchResult = server.execute(searchAll, assets).print();
    assertEquals("Documents are properly ordered by multi valued text field", "1", searchResult.getResults().get(0).getId());
    searchAll = Search.fulltext().sort(desc(numMulti));
    searchResult = server.execute(searchAll, assets).print();
    assertEquals("Documents are properly ordered by multi valued numeric field", "1", searchResult.getResults().get(0).getId());
    searchAll = Search.fulltext().sort(desc(dateMulti));
    searchResult = server.execute(searchAll, assets).print();
    assertEquals("Documents are properly ordered by multi valued date field", "2", searchResult.getResults().get(0).getId());
    searchAll = Search.fulltext().sort(desc(dateSingle));
    searchResult = server.execute(searchAll, assets).print();
    assertEquals("Documents are properly ordered by multi valued date field", "2", searchResult.getResults().get(0).getId());
    searchAll = Search.fulltext().sort(desc(dateComplexMulti));
    searchResult = server.execute(searchAll, assets).print();
    assertEquals("Documents are properly ordered by multi valued date field", "2", searchResult.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) ZonedDateTime(java.time.ZonedDateTime) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Test(org.junit.Test)

Example 2 with NumericFieldDescriptor

use of com.rbmhtechnology.vind.model.MultiValueFieldDescriptor.NumericFieldDescriptor in project vind by RBMHTechnology.

the class TestServerTest method sliceResultTest.

// MBDN-495
@Test
public void sliceResultTest() {
    final TextFieldDescriptor textMulti = new FieldDescriptorBuilder().buildMultivaluedTextField("textMulti");
    final NumericFieldDescriptor<Integer> numMulti = new FieldDescriptorBuilder().buildMultivaluedNumericField("numMulti", Integer.class);
    final DateFieldDescriptor dateMulti = new FieldDescriptorBuilder().buildSortableMultivaluedDateField("dateMulti", txs -> ((Collection<ZonedDateTime>) txs).stream().max(Comparator.<ZonedDateTime>naturalOrder()).get());
    final SingleValuedComplexField.UtilDateComplexField<Taxonomy, Date, Date> dateSingle = new ComplexFieldDescriptorBuilder<Taxonomy, Date, Date>().setStored(true, tx -> tx.getUtilDate()).buildUtilDateComplexField("singleDate", Taxonomy.class, Date.class, Date.class);
    final MultiValuedComplexField.DateComplexField<Taxonomy, ZonedDateTime, ZonedDateTime> dateComplexMulti = new ComplexFieldDescriptorBuilder<Taxonomy, ZonedDateTime, ZonedDateTime>().setStored(true, tx -> tx.getDate()).buildMultivaluedDateComplexField("dateComplexMulti", Taxonomy.class, ZonedDateTime.class, ZonedDateTime.class);
    final DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(textMulti).addField(numMulti).addField(dateMulti).addField(dateSingle).addField(dateComplexMulti).build();
    final Document doc1 = assets.createDoc("1").setValues(textMulti, "text 1.1", "text 1.2").setValues(numMulti, 6, 7, 8).setValue(dateSingle, new Taxonomy("today", 2, "todays date", ZonedDateTime.now())).setValues(dateComplexMulti, new Taxonomy("today", 2, "todays date", ZonedDateTime.now()), new Taxonomy("today", 2, "todays date", ZonedDateTime.now().minusDays(1))).setValues(dateMulti, ZonedDateTime.now().minusMonths(3));
    final Document doc2 = assets.createDoc("2").setValues(textMulti, "text 2.1", "text 2.2").setValues(numMulti, 1, 2, 3).setValue(dateSingle, new Taxonomy("today", 1, "todays date", ZonedDateTime.now())).setValues(dateComplexMulti, new Taxonomy("today", 2, "todays date", ZonedDateTime.now().plusDays(2)), new Taxonomy("today", 2, "todays date", ZonedDateTime.now().minusDays(1))).setValues(dateMulti, ZonedDateTime.now().plusMonths(1));
    final Document doc3 = assets.createDoc("3").addValue(textMulti, null);
    final SearchServer server = testSearchServer.getSearchServer();
    server.index(doc1);
    server.index(doc2);
    server.index(doc3);
    server.commit();
    // test empty filter in single valued field
    FulltextSearch searchAll = Search.fulltext().slice(1).sort(asc(textMulti));
    SearchResult searchResult = server.execute(searchAll, assets).print();
    assertEquals("An Slice starting in index 1", "2", searchResult.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) ZonedDateTime(java.time.ZonedDateTime) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Test(org.junit.Test)

Aggregations

Language (com.rbmhtechnology.vind.annotations.language.Language)2 Document (com.rbmhtechnology.vind.api.Document)2 SearchServer (com.rbmhtechnology.vind.api.SearchServer)2 FulltextSearch (com.rbmhtechnology.vind.api.query.FulltextSearch)2 Search (com.rbmhtechnology.vind.api.query.Search)2 DateMathExpression (com.rbmhtechnology.vind.api.query.datemath.DateMathExpression)2 TimeUnit (com.rbmhtechnology.vind.api.query.datemath.DateMathExpression.TimeUnit)2 Delete (com.rbmhtechnology.vind.api.query.delete.Delete)2 Facets (com.rbmhtechnology.vind.api.query.facet.Facets)2 Interval (com.rbmhtechnology.vind.api.query.facet.Interval)2 Filter (com.rbmhtechnology.vind.api.query.filter.Filter)2 Sort (com.rbmhtechnology.vind.api.query.sort.Sort)2 Sort.asc (com.rbmhtechnology.vind.api.query.sort.Sort.asc)2 Sort.desc (com.rbmhtechnology.vind.api.query.sort.Sort.desc)2 GetResult (com.rbmhtechnology.vind.api.result.GetResult)2 PageResult (com.rbmhtechnology.vind.api.result.PageResult)2 SearchResult (com.rbmhtechnology.vind.api.result.SearchResult)2 SuggestionResult (com.rbmhtechnology.vind.api.result.SuggestionResult)2 RangeFacetResult (com.rbmhtechnology.vind.api.result.facet.RangeFacetResult)2 TermFacetResult (com.rbmhtechnology.vind.api.result.facet.TermFacetResult)2