use of com.rbmhtechnology.vind.api.query.FulltextSearch in project vind by RBMHTechnology.
the class TestServerTest method isNotEmptyFilterTest.
// MBDN-459
@Test
public void isNotEmptyFilterTest() {
final SingleValueFieldDescriptor.TextFieldDescriptor<String> textSingle = new FieldDescriptorBuilder().setFacet(true).buildTextField("textSingle");
final SingleValueFieldDescriptor.NumericFieldDescriptor<Integer> numberSingle = new FieldDescriptorBuilder().setFacet(true).buildNumericField("intSingle", Integer.class);
final MultiValueFieldDescriptor.TextFieldDescriptor<String> textMulti = new FieldDescriptorBuilder().setFacet(true).buildMultivaluedTextField("textMulti");
final DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(textSingle).addField(textMulti).addField(numberSingle).build();
final Document doc1 = assets.createDoc("1").setValue(textSingle, "text 1");
final Document doc2 = assets.createDoc("2").setValues(textMulti, "text 2.1", "text 2.2");
final Document doc3 = assets.createDoc("3").setValue(textSingle, "").addValue(textMulti, null).setValue(numberSingle, 9);
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().filter(textSingle.isNotEmpty());
SearchResult searchResult = server.execute(searchAll, assets).print();
assertEquals("Just documents with single text fields are returned", 1, searchResult.getNumOfResults());
// test empty filter in multivalue field
searchAll = Search.fulltext().filter(textMulti.isNotEmpty());
searchResult = server.execute(searchAll, assets).print();
assertEquals("Just documents with multi valued text fields are returned", 1, searchResult.getNumOfResults());
// test empty filter in single valued field
searchAll = Search.fulltext().filter(textSingle.isEmpty());
searchResult = server.execute(searchAll, assets).print();
assertEquals("Just documents with not or empty single text fields are returned", 2, searchResult.getNumOfResults());
// test empty filter in single valued field
searchAll = Search.fulltext().filter(not(textMulti.isNotEmpty()));
searchResult = server.execute(searchAll, assets).print();
assertEquals("Just documents with not or empty multi text fields are returned", 2, searchResult.getNumOfResults());
// test empty filter in single valued numberfield
searchAll = Search.fulltext().filter(numberSingle.isNotEmpty());
searchResult = server.execute(searchAll, assets).print();
assertEquals("Just documents with not or empty multi number fields are returned", 1, searchResult.getNumOfResults());
}
use of com.rbmhtechnology.vind.api.query.FulltextSearch 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());
}
use of com.rbmhtechnology.vind.api.query.FulltextSearch in project vind by RBMHTechnology.
the class IntervalFacetsTest method testQueryBuilder.
@Test
public void testQueryBuilder() {
SolrClient client = Mockito.mock(SolrClient.class);
SolrSearchServer server = new SolrSearchServer(client, false);
FieldDescriptor<Integer> descriptor = Mockito.mock(FieldDescriptor.class);
when(descriptor.getType()).thenReturn(Integer.class);
when(descriptor.isFacet()).thenReturn(true);
DocumentFactory factory = Mockito.mock(DocumentFactory.class);
FulltextSearch search = Search.fulltext().facet(interval("quality", descriptor, Interval.numericInterval("low", 0, 2, true, false), Interval.numericInterval("high", 3, 4)));
SolrQuery query = server.buildSolrQuery(search, factory);
assertEquals("{!key=quality}dynamic_single_facet_int_null", query.get("facet.interval"));
// assertThat(Arrays.asList(query.getParams("f.dynamic_single_int_null.facet.interval.set")), contains("{!key=low}[0,2)", "{!key=high}[3,4]")); TODO fix hamcrest dependency
}
use of com.rbmhtechnology.vind.api.query.FulltextSearch in project vind by RBMHTechnology.
the class ParentChildrenTest method testFilterOnlyWithChildrenValue.
@Test
public void testFilterOnlyWithChildrenValue() {
FulltextSearch search = Search.fulltext().setStrict(false).filter(eq(child_value, "red")).orChildrenSearch(child);
SearchResult result = server.execute(search, parent);
assertEquals(1, result.getNumOfResults());
assertEquals(Integer.valueOf(1), result.getResults().get(0).getChildCount());
}
use of com.rbmhtechnology.vind.api.query.FulltextSearch in project vind by RBMHTechnology.
the class ParentChildrenTest method testFilterResultsByParentValue.
@Test
public void testFilterResultsByParentValue() {
// parent has to contain red
FulltextSearch search1 = Search.fulltext().filter(eq(parent_value, "red"));
assertEquals(2, server.execute(search1, parent).getNumOfResults());
FulltextSearch search2 = Search.fulltext("blue");
assertEquals(1, server.execute(search2, parent).getNumOfResults());
FulltextSearch search3 = Search.fulltext("blue").orChildrenSearch(child);
assertEquals(2, server.execute(search3, parent).getNumOfResults());
/**
* filtering children for parent values is not possible, therefor a extra search has to be used
*/
FulltextSearch search4 = Search.fulltext("blue").filter(eq(parent_value, "red")).orChildrenSearch(Search.fulltext("blue"), child);
assertEquals(1, server.execute(search4, parent).getNumOfResults());
assertEquals("P3", server.execute(search4, parent).getResults().get(0).getId());
}
Aggregations