Search in sources :

Example 11 with Document

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

the class TestServerTest method testEmbeddedSolr.

@Test
public void testEmbeddedSolr() {
    ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
    ZonedDateTime yesterday = ZonedDateTime.now(ZoneId.of("UTC")).minus(1, ChronoUnit.DAYS);
    FieldDescriptor<String> title = new FieldDescriptorBuilder().setFullText(true).setFacet(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();
    Interval.ZonedDateTimeInterval i1 = Interval.dateInterval("past_24_hours", ZonedDateTime.now().minus(Duration.ofDays(1)), ZonedDateTime.now());
    Interval.ZonedDateTimeInterval i2 = Interval.dateInterval("past_week", ZonedDateTime.now().minus(Duration.ofDays(7)), ZonedDateTime.now());
    FulltextSearch search = Search.fulltext("hello").filter(category.between(0, 10)).filter(created.before(ZonedDateTime.now())).filter(modified.before(new Date())).facet(pivot("cats", category, created)).facet(pivot("catVStitle", category, title)).facet(stats("avg Cat", category, "cats", "catVStitle").count().sum().percentiles(9.9, 1.0).mean()).facet(stats("countDate", created).count().sum().mean()).facet(query("new An dHot", category.between(0, 5), "cats")).facet(query("anotherQuery", and(category.between(7, 10), created.after(ZonedDateTime.now().minus(Duration.ofDays(1)))))).facet(range("dates", created, ZonedDateTime.now().minus(Duration.ofDays(1)), ZonedDateTime.now(), Duration.ofHours(1))).facet(range("mod a", modified, new Date(), new Date(), 1L, TimeUnit.HOURS, "cats")).facet(interval("quality", category, Interval.numericInterval("low", 0L, 2L), Interval.numericInterval("high", 3L, 4L))).facet(interval("time", created, i1, i2)).facet(interval("time2", modified, Interval.dateInterval("early", new Date(0), new Date(10000)), Interval.dateInterval("late", new Date(10000), new Date(20000)))).facet(category).facet(created).facet(modified).page(1, 25).sort(desc(created));
    PageResult result = (PageResult) server.execute(search, assets);
    assertEquals(2, result.getNumOfResults());
    assertEquals(2, result.getResults().size());
    assertEquals("2", result.getResults().get(0).getId());
    assertEquals("asset", result.getResults().get(0).getType());
    assertEquals("2", result.getResults().get(0).getId());
    assertEquals("asset", result.getResults().get(0).getType());
    assertTrue(now.equals(result.getResults().get(0).getValue(created)));
    assertTrue(now.equals(result.getResults().get(0).getValue("created")));
    assertEquals(2, result.getFacetResults().getIntervalFacet("quality").getValues().size());
    assertEquals(2, result.getFacetResults().getIntervalFacet("time").getValues().size());
    System.out.println(result);
    PageResult next = (PageResult) result.nextPage();
    SearchResult prev = next.previousPage();
    TermFacetResult<Long> facet = result.getFacetResults().getTermFacet(category);
    RangeFacetResult<ZonedDateTime> dates = result.getFacetResults().getRangeFacet("dates", ZonedDateTime.class);
    ZonedDateTime rangeDate = dates.getValues().get(0).getValue();
}
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) PageResult(com.rbmhtechnology.vind.api.result.PageResult) ZonedDateTime(java.time.ZonedDateTime) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Interval(com.rbmhtechnology.vind.api.query.facet.Interval) Test(org.junit.Test)

Example 12 with Document

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

the class TestServerTest method testTypeIDScoreAsFieldname.

@Test
public void testTypeIDScoreAsFieldname() {
    SearchServer server = testSearchServer.getSearchServer();
    FieldDescriptor<String> title = new FieldDescriptorBuilder().setFullText(true).setFacet(true).buildTextField("title");
    FieldDescriptor<String> id = new FieldDescriptorBuilder().setFullText(true).setFacet(true).buildTextField("id");
    FieldDescriptor<String> type = new FieldDescriptorBuilder().setFullText(true).setFacet(true).buildTextField("type");
    FieldDescriptor<String> score = new FieldDescriptorBuilder().setFacet(true).buildTextField("score");
    DocumentFactory factory = new DocumentFactoryBuilder("test").addField(score, type, id, title).build();
    server.index(factory.createDoc("1").setValue(title, "Title").setValue(id, "ID").setValue(type, "TYPE").setValue(score, "Score"));
    server.commit();
    SearchResult result = server.execute(Search.fulltext().facet("id", "type", "score"), factory);
    assertEquals(1, result.getNumOfResults());
    Document doc = result.getResults().get(0);
    assertEquals("ID", doc.getValue("id"));
    assertEquals("Title", doc.getValue("title"));
    assertEquals("Score", doc.getValue("score"));
    assertEquals("TYPE", doc.getValue("type"));
    assertEquals(1.0, doc.getScore(), 0);
    assertEquals("test", doc.getType());
    assertEquals("1", doc.getId());
}
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 13 with Document

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

