Search in sources :

Example 26 with Document

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

the class SearchService method createNewsItem.

private Document createNewsItem(String _id, String _title, ZonedDateTime _created, int _ranking, String... _categories) {
    Document document = newsItems.createDoc(_id);
    document.setValue(title, _title);
    document.setValue(created, _created);
    document.setValues(category, Arrays.asList(_categories));
    document.setValue(ranking, _ranking);
    return document;
}
Also used : Document(com.rbmhtechnology.vind.api.Document)

Example 27 with Document

use of com.rbmhtechnology.vind.api.Document 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());
}
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 28 with Document

use of com.rbmhtechnology.vind.api.Document 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"));
}
Also used : Delete(com.rbmhtechnology.vind.api.query.delete.Delete) 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) SuggestionResult(com.rbmhtechnology.vind.api.result.SuggestionResult) MultiValueFieldDescriptor(com.rbmhtechnology.vind.model.MultiValueFieldDescriptor) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Test(org.junit.Test)

Example 29 with Document

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

the class TestServerTest method testIndexMultipleDocuments.

// MBDN-352
@Test
public void testIndexMultipleDocuments() {
    ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
    ZonedDateTime yesterday = ZonedDateTime.now(ZoneId.of("UTC")).minus(1, ChronoUnit.DAYS);
    ZonedDateTime oneHourAgo = ZonedDateTime.now(ZoneId.of("UTC")).minus(1, ChronoUnit.HOURS);
    ZonedDateTime halfDayAgo = ZonedDateTime.now(ZoneId.of("UTC")).minus(1, ChronoUnit.HALF_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);
    Document d3 = assets.createDoc("3").setValue(title, "Hello You").setValue(created, halfDayAgo).setValue(modified, new Date()).setValues(category, Arrays.asList(4L, 5L));
    Document d4 = assets.createDoc("4").setValue(title, "Hello them").setValue(created, oneHourAgo).setValue(modified, new Date()).addValue(category, 7L);
    SearchServer server = testSearchServer.getSearchServer();
    List<Document> docList = new ArrayList<>();
    docList.add(d3);
    docList.add(d4);
    server.index(d1, d2);
    server.index(docList);
    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").page(1, 25).sort(desc(created));
    SearchResult result = server.execute(search, assets);
    assertEquals(4, result.getNumOfResults());
    assertEquals(4, result.getResults().size());
    assertEquals("2", result.getResults().get(0).getId());
    assertEquals("asset", result.getResults().get(0).getType());
    assertEquals("4", result.getResults().get(1).getId());
    assertEquals("asset", result.getResults().get(1).getType());
    assertTrue(now.equals(result.getResults().get(0).getValue(created)));
    assertTrue(now.equals(result.getResults().get(0).getValue("created")));
}
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) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Interval(com.rbmhtechnology.vind.api.query.facet.Interval) Test(org.junit.Test)

Example 30 with Document

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

the class TestServerTest method testLocationDescriptor.

@Test
public void testLocationDescriptor() {
    SingleValueFieldDescriptor.LocationFieldDescriptor<LatLng> locationSingle = new FieldDescriptorBuilder().setFacet(true).buildLocationField("locationSingle");
    MultiValueFieldDescriptor.LocationFieldDescriptor<LatLng> locationMulti = new FieldDescriptorBuilder().setFacet(true).buildMultivaluedLocationField("locationMulti");
    DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(locationSingle).addField(locationMulti).build();
    Document doc1 = assets.createDoc("1").setValue(locationSingle, new LatLng(10, 10)).setValues(locationMulti, new LatLng(15, 15));
    Document doc2 = assets.createDoc("2").setValue(locationSingle, new LatLng(20, 20)).setValues(locationMulti, new LatLng(11, 11));
    Document doc3 = assets.createDoc("3").setValues(locationMulti, new LatLng(10, 10), new LatLng(20, 20));
    SearchServer server = testSearchServer.getSearchServer();
    server.index(doc1);
    server.index(doc2);
    server.index(doc3);
    server.commit();
    // test bbox filter
    FulltextSearch searchAll = Search.fulltext().filter(locationSingle.withinBBox(new LatLng(10, 10), new LatLng(11, 1)));
    SearchResult searchResult = server.execute(searchAll, assets).print();
    assertEquals("LatLng filter 'within' does not filter properly single value fields", 1, searchResult.getNumOfResults());
    // test bbox filter multivalue
    searchAll = Search.fulltext().filter(locationMulti.withinBBox(new LatLng(10, 10), new LatLng(12, 12)));
    searchResult = server.execute(searchAll, assets).print();
    assertEquals("LatLng filter 'within' does not filter properly mutivalue fields", 2, searchResult.getNumOfResults());
    // test circle filter
    searchAll = Search.fulltext().filter(locationSingle.withinCircle(new LatLng(10, 10), 1));
    searchResult = server.execute(searchAll, assets).print();
    assertEquals("LatLng filter 'within' does not filter properly singlevalue fields", 1, searchResult.getNumOfResults());
    searchAll = Search.fulltext().filter(locationMulti.withinCircle(new LatLng(10, 10), 160));
    searchResult = server.execute(searchAll, assets).print();
    assertEquals("LatLng filter 'within' does not filter properly singlevalue fields", 2, searchResult.getNumOfResults());
    // test retrieving geodist
    // TODO this feature is a little hacky, but should be easy to clean uo
    searchAll = Search.fulltext().geoDistance(locationSingle, new LatLng(5, 5));
    searchResult = server.execute(searchAll, assets).print();
    assertEquals("Distance is not appended to results", 782.78015, searchResult.getResults().get(0).getDistance(), 0.001);
    // test sorting
    // TODO does not yet work (parsing error)
    searchAll = Search.fulltext().sort(Sort.SpecialSort.distance()).geoDistance(locationSingle, new LatLng(30, 30));
    ;
    searchResult = server.execute(searchAll, assets).print();
    assertTrue("Distance sorting is not correct", searchResult.getResults().get(0).getDistance() < searchResult.getResults().get(1).getDistance());
}
Also used : SearchServer(com.rbmhtechnology.vind.api.SearchServer) SearchResult(com.rbmhtechnology.vind.api.result.SearchResult) LatLng(com.rbmhtechnology.vind.model.value.LatLng) MultiValueFieldDescriptor(com.rbmhtechnology.vind.model.MultiValueFieldDescriptor) Document(com.rbmhtechnology.vind.api.Document) SolrInputDocument(org.apache.solr.common.SolrInputDocument) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) 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