Search in sources :

Example 1 with GetResult

use of com.rbmhtechnology.vind.api.result.GetResult in project vind by RBMHTechnology.

the class TestServerTest method testSubdocumentFullReindex.

// MBDN-563
@Test
public void testSubdocumentFullReindex() throws IOException {
    SearchServer server = testSearchServer.getSearchServer();
    // SearchServer server = SolrSearchServer.getInstance("com.rbmhtechnology.searchlib.solr.RemoteSolrServerProvider","http://localhost:8983/solr","core");
    server.clearIndex();
    server.commit();
    SingleValueFieldDescriptor<String> title = new FieldDescriptorBuilder().setFullText(true).setFacet(true).buildTextField("title");
    SingleValueFieldDescriptor<String> color = new FieldDescriptorBuilder().setFullText(true).setFacet(true).setSuggest(true).buildTextField("color");
    SingleValueFieldDescriptor<String> parent = new FieldDescriptorBuilder().setFacet(true).buildTextField("parent");
    DocumentFactory asset = new DocumentFactoryBuilder("asset").setUpdatable(true).addField(title, color).build();
    DocumentFactory marker = new DocumentFactoryBuilder("marker").setUpdatable(true).addField(title, color, parent).build();
    Document a1 = asset.createDoc("A1").setValue(title, "A1 1").setValue(color, "blue");
    Document a2 = asset.createDoc("A2").setValue(title, "A2").setValue(color, "red").addChild(marker.createDoc("M1").setValue(title, "M1").setValue(parent, "A2").setValue(color, "blue")).addChild(marker.createDoc("M4").setValue(title, "M4").setValue(parent, "A2").setValue(color, "green")).addChild(marker.createDoc("M5").setValue(title, "M5").setValue(parent, "A2").setValue(color, "yellow"));
    Document a3 = asset.createDoc("A3").setValue(title, "A3").setValue(color, "green").addChild(marker.createDoc("M2").setValue(title, "M2").setValue(parent, "A3").setValue(color, "red"));
    Document a4 = asset.createDoc("A4").setValue(title, "A4").setValue(color, "blue").addChild(marker.createDoc("M3").setValue(title, "M3").setValue(parent, "A4").setValue(color, "blue"));
    server.index(a1);
    server.index(a2);
    server.index(a3);
    server.index(a4);
    server.commit();
    // Test whether sub-documents are automatically removed from index when full indexing a parent document without them
    a2.getChildren().clear();
    a2.addChild(marker.createDoc("M6").setValue(title, "M6").setValue(parent, "A2").setValue(color, "purple"));
    server.index(a2);
    server.commit();
    // search in all markers
    final GetResult getM6child = server.execute(Search.getById("M6"), marker);
    assertEquals("Subdocument with id:'M6' is indexed", 1, getM6child.getNumOfResults());
    // search in all markers
    final GetResult getM4child = server.execute(Search.getById("M4"), marker);
    assertEquals("subdocument with id:'M4' is no more in the index", 0, getM4child.getNumOfResults());
    // * The search UI displays the special facets "Assets" and "Markers" with according numbers matching the search criteria.
    SearchResult result = server.execute(Search.fulltext().orChildrenSearch(marker).facet(type()), asset);
    assertEquals("Asset Count", 4, result.getNumOfResults());
    // TODO assertEquals("Facet Asset count",4,result.getFacetResults().getTypeFacet().getValues().get(0).getCount());
    // TODO assertEquals("Facet Asset count",3,result.getFacetResults().getTypeFacet().getValues().get(1).getCount());
    // * If the user selects the "Markers" facet only the assets with markers will be displayed.
    result = server.execute(Search.fulltext().filter(hasChildrenDocuments(asset)), asset);
    assertEquals("Only Assets with markers", 3, result.getNumOfResults());
    // * No partial updates for markers yet (but likely to be requested, for example comments)
    // Test behaviour of sub-documents when performing partial updates in children documents.
    server.execute(Search.update("M6").set(title, "M6 seis"), marker);
    server.commit();
    result = server.execute(Search.fulltext().filter(eq(color, "purple", Scope.Suggest)).orChildrenSearch(marker), asset);
    assertEquals("Nested document M6 is still linked to A2 parent document", 1, result.getNumOfResults());
    // Test behabiour of sub-documents when full indexing a parent document after performing partial updates to
    // children documents
    a2.getChildren().clear();
    a2.addChild(marker.createDoc("M6").setValue(title, "M6 seis").setValue(color, "purple"));
    server.index(a2);
    server.commit();
    result = server.execute(Search.fulltext().filter(eq(color, "purple")).orChildrenSearch(marker), asset);
    assertEquals("Nested document M6 is still linked to A2 parent document", 1, result.getNumOfResults());
    // * Partial update are required for the asset.
    assertEquals(1, server.execute(Search.getById("A2"), asset).getNumOfResults());
    assertEquals(4, server.execute(Search.fulltext(), asset).getNumOfResults());
    // Test behaviour of sub-documents when performing partial updates in parent documents.
    server.execute(Search.update("A2").set(title, "A2 dos"), asset);
    server.commit();
    assertEquals(1, server.execute(Search.getById("A2"), asset).getNumOfResults());
    // assertEquals(4, server.execute(Search.fulltext(),asset).getNumOfResults()); TODO!!
    result = server.execute(Search.fulltext().filter(eq(color, "purple")).orChildrenSearch(marker), asset);
    assertEquals("Nested document M6 is still linked to A2 parent document", 1, result.getNumOfResults());
    // Test behabiour of sub-documents when full indexing a parent document after performing partial updates to
    // parent documents
    a2.setValue(title, "A2 dos");
    server.index(a2);
    server.commit();
    result = server.execute(Search.fulltext().filter(eq(color, "purple")).orChildrenSearch(marker), asset);
    assertEquals("Nested document M6 is still linked to A2 parent document", 1, result.getNumOfResults());
    // * The search uses one index configuration for both. The field names for markers and assets are the same (for
    // example a field "Person" of the asset is als available as "Person" on the Marker)
    server.clearIndex();
    server.commit();
}
Also used : GetResult(com.rbmhtechnology.vind.api.result.GetResult) 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) Test(org.junit.Test)