the class TestServerTest method isNotEmptyFilterTest.

// MBDN-459
@Test
public void isNotEmptyFilterTest() {
    final SingleValueFieldDescriptor.TextFieldDescriptor<String> textSingle = new FieldDescriptorBuilder().setFacet(true).buildTextField("textSingle");
    final SingleValueFieldDescriptor.NumericFieldDescriptor<Integer> numberSingle = new FieldDescriptorBuilder().setFacet(true).buildNumericField("intSingle", Integer.class);
    final MultiValueFieldDescriptor.TextFieldDescriptor<String> textMulti = new FieldDescriptorBuilder().setFacet(true).buildMultivaluedTextField("textMulti");
    final DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(textSingle).addField(textMulti).addField(numberSingle).build();
    final Document doc1 = assets.createDoc("1").setValue(textSingle, "text 1");
    final Document doc2 = assets.createDoc("2").setValues(textMulti, "text 2.1", "text 2.2");
    final Document doc3 = assets.createDoc("3").setValue(textSingle, "").addValue(textMulti, null).setValue(numberSingle, 9);
    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().filter(textSingle.isNotEmpty());
    SearchResult searchResult = server.execute(searchAll, assets).print();
    assertEquals("Just documents with single text fields are returned", 1, searchResult.getNumOfResults());
    // test empty filter in multivalue field
    searchAll = Search.fulltext().filter(textMulti.isNotEmpty());
    searchResult = server.execute(searchAll, assets).print();
    assertEquals("Just documents with multi valued text fields are returned", 1, searchResult.getNumOfResults());
    // test empty filter in single valued field
    searchAll = Search.fulltext().filter(textSingle.isEmpty());
    searchResult = server.execute(searchAll, assets).print();
    assertEquals("Just documents with not or empty single text fields are returned", 2, searchResult.getNumOfResults());
    // test empty filter in single valued field
    searchAll = Search.fulltext().filter(not(textMulti.isNotEmpty()));
    searchResult = server.execute(searchAll, assets).print();
    assertEquals("Just documents with not or empty multi text fields are returned", 2, searchResult.getNumOfResults());
    // test empty filter in single valued numberfield
    searchAll = Search.fulltext().filter(numberSingle.isNotEmpty());
    searchResult = server.execute(searchAll, assets).print();
    assertEquals("Just documents with not or empty multi number fields are returned", 1, searchResult.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) MultiValueFieldDescriptor(com.rbmhtechnology.vind.model.MultiValueFieldDescriptor) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Test(org.junit.Test)

Example 14 with Document

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

use of com.rbmhtechnology.vind.api.Document 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)

Aggregations

Document (com.rbmhtechnology.vind.api.Document)50 Test (org.junit.Test)40 SolrInputDocument (org.apache.solr.common.SolrInputDocument)36 SearchServer (com.rbmhtechnology.vind.api.SearchServer)33 SearchResult (com.rbmhtechnology.vind.api.result.SearchResult)27 FulltextSearch (com.rbmhtechnology.vind.api.query.FulltextSearch)23 ZonedDateTime (java.time.ZonedDateTime)20 Interval (com.rbmhtechnology.vind.api.query.facet.Interval)13 Delete (com.rbmhtechnology.vind.api.query.delete.Delete)12 MultiValueFieldDescriptor (com.rbmhtechnology.vind.model.MultiValueFieldDescriptor)12 PageResult (com.rbmhtechnology.vind.api.result.PageResult)11 LatLng (com.rbmhtechnology.vind.model.value.LatLng)11 IOException (java.io.IOException)11 SolrQuery (org.apache.solr.client.solrj.SolrQuery)11 SolrServerException (org.apache.solr.client.solrj.SolrServerException)11 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)11 SuggestionResult (com.rbmhtechnology.vind.api.result.SuggestionResult)10 SearchConfiguration (com.rbmhtechnology.vind.configure.SearchConfiguration)10 java.util (java.util)10 SolrClient (org.apache.solr.client.solrj.SolrClient)10