use of com.rbmhtechnology.vind.api.result.PageResult 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();
}
use of com.rbmhtechnology.vind.api.result.PageResult 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());
}
use of com.rbmhtechnology.vind.api.result.PageResult in project vind by RBMHTechnology.
the class TestServerTest method testEmbeddedSolr.
@Test
public void testEmbeddedSolr() {
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).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.ZonedDateTimeInterval i1 = Interval.dateInterval("past_24_hours", ZonedDateTime.now().minus(Duration.ofDays(1)), ZonedDateTime.now());
Interval.ZonedDateTimeInterval i2 = Interval.dateInterval("past_week", ZonedDateTime.now().minus(Duration.ofDays(7)), ZonedDateTime.now());
FulltextSearch search = Search.fulltext("hello").filter(category.between(0, 10)).filter(created.before(ZonedDateTime.now())).filter(modified.before(new Date())).facet(pivot("cats", category, created)).facet(pivot("catVStitle", category, title)).facet(stats("avg Cat", category, "cats", "catVStitle").count().sum().percentiles(9.9, 1.0).mean()).facet(stats("countDate", created).count().sum().mean()).facet(query("new An dHot", category.between(0, 5), "cats")).facet(query("anotherQuery", and(category.between(7, 10), created.after(ZonedDateTime.now().minus(Duration.ofDays(1)))))).facet(range("dates", created, ZonedDateTime.now().minus(Duration.ofDays(1)), ZonedDateTime.now(), 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(category).facet(created).facet(modified).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();
}
use of com.rbmhtechnology.vind.api.result.PageResult in project vind by RBMHTechnology.
the class TestServerTest method queryTermWithDashCharTest.
@Test
public void queryTermWithDashCharTest() {
SingleValueFieldDescriptor.TextFieldDescriptor internalId = new FieldDescriptorBuilder().setFullText(true).setFacet(true).buildTextField("internalId");
SingleValueFieldDescriptor.TextFieldDescriptor textField = new FieldDescriptorBuilder().setFullText(true).setFacet(true).buildTextField("textField");
NumericFieldDescriptor<Long> category = new FieldDescriptorBuilder().setFacet(true).buildMultivaluedNumericField("category", Long.class);
DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(internalId, textField, category).build();
Document d1 = assets.createDoc("1").setValue(internalId, "A-20170322-001").setValue(textField, "").setValues(category, 1L, 2L);
Document d2 = assets.createDoc("2").setValue(internalId, "PN-1HBTR8P952111").setValue(textField, "").addValue(category, 4L);
Document d3 = assets.createDoc("3").setValue(internalId, "1234-34345-54656").setValue(textField, "");
Document d4 = assets.createDoc("4").setValue(internalId, "").setValue(textField, "This is a text1234 field");
Document d5 = assets.createDoc("5").setValue(internalId, "And this is another text-1234 field").setValue(textField, "");
Document d6 = assets.createDoc("6").setValue(internalId, "").setValue(textField, "This is a text 1234 field");
SearchServer server = testSearchServer.getSearchServer();
server.index(d1);
server.index(d2);
server.index(d3);
server.index(d4);
server.index(d5);
server.index(d6);
server.commit();
FulltextSearch search = Search.fulltext("A-20170322-001 1234-34345-54656 PN-1HBTR8P952111");
PageResult result = (PageResult) server.execute(search, assets);
assertEquals(3, result.getResults().size());
search = Search.fulltext("1234");
result = (PageResult) server.execute(search, assets);
assertEquals(1, result.getResults().size());
}
Aggregations