Example 2 with GetResult

use of com.rbmhtechnology.vind.api.result.GetResult in project vind by RBMHTechnology.

the class TestServerTest method testSearchGetById.

@Test
public void testSearchGetById() {
    SearchServer server = testSearchServer.getSearchServer();
    MultiValueFieldDescriptor<String> term = new FieldDescriptorBuilder().setFullText(true).setFacet(true).buildMultivaluedTextField("term");
    DocumentFactory factory = new DocumentFactoryBuilder("testDocFactory").addField(term).build();
    server.index(factory.createDoc("1").setValue(term, "t1").addValue(term, "t2"));
    server.index(factory.createDoc("2").setValue(term, "t2"));
    server.index(factory.createDoc("21").setValue(term, "t2"));
    server.index(factory.createDoc("42").setValue(term, "t42"));
    server.commit();
    GetResult result = server.execute(Search.getById("2"), factory);
    assertEquals(1, result.getResults().size());
    assertEquals("2", result.getResults().get(0).getId());
    GetResult multiResult = server.execute(Search.getById("1", "2", "42"), factory);
    assertEquals(3, multiResult.getResults().size());
    assertEquals("1", multiResult.getResults().get(0).getId());
}
Also used : GetResult(com.rbmhtechnology.vind.api.result.GetResult) SearchServer(com.rbmhtechnology.vind.api.SearchServer) Test(org.junit.Test)

Example 3 with GetResult

use of com.rbmhtechnology.vind.api.result.GetResult in project vind by RBMHTechnology.

the class TestServerTest method atomicUpdateComplexFieldsTest.

