use of com.rbmhtechnology.vind.api.result.SuggestionResult in project vind by RBMHTechnology.
the class TestServerPojoTest method testRoundtrip2.
@Test
public void testRoundtrip2() {
final SearchServer server = searchServer.getSearchServer();
server.indexBean(new SimplePojo("1", "Hello World", 1, "hello"));
server.indexBean(new SimplePojo("2", "Hello Thomas", 2, "foo", "bar"));
server.commit();
BeanSearchResult<SimplePojo> result = server.execute(Search.fulltext().facet("voting", "category").sort(desc("voting")), SimplePojo.class);
assertNotNull(result);
assertEquals(1, result.getResults().get(0).getScoring(), 0);
// test suggestion
SuggestionResult suggestions = server.execute(Search.suggest("*").fields("category", "voting").filter("voting", "1"), SimplePojo.class);
assertEquals(1, suggestions.get("category").getValues().size());
}
use of com.rbmhtechnology.vind.api.result.SuggestionResult in project vind by RBMHTechnology.
the class TestServerTest method testContextSearch.
// MBDN-458
@Test
public void testContextSearch() {
final SingleValueFieldDescriptor<Float> numberField = new FieldDescriptorBuilder().setFacet(true).buildNumericField("numberone", Float.class);
final FieldDescriptor<String> entityID = new FieldDescriptorBuilder().setFacet(true).setLanguage(Language.English).buildTextField("entityID");
final SingleValueFieldDescriptor<Date> dateField = new FieldDescriptorBuilder().buildUtilDateField("datefield");
final MultiValueFieldDescriptor.TextFieldDescriptor<String> multiTextField = new FieldDescriptorBuilder().setFacet(true).setSuggest(true).buildMultivaluedTextField("textMulti");
final DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(numberField).addField(dateField).addField(entityID).addField(multiTextField).setUpdatable(true).build();
final Document d1 = assets.createDoc("1").setValue(numberField, 0f).setContextualizedValue(numberField, "numberContext", 24f).setContextualizedValue(numberField, "singleContext", 3f).setValue(entityID, "123").setValue(dateField, new Date());
final Document d2 = assets.createDoc("2").setValue(numberField, 2f).setValue(entityID, "123").setContextualizedValues(multiTextField, "multicontext", "text1", "text2").setValue(dateField, new Date());
final SearchServer server = testSearchServer.getSearchServer();
server.index(d1);
server.index(d2);
server.commit();
final SuggestionResult suggestion = server.execute(Search.suggest("text1").context("multicontext").addField(multiTextField), assets);
assertEquals("One contextualize suggestion expected", 1, suggestion.size());
FulltextSearch searchAll = Search.fulltext();
SearchResult searchResult = server.execute(searchAll, assets);
assertEquals("Number of results", 2, searchResult.getNumOfResults());
assertEquals("Number_one field", 0f, searchResult.getResults().get(0).getValue("numberone"));
searchAll = Search.fulltext().context("numberContext").filter(and(eq(entityID, "123"), eq(numberField, 24f))).facet(entityID);
searchResult = server.execute(searchAll, assets);
assertEquals("Number of results", 1, searchResult.getNumOfResults());
assertEquals("Number_one field", 24f, searchResult.getResults().get(0).getContextualizedValue("numberone", "numberContext"));
assertEquals("Number_one field", null, searchResult.getResults().get(0).getContextualizedValue("numberone", "singleContext"));
searchAll = Search.fulltext().context("singleContext");
searchResult = server.execute(searchAll, assets);
assertEquals("Number of results", 2, searchResult.getNumOfResults());
assertEquals("Number_one field", 3f, searchResult.getResults().get(0).getContextualizedValue("numberone", "singleContext"));
assertEquals("Number_one field", null, searchResult.getResults().get(0).getContextualizedValue("numberone", "numberContext"));
searchAll = Search.fulltext().context("multicontext");
searchResult = server.execute(searchAll, assets);
assertEquals("Number of results", 2, searchResult.getNumOfResults());
assertThat("textMulti multi text field", (List<String>) searchResult.getResults().get(1).getContextualizedValue("textMulti", "multicontext"), containsInAnyOrder("text1", "text2"));
Delete deleteInContext = new Delete(multiTextField.isNotEmpty()).context("multicontext");
server.execute(deleteInContext, assets);
server.commit();
searchResult = server.execute(searchAll, assets);
assertEquals("Number of results", 1, searchResult.getResults().size());
server.execute(Search.update("1").set(numberField, 1f), assets);
server.commit();
searchResult = server.execute(searchAll, assets);
assertEquals("Number_one field", 1f, searchResult.getResults().get(0).getValue("numberone"));
server.execute(Search.update("1").set("singleContext", numberField, 4f), assets);
server.commit();
searchResult = server.execute(searchAll.context("singleContext"), assets);
assertEquals("Number_one field", 4f, searchResult.getResults().get(0).getContextualizedValue("numberone", "singleContext"));
server.execute(Search.update("1").remove("singleContext", numberField, null), assets);
server.commit();
searchResult = server.execute(searchAll.context("singleContext"), assets);
assertEquals("Number_one field in single context has been removed", null, searchResult.getResults().get(0).getContextualizedValue("numberone", "singleContext"));
}
use of com.rbmhtechnology.vind.api.result.SuggestionResult 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());
}
use of com.rbmhtechnology.vind.api.result.SuggestionResult in project vind by RBMHTechnology.
the class TestServerTest method complexFieldTest.
// MBDN-455
@Test
public void complexFieldTest() {
SingleValuedComplexField.NumericComplexField<Taxonomy, Integer, String> numericComplexField = new ComplexFieldDescriptorBuilder<Taxonomy, Integer, String>().setFacet(true, tx -> Arrays.asList(tx.getId())).setFullText(true, tx -> Arrays.asList(tx.getTerm())).setSuggest(true, tx -> Arrays.asList(tx.getLabel())).buildNumericComplexField("numberFacetTaxonomy", Taxonomy.class, Integer.class, String.class);
SingleValuedComplexField.DateComplexField<Taxonomy, ZonedDateTime, String> dateComplexField = new ComplexFieldDescriptorBuilder<Taxonomy, ZonedDateTime, String>().setFacet(true, tx -> Arrays.asList(tx.getDate())).setFullText(true, tx -> Arrays.asList(tx.getTerm())).setSuggest(true, tx -> Arrays.asList(tx.getLabel())).buildDateComplexField("dateFacetTaxonomy", Taxonomy.class, ZonedDateTime.class, String.class);
SingleValuedComplexField.TextComplexField<Taxonomy, String, String> textComplexField = new ComplexFieldDescriptorBuilder<Taxonomy, String, String>().setFacet(true, tx -> Arrays.asList(tx.getLabel())).setSuggest(true, tx -> Arrays.asList(tx.getLabel())).setStored(true, tx -> tx.getTerm()).buildTextComplexField("textFacetTaxonomy", Taxonomy.class, String.class, String.class);
SingleValuedComplexField.DateComplexField<Taxonomy, ZonedDateTime, ZonedDateTime> dateStoredComplexField = new ComplexFieldDescriptorBuilder<Taxonomy, ZonedDateTime, ZonedDateTime>().setStored(true, tx -> tx.getDate()).buildSortableDateComplexField("dateStoredFacetTaxonomy", Taxonomy.class, ZonedDateTime.class, ZonedDateTime.class, cdf -> cdf.getDate());
MultiValuedComplexField.TextComplexField<Taxonomy, String, String> multiComplexField = new ComplexFieldDescriptorBuilder<Taxonomy, String, String>().setFacet(true, tx -> Arrays.asList(tx.getLabel())).setSuggest(true, tx -> Arrays.asList(tx.getLabel())).setStored(true, tx -> tx.getTerm()).buildMultivaluedTextComplexField("multiTextTaxonomy", Taxonomy.class, String.class, String.class);
FieldDescriptor<String> entityID = new FieldDescriptorBuilder().buildTextField("entityID");
SingleValueFieldDescriptor<Date> dateField = new FieldDescriptorBuilder().buildUtilDateField("date");
DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(numericComplexField).addField(dateComplexField).addField(textComplexField).addField(dateField).addField(dateStoredComplexField).addField(entityID).addField(multiComplexField).build();
Document d1 = assets.createDoc("1").setValue(numericComplexField, new Taxonomy("uno", 1, "Uno label", ZonedDateTime.now())).setValue(dateComplexField, new Taxonomy("uno", 1, "Uno label", ZonedDateTime.now())).setValue(textComplexField, new Taxonomy("uno", 1, "Label", ZonedDateTime.now())).setValue(entityID, "123").setValue(dateStoredComplexField, new Taxonomy("uno", 1, "Label", ZonedDateTime.now())).setValues(multiComplexField, new Taxonomy("uno", 1, "Label", ZonedDateTime.now()), new Taxonomy("dos", 2, "Label dos", ZonedDateTime.now())).setValue(dateField, new Date());
Document d2 = assets.createDoc("2").setValue(numericComplexField, new Taxonomy("dos", 2, "dos label", ZonedDateTime.now())).setValue(dateComplexField, new Taxonomy("dos", 2, "dos label", ZonedDateTime.now())).setValue(textComplexField, new Taxonomy("uno", 2, "Label", ZonedDateTime.now())).setValue(entityID, "456").setValue(dateStoredComplexField, new Taxonomy("uno", 1, "Label", ZonedDateTime.now().plusMonths(1))).setValues(multiComplexField, new Taxonomy("uno", 1, "Label", ZonedDateTime.now()), new Taxonomy("dos", 1, "Label", ZonedDateTime.now())).setValue(dateField, new Date());
SearchServer server = testSearchServer.getSearchServer();
server.index(d1);
server.index(d2);
server.commit();
FulltextSearch searchAll = Search.fulltext().filter(and(textComplexField.isNotEmpty(Scope.Facet), or(Filter.eq(numericComplexField, 1), Filter.eq(numericComplexField, 2)), numericComplexField.between(0, 5), dateComplexField.between(ZonedDateTime.now().minusDays(3), ZonedDateTime.now().plusDays(3)), textComplexField.equals("Label"))).facet(interval("facetNumber", numericComplexField, Interval.numericInterval("[1-4]", 0, 5), Interval.numericInterval("[6-9]", 5, 10))).facet(interval("facetDateInterval", dateComplexField, Interval.dateInterval("3_days_ago_till_now-1_hour]", ZonedDateTime.now().minusDays(3), ZonedDateTime.now().minusHours(1)), Interval.dateInterval("[now-1_hour_till_the_future]", ZonedDateTime.now().minusHours(1), null))).facet(range("facetRange", numericComplexField, 0, 10, 5)).facet(range("facetDateRange", dateComplexField, ZonedDateTime.now().minusDays(3), ZonedDateTime.now().plusDays(3), Duration.ofDays(1))).facet(stats("facetStats", numericComplexField)).facet(stats("facetDateStats", dateComplexField)).facet(stats("facetTextStats", textComplexField)).facet(pivot("facetPivot", numericComplexField, entityID, dateComplexField, textComplexField)).facet(numericComplexField, entityID, dateComplexField, textComplexField).sort(desc(dateStoredComplexField));
final SearchResult searchResult = server.execute(searchAll, assets);
assertEquals("Stored text exists", "uno", searchResult.getResults().get(0).getValue(textComplexField));
assertThat("Multivalued text exists", (List<String>) searchResult.getResults().get(0).getValue(multiComplexField), containsInAnyOrder("uno", "dos"));
assertEquals("No of interval", 2, searchResult.getFacetResults().getIntervalFacet("facetNumber").getValues().size());
assertEquals("No of doc in interval", 2, searchResult.getFacetResults().getIntervalFacet("facetNumber").getValues().get(0).getCount());
assertEquals("No of StatsFacets", 3, searchResult.getFacetResults().getStatsFacets().size());
assertEquals("Stats Min: ", (Integer) 1, searchResult.getFacetResults().getStatsFacet("facetStats", Integer.class).getMin());
assertEquals("Stats Max: ", (Integer) 2, searchResult.getFacetResults().getStatsFacet("facetStats", Integer.class).getMax());
assertEquals("Stats Sum: ", (Integer) 3, searchResult.getFacetResults().getStatsFacet("facetStats", Integer.class).getSum());
final SuggestionResult suggestSearch = server.execute(Search.suggest("la").fields(numericComplexField, textComplexField), assets);
assertEquals(3, suggestSearch.size());
assertEquals("Label", suggestSearch.get(textComplexField).getValues().get(0).getValue());
assertEquals("Uno label", suggestSearch.get(numericComplexField).getValues().get(0).getValue());
}
Aggregations