Search in sources :

Example 11 with FulltextSearch

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());
}
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) MultiValueFieldDescriptor(com.rbmhtechnology.vind.model.MultiValueFieldDescriptor) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Test(org.junit.Test)

Example 12 with FulltextSearch

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());
}
Also used : SearchServer(com.rbmhtechnology.vind.api.SearchServer) Document(com.rbmhtechnology.vind.api.Document) SolrInputDocument(org.apache.solr.common.SolrInputDocument) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) PageResult(com.rbmhtechnology.vind.api.result.PageResult) Test(org.junit.Test)

Example 13 with FulltextSearch

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
}
Also used : DocumentFactory(com.rbmhtechnology.vind.model.DocumentFactory) SolrClient(org.apache.solr.client.solrj.SolrClient) SolrSearchServer(com.rbmhtechnology.vind.solr.backend.SolrSearchServer) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 14 with FulltextSearch

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());
}
Also used : SearchResult(com.rbmhtechnology.vind.api.result.SearchResult) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Test(org.junit.Test)

Example 15 with FulltextSearch

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());
}
Also used : 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