use of com.rbmhtechnology.vind.api.result.SearchResult 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.result.SearchResult in project vind by RBMHTechnology.
the class ParentChildrenTest method testGetNumberOfChildren.
@Test
public void testGetNumberOfChildren() {
FulltextSearch search = Search.fulltext().orChildrenSearch(child);
SearchResult result = server.execute(search, parent);
assertEquals(4, result.getNumOfResults());
assertEquals(Integer.valueOf(2), result.getResults().get(2).getChildCount());
}
use of com.rbmhtechnology.vind.api.result.SearchResult in project vind by RBMHTechnology.
the class SearchApplication method main.
public static void main(String[] args) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.registerModule(new JavaTimeModule());
try (SearchService searchService = new SearchService()) {
// index
searchService.index();
// search
SearchResult result = searchService.news("vind");
System.out.println(mapper.writeValueAsString(result));
}
}
use of com.rbmhtechnology.vind.api.result.SearchResult in project vind by RBMHTechnology.
the class TestServerTest method testEmptyChildrenSearch.
@Test
public void testEmptyChildrenSearch() {
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();
final SearchResult result = server.execute(Search.fulltext().orChildrenSearch(marker), asset);
assertEquals(4, result.getNumOfResults());
}
use of com.rbmhtechnology.vind.api.result.SearchResult in project vind by RBMHTechnology.
the class TestServerTest method testContextSearch.
// MBDN-458
@Test
public void testContextSearch() {
final SingleValueFieldDescriptor<Float> numberField = new FieldDescriptorBuilder().setFacet(true).buildNumericField("numberone", Float.class);
final FieldDescriptor<String> entityID = new FieldDescriptorBuilder().setFacet(true).setLanguage(Language.English).buildTextField("entityID");
final SingleValueFieldDescriptor<Date> dateField = new FieldDescriptorBuilder().buildUtilDateField("datefield");
final MultiValueFieldDescriptor.TextFieldDescriptor<String> multiTextField = new FieldDescriptorBuilder().setFacet(true).setSuggest(true).buildMultivaluedTextField("textMulti");
final DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(numberField).addField(dateField).addField(entityID).addField(multiTextField).setUpdatable(true).build();
final Document d1 = assets.createDoc("1").setValue(numberField, 0f).setContextualizedValue(numberField, "numberContext", 24f).setContextualizedValue(numberField, "singleContext", 3f).setValue(entityID, "123").setValue(dateField, new Date());
final Document d2 = assets.createDoc("2").setValue(numberField, 2f).setValue(entityID, "123").setContextualizedValues(multiTextField, "multicontext", "text1", "text2").setValue(dateField, new Date());
final SearchServer server = testSearchServer.getSearchServer();
server.index(d1);
server.index(d2);
server.commit();
final SuggestionResult suggestion = server.execute(Search.suggest("text1").context("multicontext").addField(multiTextField), assets);
assertEquals("One contextualize suggestion expected", 1, suggestion.size());
FulltextSearch searchAll = Search.fulltext();
SearchResult searchResult = server.execute(searchAll, assets);
assertEquals("Number of results", 2, searchResult.getNumOfResults());
assertEquals("Number_one field", 0f, searchResult.getResults().get(0).getValue("numberone"));
searchAll = Search.fulltext().context("numberContext").filter(and(eq(entityID, "123"), eq(numberField, 24f))).facet(entityID);
searchResult = server.execute(searchAll, assets);
assertEquals("Number of results", 1, searchResult.getNumOfResults());
assertEquals("Number_one field", 24f, searchResult.getResults().get(0).getContextualizedValue("numberone", "numberContext"));
assertEquals("Number_one field", null, searchResult.getResults().get(0).getContextualizedValue("numberone", "singleContext"));
searchAll = Search.fulltext().context("singleContext");
searchResult = server.execute(searchAll, assets);
assertEquals("Number of results", 2, searchResult.getNumOfResults());
assertEquals("Number_one field", 3f, searchResult.getResults().get(0).getContextualizedValue("numberone", "singleContext"));
assertEquals("Number_one field", null, searchResult.getResults().get(0).getContextualizedValue("numberone", "numberContext"));
searchAll = Search.fulltext().context("multicontext");
searchResult = server.execute(searchAll, assets);
assertEquals("Number of results", 2, searchResult.getNumOfResults());
assertThat("textMulti multi text field", (List<String>) searchResult.getResults().get(1).getContextualizedValue("textMulti", "multicontext"), containsInAnyOrder("text1", "text2"));
Delete deleteInContext = new Delete(multiTextField.isNotEmpty()).context("multicontext");
server.execute(deleteInContext, assets);
server.commit();
searchResult = server.execute(searchAll, assets);
assertEquals("Number of results", 1, searchResult.getResults().size());
server.execute(Search.update("1").set(numberField, 1f), assets);
server.commit();
searchResult = server.execute(searchAll, assets);
assertEquals("Number_one field", 1f, searchResult.getResults().get(0).getValue("numberone"));
server.execute(Search.update("1").set("singleContext", numberField, 4f), assets);
server.commit();
searchResult = server.execute(searchAll.context("singleContext"), assets);
assertEquals("Number_one field", 4f, searchResult.getResults().get(0).getContextualizedValue("numberone", "singleContext"));
server.execute(Search.update("1").remove("singleContext", numberField, null), assets);
server.commit();
searchResult = server.execute(searchAll.context("singleContext"), assets);
assertEquals("Number_one field in single context has been removed", null, searchResult.getResults().get(0).getContextualizedValue("numberone", "singleContext"));
}
Aggregations