Search in sources :

Example 6 with SearchResult

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

the class TestServerTest method testTermFacetAccess.

public void testTermFacetAccess() {
    SearchServer server = testSearchServer.getSearchServer();
    MultiValueFieldDescriptor<String> term = new FieldDescriptorBuilder().setFullText(true).setFacet(true).buildMultivaluedTextField("term");
    DocumentFactory factory = new DocumentFactoryBuilder("doc").addField(term).build();
    server.index(factory.createDoc("1").setValue(term, "t1").addValue(term, "t2"));
    server.index(factory.createDoc("2").setValue(term, "t2"));
    server.commit();
    SearchResult result = server.execute(Search.fulltext().facet(term), factory);
    assertEquals(2, result.getFacetResults().getTermFacet(term).getValues().size());
    assertEquals(2, result.getFacetResults().getTermFacet("term", String.class).getValues().size());
    assertEquals(2, result.getFacetResults().getTermFacets().get(term).getValues().size());
}
Also used : SearchServer(com.rbmhtechnology.vind.api.SearchServer) SearchResult(com.rbmhtechnology.vind.api.result.SearchResult)

Example 7 with SearchResult

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

the class TestServerTest method testClearIndex.

// MBDN-432
@Test
public void testClearIndex() {
    // Storing as text_en solr type
    SingleValueFieldDescriptor.TextFieldDescriptor<String> title = new FieldDescriptorBuilder().setFullText(true).setStored(true).buildTextField("title");
    FieldDescriptor<String> entityID = new FieldDescriptorBuilder().buildTextField("entityID");
    SingleValueFieldDescriptor<String> description = new FieldDescriptorBuilder().setLanguage(Language.English).buildTextField("description");
    DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(title).addField(description).addField(entityID).build();
    Document d1 = assets.createDoc("1").setValue(title, "Hello World").setValue(entityID, "123").setValue(description, "This value is not stored");
    Document d2 = assets.createDoc("2").setValue(entityID, "456").setValue(title, "Hello Friends").setValue(description, "This value is also not stored");
    SearchServer server = testSearchServer.getSearchServer();
    server.index(d1);
    server.index(d2);
    server.commit();
    FulltextSearch searchAll = Search.fulltext();
    final SearchResult searchResult = server.execute(searchAll, assets);
    assertEquals("No of results", 2, searchResult.getNumOfResults());
    final Document result = searchResult.getResults().get(0);
    assertThat("Doc-Title", result.getValue(title), Matchers.equalTo("Hello World"));
    server.clearIndex();
    server.commit();
    final SearchResult searchResultClear = server.execute(searchAll, assets);
    assertEquals("No of results", 0, searchResultClear.getNumOfResults());
}
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) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Test(org.junit.Test)

Example 8 with SearchResult

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

the class TestServerTest method timeZoneSearchTest.

// MBDN-441
@Test
public void timeZoneSearchTest() {
    ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
    ZonedDateTime yesterday = ZonedDateTime.now(ZoneId.of("UTC")).minus(1, ChronoUnit.DAYS);
    ZonedDateTime oneHourAgo = ZonedDateTime.now(ZoneId.systemDefault()).minus(1, ChronoUnit.HOURS);
    FieldDescriptor<String> title = new FieldDescriptorBuilder().setFullText(true).buildTextField("title");
    SingleValueFieldDescriptor.DateFieldDescriptor<ZonedDateTime> created = new FieldDescriptorBuilder().setFacet(true).buildDateField("created");
    SingleValueFieldDescriptor.UtilDateFieldDescriptor<Date> modified = new FieldDescriptorBuilder().setFacet(true).buildUtilDateField("modified");
    NumericFieldDescriptor<Long> category = new FieldDescriptorBuilder().setFacet(true).buildMultivaluedNumericField("category", Long.class);
    DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(title).addField(created).addField(category).addField(modified).build();
    Document d1 = assets.createDoc("1").setValue(title, "Hello World").setValue(created, yesterday).setValue(modified, new Date()).setValues(category, Arrays.asList(1L, 2L));
    Document d2 = assets.createDoc("2").setValue(title, "Hello Friends").setValue(created, now).setValue(modified, new Date()).addValue(category, 4L);
    SearchServer server = testSearchServer.getSearchServer();
    server.index(d1);
    server.index(d2);
    server.commit();
    FulltextSearch searchAll = Search.fulltext().filter(before("created", new DateMathExpression().sub(1, HOUR))).timeZone("America/Havana");
    final SearchResult searchResult = server.execute(searchAll, assets);
    assertEquals("No of results", 1, searchResult.getNumOfResults());
    final Document result = searchResult.getResults().get(0);
    assertThat("Doc-Title", result.getValue(title), Matchers.equalTo("Hello World"));
}
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) ZonedDateTime(java.time.ZonedDateTime) DateMathExpression(com.rbmhtechnology.vind.api.query.datemath.DateMathExpression) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Test(org.junit.Test)

Example 9 with SearchResult

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

