use of com.rbmhtechnology.vind.api.query.FulltextSearch in project vind by RBMHTechnology.
the class TestServerTest method prefixFilterTest.
// MBDN-461
@Test
public void prefixFilterTest() {
final SingleValueFieldDescriptor.TextFieldDescriptor<String> textSingle = new FieldDescriptorBuilder().setFacet(true).buildTextField("textSingle");
final MultiValueFieldDescriptor.TextFieldDescriptor<String> textMulti = new FieldDescriptorBuilder().setFacet(true).buildMultivaluedTextField("textMulti");
final DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(textSingle).addField(textMulti).build();
final Document doc1 = assets.createDoc("1").setValue(textSingle, "text 1");
final Document doc2 = assets.createDoc("2").setValue(textSingle, "Other text 2").setValues(textMulti, "text 2.1", "text 2.2");
final SearchServer server = testSearchServer.getSearchServer();
server.index(doc1);
server.index(doc2);
server.commit();
FulltextSearch searchAll = Search.fulltext().filter(textSingle.prefix("tex"));
SearchResult searchResult = server.execute(searchAll, assets).print();
assertEquals("Just documents with single text fields starting with 'tex'", 1, searchResult.getNumOfResults());
searchAll = Search.fulltext().filter(textMulti.prefix("tex"));
searchResult = server.execute(searchAll, assets).print();
assertEquals("Just documents with multi text fields starting with 'tex'", 1, searchResult.getNumOfResults());
}
use of com.rbmhtechnology.vind.api.query.FulltextSearch 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());
}
use of com.rbmhtechnology.vind.api.query.FulltextSearch in project vind by RBMHTechnology.
the class ParentChildrenTest method testFilterOnlyWithParentValues.
@Test
public void testFilterOnlyWithParentValues() {
FulltextSearch search = Search.fulltext().setStrict(false).filter(and(not(eq(parent_value, "orange")), or(eq(parent_value, "blue"), eq(parent_value, "red")))).orChildrenSearch(child);
SearchResult result = server.execute(search, parent);
assertEquals(3, result.getNumOfResults());
assertEquals(Integer.valueOf(2), result.getResults().get(1).getChildCount());
}
use of com.rbmhtechnology.vind.api.query.FulltextSearch in project vind by RBMHTechnology.
the class ParentChildrenTest method testFilterRandomOrderFailure.
// MBDN-599
@Test
public void testFilterRandomOrderFailure() {
FulltextSearch search = Search.fulltext().setStrict(false).filter(and(eq(child_value, "blue"), eq(shared_value, "red"))).orChildrenSearch(child);
SearchResult result = server.execute(search, parent);
assertEquals(2, result.getNumOfResults());
// 0 because none of the assets have the shared_value:red
assertEquals(Integer.valueOf(0), result.getResults().get(0).getChildCount());
}
use of com.rbmhtechnology.vind.api.query.FulltextSearch in project vind by RBMHTechnology.
the class ParentChildrenTest method testQuerySyntaxExceptionOnChildrenFacetSearch.
@Test
public void testQuerySyntaxExceptionOnChildrenFacetSearch() {
FulltextSearch search = Search.fulltext("S003 \"M001\" M004").setStrict(false).orChildrenSearch(child);
SearchResult result = server.execute(search, parent);
assertEquals(3, result.getNumOfResults());
search = Search.fulltext("S003 AND").setStrict(false).orChildrenSearch(child);
result = server.execute(search, parent);
assertEquals(1, result.getNumOfResults());
search = Search.fulltext("S003 \"").setStrict(false).orChildrenSearch(child);
result = server.execute(search, parent);
assertEquals(1, result.getNumOfResults());
search = Search.fulltext("S003 (").setStrict(false).orChildrenSearch(child);
result = server.execute(search, parent);
assertEquals(1, result.getNumOfResults());
}
Aggregations