use of com.rbmhtechnology.vind.api.query.FulltextSearch 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")));
}
use of com.rbmhtechnology.vind.api.query.FulltextSearch 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());
}
use of com.rbmhtechnology.vind.api.query.FulltextSearch in project vind by RBMHTechnology.
the class TestServerTest method supportUnderscoredFieldNamesTest.
// MBDN-452
@Test
public void supportUnderscoredFieldNamesTest() {
SingleValueFieldDescriptor<Float> numberField = new FieldDescriptorBuilder().buildNumericField("number_one", Float.class);
FieldDescriptor<String> entityID = new FieldDescriptorBuilder().setLanguage(Language.English).buildTextField("entity_ID");
SingleValueFieldDescriptor<Date> dateField = new FieldDescriptorBuilder().buildUtilDateField("date_field");
DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(numberField).addField(dateField).addField(entityID).build();
Document d1 = assets.createDoc("1").setValue(numberField, 24f).setValue(entityID, "123").setValue(dateField, new Date());
Document d2 = assets.createDoc("2").setValue(numberField, 2f).setValue(entityID, "123").setValue(dateField, new Date());
SearchServer server = testSearchServer.getSearchServer();
server.index(d1);
server.index(d2);
server.commit();
FulltextSearch searchAll = Search.fulltext();
final SearchResult searchResult = server.execute(searchAll, assets);
assertEquals("Number of results", 2, searchResult.getNumOfResults());
assertEquals("Number_one field", 24f, searchResult.getResults().get(0).getValue("number_one"));
}
use of com.rbmhtechnology.vind.api.query.FulltextSearch in project vind by RBMHTechnology.
the class TestServerTest method binaryFieldTest.
// MBDN-454
@Test
public void binaryFieldTest() {
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);
SingleValueFieldDescriptor.BinaryFieldDescriptor<ByteBuffer> byteField = new FieldDescriptorBuilder().setStored(true).buildBinaryField("blob");
DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(title).addField(created).addField(category).addField(modified).addField(byteField).build();
Document d1 = assets.createDoc("1").setValue(title, "Hello World").setValue(modified, new Date()).setValue(byteField, ByteBuffer.wrap("ooalalalalala".getBytes())).setValues(category, Arrays.asList(1L, 2L));
Document d2 = assets.createDoc("2").setValue(title, "Hello Friends").setValue(modified, new Date()).addValue(category, 4L).setValue(byteField, ByteBuffer.wrap("oolelelelele".getBytes()));
SearchServer server = testSearchServer.getSearchServer();
server.index(d1);
server.index(d2);
server.commit();
FulltextSearch search = Search.fulltext();
SearchResult result = server.execute(search, assets);
assertEquals(2, result.getNumOfResults());
assertEquals(2, result.getResults().size());
assertTrue(ByteBuffer.class.isAssignableFrom(result.getResults().get(0).getValue("blob").getClass()));
assertEquals("ooalalalalala", new String(((ByteBuffer) result.getResults().get(0).getValue("blob")).array()));
}
use of com.rbmhtechnology.vind.api.query.FulltextSearch in project vind by RBMHTechnology.
the class TestServerTest method testDeleteByQuery.
/*
@Test
public void testZKConnection() {
SearchConfiguration.set(SearchConfiguration.SERVER_SOLR_PROVIDER, "RemoteSolrServerProvider");
SearchConfiguration.set(SearchConfiguration.SERVER_SOLR_CLOUD, true);
SearchConfiguration.set(SearchConfiguration.SERVER_SOLR_HOST, "zkServerA:2181,zkServerB:2181,zkServerC:2181");
SearchConfiguration.set(SearchConfiguration.SERVER_SOLR_COLLECTION, "my_collection");
SearchServer server = SearchServer.getInstance();
DocumentFactory assets = new DocumentFactoryBuilder("asset").build();
SearchResult result = server.execute(Search.fulltext(), assets);
}
*/
// MBDN-431
@Test
public void testDeleteByQuery() {
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);
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();
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"));
Delete deleteBeforeOneHourAgo = new Delete(Filter.before("created", oneHourAgo));
server.execute(deleteBeforeOneHourAgo, assets);
server.commit();
final SearchResult searchAfterDeleteResult = server.execute(searchAll, assets);
assertEquals("No of results", 1, searchAfterDeleteResult.getNumOfResults());
final Document nonDeletedResult = searchAfterDeleteResult.getResults().get(0);
assertThat("Doc-Title", nonDeletedResult.getValue(title), Matchers.equalTo("Hello Friends"));
Delete deleteByTitle = new Delete(Filter.eq(title, "Hello Friends"));
server.execute(deleteByTitle, assets);
server.commit();
final SearchResult searchAfterTitleDeletionResult = server.execute(searchAll, assets);
assertEquals("No of results", 0, searchAfterTitleDeletionResult.getNumOfResults());
}
Aggregations