the class TestServerTest method sliceResultTest.

// MBDN-495
@Test
public void sliceResultTest() {
    final TextFieldDescriptor textMulti = new FieldDescriptorBuilder().buildMultivaluedTextField("textMulti");
    final NumericFieldDescriptor<Integer> numMulti = new FieldDescriptorBuilder().buildMultivaluedNumericField("numMulti", Integer.class);
    final DateFieldDescriptor dateMulti = new FieldDescriptorBuilder().buildSortableMultivaluedDateField("dateMulti", txs -> ((Collection<ZonedDateTime>) txs).stream().max(Comparator.<ZonedDateTime>naturalOrder()).get());
    final SingleValuedComplexField.UtilDateComplexField<Taxonomy, Date, Date> dateSingle = new ComplexFieldDescriptorBuilder<Taxonomy, Date, Date>().setStored(true, tx -> tx.getUtilDate()).buildUtilDateComplexField("singleDate", Taxonomy.class, Date.class, Date.class);
    final MultiValuedComplexField.DateComplexField<Taxonomy, ZonedDateTime, ZonedDateTime> dateComplexMulti = new ComplexFieldDescriptorBuilder<Taxonomy, ZonedDateTime, ZonedDateTime>().setStored(true, tx -> tx.getDate()).buildMultivaluedDateComplexField("dateComplexMulti", Taxonomy.class, ZonedDateTime.class, ZonedDateTime.class);
    final DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(textMulti).addField(numMulti).addField(dateMulti).addField(dateSingle).addField(dateComplexMulti).build();
    final Document doc1 = assets.createDoc("1").setValues(textMulti, "text 1.1", "text 1.2").setValues(numMulti, 6, 7, 8).setValue(dateSingle, new Taxonomy("today", 2, "todays date", ZonedDateTime.now())).setValues(dateComplexMulti, new Taxonomy("today", 2, "todays date", ZonedDateTime.now()), new Taxonomy("today", 2, "todays date", ZonedDateTime.now().minusDays(1))).setValues(dateMulti, ZonedDateTime.now().minusMonths(3));
    final Document doc2 = assets.createDoc("2").setValues(textMulti, "text 2.1", "text 2.2").setValues(numMulti, 1, 2, 3).setValue(dateSingle, new Taxonomy("today", 1, "todays date", ZonedDateTime.now())).setValues(dateComplexMulti, new Taxonomy("today", 2, "todays date", ZonedDateTime.now().plusDays(2)), new Taxonomy("today", 2, "todays date", ZonedDateTime.now().minusDays(1))).setValues(dateMulti, ZonedDateTime.now().plusMonths(1));
    final Document doc3 = assets.createDoc("3").addValue(textMulti, null);
    final SearchServer server = testSearchServer.getSearchServer();
    server.index(doc1);
    server.index(doc2);
    server.index(doc3);
    server.commit();
    // test empty filter in single valued field
    FulltextSearch searchAll = Search.fulltext().slice(1).sort(asc(textMulti));
    SearchResult searchResult = server.execute(searchAll, assets).print();
    assertEquals("An Slice starting in index 1", "2", searchResult.getResults().get(0).getId());
}
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) 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) ZonedDateTime(java.time.ZonedDateTime) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Test(org.junit.Test)

Example 10 with SearchResult

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

the class TestServerTest method complexFieldBooleanTest.

@Test
public void complexFieldBooleanTest() {
    SingleValuedComplexField.NumericComplexField<Taxonomy, Integer, Boolean> numericComplexField = new ComplexFieldDescriptorBuilder<Taxonomy, Integer, Boolean>().setFacet(true, tx -> Arrays.asList(tx.getId())).setStored(true, tx -> true).setFullText(true, tx -> Arrays.asList(tx.getTerm())).setSuggest(true, tx -> Arrays.asList(tx.getLabel())).buildNumericComplexField("numberFacetBooleanStoredTaxonomy", Taxonomy.class, Integer.class, Boolean.class);
    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);
    DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(numericComplexField).addField(multiComplexField).build();
    Document d1 = assets.createDoc("1").setValue(numericComplexField, new Taxonomy("uno", 1, "Uno label", ZonedDateTime.now())).setValues(multiComplexField, new Taxonomy("uno", 1, "Label", ZonedDateTime.now()), new Taxonomy("dos", 2, "Label dos", ZonedDateTime.now()));
    Document d2 = assets.createDoc("2").setValue(numericComplexField, new Taxonomy("dos", 2, "dos label", ZonedDateTime.now())).setValues(multiComplexField, new Taxonomy("uno", 1, "Label", ZonedDateTime.now()), new Taxonomy("dos", 1, "Label", ZonedDateTime.now()));
    SearchServer server = testSearchServer.getSearchServer();
    server.index(d1);
    server.index(d2);
    server.commit();
    final FulltextSearch searchAll = Search.fulltext();
    final SearchResult searchResult = server.execute(searchAll, assets);
}
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) 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) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Test(org.junit.Test)

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