Search in sources :

Example 16 with SearchServer

use of com.rbmhtechnology.vind.api.SearchServer in project vind by RBMHTechnology.

the class TestServerTest method testPartialUpdates.

@Test
public void testPartialUpdates() {
    SearchServer server = testSearchServer.getSearchServer();
    MultiValueFieldDescriptor<Integer> value = new FieldDescriptorBuilder<Integer>().setFullText(true).setFacet(true).buildMultivaluedNumericField("value", Integer.class);
    DocumentFactory documentFactory = new DocumentFactoryBuilder("doc").setUpdatable(true).addField(value).build();
    server.index(documentFactory.createDoc("1").setValues(value, 1, 2));
    server.commit();
    Assert.assertEquals(2, ((List) server.execute(Search.getById("1"), documentFactory).getResults().get(0).getValues().get("value")).size());
    server.execute(Search.update("1").add(value, 3, 4), documentFactory);
    server.commit();
    Assert.assertEquals(4, ((List) server.execute(Search.getById("1"), documentFactory).getResults().get(0).getValues().get("value")).size());
    server.execute(Search.update("1").set(value, 5), documentFactory);
    server.commit();
    Assert.assertEquals(1, ((List) server.execute(Search.getById("1"), documentFactory).getResults().get(0).getValues().get("value")).size());
}
Also used : SearchServer(com.rbmhtechnology.vind.api.SearchServer) Test(org.junit.Test)

Example 17 with SearchServer

use of com.rbmhtechnology.vind.api.SearchServer 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 18 with SearchServer

use of com.rbmhtechnology.vind.api.SearchServer in project vind by RBMHTechnology.

the class TestServerTest method testSubdocuments.

@Test
public void testSubdocuments() throws IOException {
    SearchServer server = testSearchServer.getSearchServer();
    SingleValueFieldDescriptor<String> title = new FieldDescriptorBuilder().setFullText(true).setFacet(true).buildTextField("title");
    SingleValueFieldDescriptor<String> color = new FieldDescriptorBuilder().setFullText(true).setFacet(true).buildTextField("color");
    DocumentFactory asset = new DocumentFactoryBuilder("asset").addField(title, color).build();
    DocumentFactory marker = new DocumentFactoryBuilder("marker").addField(title, color).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(color, "blue"));
    Document a3 = asset.createDoc("A3").setValue(title, "A3").setValue(color, "green").addChild(marker.createDoc("M2").setValue(title, "M2").setValue(color, "red"));
    Document a4 = asset.createDoc("A4").setValue(title, "A4").setValue(color, "blue").addChild(marker.createDoc("M3").setValue(title, "M3").setValue(color, "blue"));
    server.index(a1);
    server.index(a2);
    server.index(a3);
    server.index(a4);
    server.commit();
    // search in all assets
    server.execute(Search.fulltext("some"), asset);
    // search in all markers
    server.execute(Search.fulltext("some"), marker);
    // search in all markers
    SearchResult orChildrenFilteredSearch = server.execute(Search.fulltext().filter(Filter.eq(color, "blue")).orChildrenSearch(marker), asset);
    // search in all markers
    SearchResult andChildrenFilteredSearch = server.execute(Search.fulltext().filter(Filter.eq(color, "blue")).andChildrenSearch(marker), asset);
    Assert.assertTrue(orChildrenFilteredSearch.getNumOfResults() == 3);
    Assert.assertTrue(andChildrenFilteredSearch.getNumOfResults() == 1);
    // search in all markers
    SearchResult orChildrenCustomSearch = server.execute(Search.fulltext("1").filter(Filter.eq(color, "blue")).orChildrenSearch(Search.fulltext().filter(Filter.eq(color, "red")), marker), asset);
    // TODO: confirm with Thomas
    Assert.assertEquals(3, orChildrenCustomSearch.getNumOfResults());
// server.execute(Search.fulltext("some").facet(children(title)),asset); //get title facts for children
// server.executdeepSearchResulte(Search.fulltext("some").facet(parent(title)),marker); //get title facets for parents
// server.execute(Search.fulltext("some").includeChildren(true),marker); //search everywhere and include matching children
}
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) Test(org.junit.Test)

Example 19 with SearchServer

use of com.rbmhtechnology.vind.api.SearchServer 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 20 with SearchServer

use of com.rbmhtechnology.vind.api.SearchServer in project vind by RBMHTechnology.

the class SolrSearchServerTest method testConfigureCloudCoreHostReal.

// is ignored because tests (and therefor requires) a remote solr cloud server
@Test
@Ignore
public void testConfigureCloudCoreHostReal() throws Exception {
    SearchConfiguration.set(SearchConfiguration.SERVER_SOLR_CLOUD, true);
    SearchServer server = SearchServer.getInstance("localhost:9983", "searchindex");
    server.commit();
}
Also used : SolrSearchServer(com.rbmhtechnology.vind.solr.backend.SolrSearchServer) SearchServer(com.rbmhtechnology.vind.api.SearchServer) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

SearchServer (com.rbmhtechnology.vind.api.SearchServer)50 Test (org.junit.Test)46 SolrInputDocument (org.apache.solr.common.SolrInputDocument)31 Document (com.rbmhtechnology.vind.api.Document)30 SearchResult (com.rbmhtechnology.vind.api.result.SearchResult)28 FulltextSearch (com.rbmhtechnology.vind.api.query.FulltextSearch)24 ZonedDateTime (java.time.ZonedDateTime)16 SuggestionResult (com.rbmhtechnology.vind.api.result.SuggestionResult)13 MultiValueFieldDescriptor (com.rbmhtechnology.vind.model.MultiValueFieldDescriptor)12 PageResult (com.rbmhtechnology.vind.api.result.PageResult)11 Interval (com.rbmhtechnology.vind.api.query.facet.Interval)10 DateMathExpression (com.rbmhtechnology.vind.api.query.datemath.DateMathExpression)9 Delete (com.rbmhtechnology.vind.api.query.delete.Delete)9 GetResult (com.rbmhtechnology.vind.api.result.GetResult)9 LatLng (com.rbmhtechnology.vind.model.value.LatLng)8 ByteBuffer (java.nio.ByteBuffer)8 Language (com.rbmhtechnology.vind.annotations.language.Language)7 Search (com.rbmhtechnology.vind.api.query.Search)7 TimeUnit (com.rbmhtechnology.vind.api.query.datemath.DateMathExpression.TimeUnit)7 Facets (com.rbmhtechnology.vind.api.query.facet.Facets)7