Search in sources :

Example 36 with SearchResult

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

Example 37 with SearchResult

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);
}
Also used : SearchResult(com.rbmhtechnology.vind.api.result.SearchResult) Document(com.rbmhtechnology.vind.api.Document) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.Test)

Example 38 with SearchResult

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);
    }
}
Also used : SearchService(com.rbmhtechnology.vind.demo.step3.service.SearchService) SearchResult(com.rbmhtechnology.vind.api.result.SearchResult)

Aggregations

SearchResult (com.rbmhtechnology.vind.api.result.SearchResult)38 Test (org.junit.Test)35 FulltextSearch (com.rbmhtechnology.vind.api.query.FulltextSearch)28 SearchServer (com.rbmhtechnology.vind.api.SearchServer)27 Document (com.rbmhtechnology.vind.api.Document)26 SolrInputDocument (org.apache.solr.common.SolrInputDocument)26 ZonedDateTime (java.time.ZonedDateTime)14 MultiValueFieldDescriptor (com.rbmhtechnology.vind.model.MultiValueFieldDescriptor)10 Interval (com.rbmhtechnology.vind.api.query.facet.Interval)9 DateMathExpression (com.rbmhtechnology.vind.api.query.datemath.DateMathExpression)8 Delete (com.rbmhtechnology.vind.api.query.delete.Delete)8 PageResult (com.rbmhtechnology.vind.api.result.PageResult)8 SuggestionResult (com.rbmhtechnology.vind.api.result.SuggestionResult)8 GetResult (com.rbmhtechnology.vind.api.result.GetResult)7 LatLng (com.rbmhtechnology.vind.model.value.LatLng)7 ByteBuffer (java.nio.ByteBuffer)7 Language (com.rbmhtechnology.vind.annotations.language.Language)6 Search (com.rbmhtechnology.vind.api.query.Search)6 TimeUnit (com.rbmhtechnology.vind.api.query.datemath.DateMathExpression.TimeUnit)6 Facets (com.rbmhtechnology.vind.api.query.facet.Facets)6