use of com.rbmhtechnology.vind.api.result.SearchResult in project vind by RBMHTechnology.
the class ParentChildrenTest method testParentDuplicationOnAtomicUpdate.
// MBDN-579
@Test
public void testParentDuplicationOnAtomicUpdate() {
// Safe check: ensure the orChildren search works
FulltextSearch search = Search.fulltext().filter(eq(shared_value, "red")).orChildrenSearch(child);
SearchResult result = server.execute(search, parent);
assertEquals(2, result.getNumOfResults());
assertEquals(Integer.valueOf(1), result.getResults().get(1).getChildCount());
// Update parent document to pink
final Update updateToPink = Search.update("P2").set(parent_value, "pink");
server.execute(updateToPink, parent);
server.commit();
search = Search.fulltext().filter(eq(parent_value, "pink"));
result = server.execute(search, parent);
assertEquals(1, result.getNumOfResults());
// Safe check: ensure the orChildren search still works
search = Search.fulltext().filter(eq(shared_value, "red")).orChildrenSearch(child);
result = server.execute(search, parent);
assertEquals(2, result.getNumOfResults());
assertEquals(Integer.valueOf(1), result.getResults().get(1).getChildCount());
// ////////////////////////////////////
server.index(parent.createDoc("P2").setValue(parent_value, "blue").setValue(shared_value, "purple").addChild(child.createDoc("C1").setValue(child_value, "red").setValue(shared_value, "red"), child.createDoc("C2").setValue(child_value, "goblin-green").setValue(shared_value, "yellow")));
server.commit();
// ///////////////////////////////////
// Update parent document to neon-orange
final Update updateToNeonOrange = Search.update("P2").set(parent_value, "neon-orange");
server.execute(updateToNeonOrange, parent);
server.commit();
search = Search.fulltext().filter(eq(parent_value, "neon-orange"));
result = server.execute(search, parent);
assertEquals(1, result.getNumOfResults());
// Safe check: ensure the orChildren search still works
search = Search.fulltext().filter(eq(shared_value, "red")).orChildrenSearch(child);
result = server.execute(search, parent);
assertEquals(2, result.getNumOfResults());
assertEquals(Integer.valueOf(1), result.getResults().get(1).getChildCount());
server.index(parent.createDoc("P2").setValue(parent_value, "neon-yellow").setValue(shared_value, "purple").addChild(child.createDoc("C1").setValue(child_value, "red").setValue(shared_value, "red"), child.createDoc("C2").setValue(child_value, "blue").setValue(shared_value, "yellow")));
server.commit();
search = Search.fulltext().filter(eq(parent_value, "neon-yellow"));
result = server.execute(search, parent);
assertEquals(1, result.getNumOfResults());
// Safe check: ensure the orChildren search still works
search = Search.fulltext().filter(eq(shared_value, "red")).orChildrenSearch(child);
result = server.execute(search, parent);
assertEquals(2, result.getNumOfResults());
assertEquals(Integer.valueOf(1), result.getResults().get(1).getChildCount());
server.index(parent.createDoc("P2").setValue(parent_value, "neon-yellow").setValue(shared_value, "purple").addChild(child.createDoc("C0").setValue(child_value, "blue").setValue(shared_value, "yellow")));
server.commit();
assertEquals(1, 1);
}
use of com.rbmhtechnology.vind.api.result.SearchResult in project vind by RBMHTechnology.
the class SolrSearchServerTest method testIndex.
@Test
public void testIndex() throws Exception {
FieldDescriptor<String> title = new FieldDescriptorBuilder<>().setFullText(true).buildTextField("title");
SingleValueFieldDescriptor.DateFieldDescriptor<ZonedDateTime> created = new FieldDescriptorBuilder<>().setFacet(true).buildDateField("created");
MultiValueFieldDescriptor.NumericFieldDescriptor<Integer> category = new FieldDescriptorBuilder<>().setFacet(true).buildMultivaluedNumericField("category", Integer.class);
final DocumentFactoryBuilder docFactoryBuilder = new DocumentFactoryBuilder("asset");
DocumentFactory documents = docFactoryBuilder.addField(title).addField(created).addField(category).build();
final ZonedDateTime creationDate = ZonedDateTime.of(2016, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault());
Document d1 = documents.createDoc("1").setValue(title, "Hello World").setValue(created, creationDate).setValues(category, Arrays.asList(1, 2));
Document d2 = documents.createDoc("2").setValue(title, "Hello Austria").setValue(created, creationDate).setValue(category, 4);
server.index(d1);
ArgumentCaptor<SolrInputDocument> argument = ArgumentCaptor.forClass(SolrInputDocument.class);
verify(solrClient).add(argument.capture());
SolrInputDocument doc = argument.getValue();
assertThat(doc.get(SolrUtils.Fieldname.ID), solrInputField(SolrUtils.Fieldname.ID, "1"));
assertThat(doc.get(SolrUtils.Fieldname.TYPE), solrInputField(SolrUtils.Fieldname.TYPE, "asset"));
assertThat(doc.get("dynamic_multi_int_category"), solrInputField("dynamic_multi_int_category", Matchers.containsInAnyOrder(1, 2)));
assertThat(doc.get("dynamic_single_string_title"), solrInputField("dynamic_single_string_title", "Hello World"));
assertThat(doc.get("dynamic_single_date_created"), solrInputField("dynamic_single_date_created", Date.from(creationDate.toInstant())));
server.commit();
SearchResult result = server.execute(Search.fulltext("hello").filter(or(category.between(3, 5), created.before(ZonedDateTime.now()))), documents);
}
use of com.rbmhtechnology.vind.api.result.SearchResult in project vind by RBMHTechnology.
the class SearchApplication method main.
public static void main(String[] args) {
try (SearchService searchService = new SearchService()) {
// index
searchService.index();
// search
SearchResult result = searchService.search("vind", 1);
System.out.println(result);
}
}
Aggregations