// MBDN-483
@Test
public void atomicUpdateComplexFieldsTest() {
    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).setUpdatable(true).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();
    server.execute(Search.update("1").set(textComplexField, new Taxonomy("unoUpdated", 11, "Uno label updated", ZonedDateTime.now().plusMonths(1))), assets);
    server.commit();
    GetResult result = server.execute(Search.getById("1"), assets);
    Assert.assertTrue(true);
}
Also used : Interval(com.rbmhtechnology.vind.api.query.facet.Interval) PageResult(com.rbmhtechnology.vind.api.result.PageResult) java.util(java.util) Delete(com.rbmhtechnology.vind.api.query.delete.Delete) Matchers.isA(org.hamcrest.Matchers.isA) ZonedDateTime(java.time.ZonedDateTime) Function(java.util.function.Function) ByteBuffer(java.nio.ByteBuffer) SolrServerException(org.apache.solr.client.solrj.SolrServerException) Sort.desc(com.rbmhtechnology.vind.api.query.sort.Sort.desc) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) FacetMapper(com.rbmhtechnology.vind.utils.mam.FacetMapper) Duration(java.time.Duration) NumericFieldDescriptor(com.rbmhtechnology.vind.model.MultiValueFieldDescriptor.NumericFieldDescriptor) DateMathExpression(com.rbmhtechnology.vind.api.query.datemath.DateMathExpression) ExpectedException(org.junit.rules.ExpectedException) SearchServer(com.rbmhtechnology.vind.api.SearchServer) Language(com.rbmhtechnology.vind.annotations.language.Language) TermFacetResult(com.rbmhtechnology.vind.api.result.facet.TermFacetResult) SearchConfiguration(com.rbmhtechnology.vind.configure.SearchConfiguration) Facets(com.rbmhtechnology.vind.api.query.facet.Facets) SearchResult(com.rbmhtechnology.vind.api.result.SearchResult) LatLng(com.rbmhtechnology.vind.model.value.LatLng) RangeFacetResult(com.rbmhtechnology.vind.api.result.facet.RangeFacetResult) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) MultiValueFieldDescriptor(com.rbmhtechnology.vind.model.MultiValueFieldDescriptor) Sort(com.rbmhtechnology.vind.api.query.sort.Sort) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) IOException(java.io.IOException) GetResult(com.rbmhtechnology.vind.api.result.GetResult) com.rbmhtechnology.vind.model(com.rbmhtechnology.vind.model) ZoneId(java.time.ZoneId) Document(com.rbmhtechnology.vind.api.Document) SuggestionResult(com.rbmhtechnology.vind.api.result.SuggestionResult) SolrClient(org.apache.solr.client.solrj.SolrClient) TimeUnit(java.util.concurrent.TimeUnit) TimeUnit(com.rbmhtechnology.vind.api.query.datemath.DateMathExpression.TimeUnit) Search(com.rbmhtechnology.vind.api.query.Search) Rule(org.junit.Rule) ChronoUnit(java.time.temporal.ChronoUnit) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Filter(com.rbmhtechnology.vind.api.query.filter.Filter) Assert(org.junit.Assert) Sort.asc(com.rbmhtechnology.vind.api.query.sort.Sort.asc) SolrInputDocument(org.apache.solr.common.SolrInputDocument) GetResult(com.rbmhtechnology.vind.api.result.GetResult) SearchServer(com.rbmhtechnology.vind.api.SearchServer) Document(com.rbmhtechnology.vind.api.Document) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.Test)

Aggregations

SearchServer (com.rbmhtechnology.vind.api.SearchServer)3 GetResult (com.rbmhtechnology.vind.api.result.GetResult)3 Test (org.junit.Test)3 Document (com.rbmhtechnology.vind.api.Document)2 SearchResult (com.rbmhtechnology.vind.api.result.SearchResult)2 Language (com.rbmhtechnology.vind.annotations.language.Language)1 FulltextSearch (com.rbmhtechnology.vind.api.query.FulltextSearch)1 Search (com.rbmhtechnology.vind.api.query.Search)1 DateMathExpression (com.rbmhtechnology.vind.api.query.datemath.DateMathExpression)1 TimeUnit (com.rbmhtechnology.vind.api.query.datemath.DateMathExpression.TimeUnit)1 Delete (com.rbmhtechnology.vind.api.query.delete.Delete)1 Facets (com.rbmhtechnology.vind.api.query.facet.Facets)1 Interval (com.rbmhtechnology.vind.api.query.facet.Interval)1 Filter (com.rbmhtechnology.vind.api.query.filter.Filter)1 Sort (com.rbmhtechnology.vind.api.query.sort.Sort)1 Sort.asc (com.rbmhtechnology.vind.api.query.sort.Sort.asc)1 Sort.desc (com.rbmhtechnology.vind.api.query.sort.Sort.desc)1 PageResult (com.rbmhtechnology.vind.api.result.PageResult)1 SuggestionResult (com.rbmhtechnology.vind.api.result.SuggestionResult)1 RangeFacetResult (com.rbmhtechnology.vind.api.result.facet.RangeFacetResult)1