Search in sources :

Example 1 with FulltextSearch

use of com.rbmhtechnology.vind.api.query.FulltextSearch in project vind by RBMHTechnology.

the class TestServerTest method testDateMathIntervals.

// MBDN-450
@Test
public void testDateMathIntervals() {
    ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
    ZonedDateTime yesterday = ZonedDateTime.now(ZoneId.of("UTC")).minus(1, ChronoUnit.DAYS);
    FieldDescriptor<String> title = new FieldDescriptorBuilder().setFullText(true).setFacet(true).buildTextField("title");
    SingleValueFieldDescriptor.DateFieldDescriptor<ZonedDateTime> created = new FieldDescriptorBuilder().setFacet(true).setStored(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();
    Interval.DateMathInterval i1 = Interval.dateInterval("past_24_hours", new DateMathExpression().sub(1, DAY), new DateMathExpression());
    Interval.DateMathInterval i2 = Interval.dateInterval("past_week", new DateMathExpression().sub(7, DAY), new DateMathExpression());
    FulltextSearch search = Search.fulltext("hello").filter(created.before(new DateMathExpression())).facet(query("anotherQuery", and(category.between(7, 10), created.after(new DateMathExpression().sub(1, DAY))))).facet(range("dates", created, new DateMathExpression().sub(1, DAY), new DateMathExpression(), Duration.ofHours(1))).facet(range("mod a", modified, new Date(), new Date(), 1L, TimeUnit.HOURS, "cats")).facet(interval("quality", category, Interval.numericInterval("low", 0L, 2L), Interval.numericInterval("high", 3L, 4L))).facet(interval("time", created, i1, i2)).facet(interval("time2", modified, Interval.dateInterval("early", new Date(0), new Date(10000)), Interval.dateInterval("late", new Date(10000), new Date(20000)))).facet(interval("time3", modified, Interval.dateInterval("early", new DateMathExpression(), new DateMathExpression().add(10000, MILLISECONDS)), Interval.dateInterval("late", new DateMathExpression().add(10000, MILLISECONDS), new DateMathExpression().add(20000, MILLISECONDS)))).page(1, 25).sort(desc(created));
    PageResult result = (PageResult) server.execute(search, assets);
    assertEquals(2, result.getNumOfResults());
    assertEquals(2, result.getResults().size());
    assertEquals("2", result.getResults().get(0).getId());
    assertEquals("asset", result.getResults().get(0).getType());
    assertEquals("2", result.getResults().get(0).getId());
    assertEquals("asset", result.getResults().get(0).getType());
    assertTrue(now.equals(result.getResults().get(0).getValue(created)));
    assertTrue(now.equals(result.getResults().get(0).getValue("created")));
    assertEquals(2, result.getFacetResults().getIntervalFacet("quality").getValues().size());
    assertEquals(2, result.getFacetResults().getIntervalFacet("time").getValues().size());
    System.out.println(result);
    PageResult next = (PageResult) result.nextPage();
    SearchResult prev = next.previousPage();
    TermFacetResult<Long> facet = result.getFacetResults().getTermFacet(category);
    RangeFacetResult<ZonedDateTime> dates = result.getFacetResults().getRangeFacet("dates", ZonedDateTime.class);
    ZonedDateTime rangeDate = dates.getValues().get(0).getValue();
}
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) PageResult(com.rbmhtechnology.vind.api.result.PageResult) ZonedDateTime(java.time.ZonedDateTime) DateMathExpression(com.rbmhtechnology.vind.api.query.datemath.DateMathExpression) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Interval(com.rbmhtechnology.vind.api.query.facet.Interval) Test(org.junit.Test)

Example 2 with FulltextSearch

use of com.rbmhtechnology.vind.api.query.FulltextSearch 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 3 with FulltextSearch

use of com.rbmhtechnology.vind.api.query.FulltextSearch in project vind by RBMHTechnology.

the class TestServerTest method wildcardIntervalLimitTest.

// MBDN-451
@Test
public void wildcardIntervalLimitTest() {
    SingleValueFieldDescriptor<Float> numberField = new FieldDescriptorBuilder().setFacet(true).buildNumericField("number", Float.class);
    FieldDescriptor<String> entityID = new FieldDescriptorBuilder().buildTextField("entityID");
    SingleValueFieldDescriptor<Date> dateField = new FieldDescriptorBuilder().setFacet(true).buildUtilDateField("date");
    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().facet(interval("numbers", numberField, Interval.numericInterval("low", null, 20f), Interval.numericInterval("high", 21f, null))).facet(interval("dates", dateField, Interval.dateInterval("before", null, new Date()), Interval.dateInterval("after", new Date(), null)));
    final SearchResult searchResult = server.execute(searchAll, assets);
    assertEquals("No of interval facets", 2, searchResult.getFacetResults().getIntervalFacet("numbers").getValues().size());
    assertEquals("No of interval facets", 2, searchResult.getFacetResults().getIntervalFacet("dates").getValues().size());
    assertEquals("No of interval facets", 2, searchResult.getFacetResults().getIntervalFacet("dates").getValues().get(0).getCount());
}
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 4 with FulltextSearch

use of com.rbmhtechnology.vind.api.query.FulltextSearch in project vind by RBMHTechnology.

the class TestServerTest method string2FacetTest.

// MBDN-442
@Test
public void string2FacetTest() {
    SingleValueFieldDescriptor<Float> numberField = new FieldDescriptorBuilder().setFacet(true).buildNumericField("number", Float.class);
    FieldDescriptor<String> entityID = new FieldDescriptorBuilder().buildTextField("entityID");
    SingleValueFieldDescriptor<Date> dateField = new FieldDescriptorBuilder().setFacet(true).buildUtilDateField("date");
    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();
    HashMap<String, String> numberIntervals = new HashMap<>();
    numberIntervals.put("low", "[* TO 20]");
    numberIntervals.put("high", "[20 TO *]");
    HashMap<String, String> dateIntervals = new HashMap<>();
    dateIntervals.put("after", "[NOW+23DAYS/DAY TO *]");
    dateIntervals.put("before", "[* TO NOW+23DAYS/DAY]");
    FulltextSearch searchAll = Search.fulltext().facet(FacetMapper.stringQuery2FacetMapper(numberField, "numberFacets", numberIntervals)).facet(FacetMapper.stringQuery2FacetMapper(dateField, "dateFacets", dateIntervals));
    final SearchResult searchResult = server.execute(searchAll, assets);
    assertEquals("No of interval number facets", 2, searchResult.getFacetResults().getIntervalFacet("numberFacets").getValues().size());
    assertEquals("No of interval date facets", 2, searchResult.getFacetResults().getIntervalFacet("dateFacets").getValues().size());
}
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 5 with FulltextSearch

use of com.rbmhtechnology.vind.api.query.FulltextSearch in project vind by RBMHTechnology.

the class TestServerTest method byQueryFacetConfigurationTest.

// MBDN-498
@Test
public void byQueryFacetConfigurationTest() {
    ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
    ZonedDateTime yesterday = ZonedDateTime.now(ZoneId.of("UTC")).minus(1, ChronoUnit.DAYS);
    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, created, category, modified).build();
    Document d1 = assets.createDoc("1").setValue(title, "Hello World").setValue(created, yesterday).setValue(modified, new Date()).setValues(category, 1L, 2L);
    Document d2 = assets.createDoc("2").setValue(title, "Friends").setValue(created, now).setValue(modified, new Date()).addValue(category, 4L);
    Document d3 = assets.createDoc("3").setValue(title, "Hello").setValue(created, now).setValue(modified, new Date());
    SearchServer server = testSearchServer.getSearchServer();
    server.index(d1);
    server.index(d2);
    server.index(d3);
    server.commit();
    FulltextSearch search = Search.fulltext("hello").facet(category).setFacetLimit(2).setFacetMinCount(1).sort(desc(created));
    PageResult result = (PageResult) server.execute(search, assets);
    assertEquals(2, result.getFacetResults().getTermFacet(category).getValues().size());
}
Also used : SearchServer(com.rbmhtechnology.vind.api.SearchServer) Document(com.rbmhtechnology.vind.api.Document) SolrInputDocument(org.apache.solr.common.SolrInputDocument) PageResult(com.rbmhtechnology.vind.api.result.PageResult) ZonedDateTime(java.time.ZonedDateTime) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Test(org.junit.Test)

Aggregations

FulltextSearch (com.rbmhtechnology.vind.api.query.FulltextSearch)35 Test (org.junit.Test)31 SearchResult (com.rbmhtechnology.vind.api.result.SearchResult)26 SearchServer (com.rbmhtechnology.vind.api.SearchServer)21 Document (com.rbmhtechnology.vind.api.Document)20 SolrInputDocument (org.apache.solr.common.SolrInputDocument)20 ZonedDateTime (java.time.ZonedDateTime)11 PageResult (com.rbmhtechnology.vind.api.result.PageResult)8 MultiValueFieldDescriptor (com.rbmhtechnology.vind.model.MultiValueFieldDescriptor)8 Interval (com.rbmhtechnology.vind.api.query.facet.Interval)7 DateMathExpression (com.rbmhtechnology.vind.api.query.datemath.DateMathExpression)6 Delete (com.rbmhtechnology.vind.api.query.delete.Delete)6 SuggestionResult (com.rbmhtechnology.vind.api.result.SuggestionResult)6 LatLng (com.rbmhtechnology.vind.model.value.LatLng)5 ByteBuffer (java.nio.ByteBuffer)5 SolrClient (org.apache.solr.client.solrj.SolrClient)5 SolrQuery (org.apache.solr.client.solrj.SolrQuery)5 Language (com.rbmhtechnology.vind.annotations.language.Language)4 Search (com.rbmhtechnology.vind.api.query.Search)4 TimeUnit (com.rbmhtechnology.vind.api.query.datemath.DateMathExpression.TimeUnit)4