0

I have a CustomPojo where I have a date field(testDate) in it. Now I want to search this CustomPojo's based on the date range of that date field. Am trying to achieve it in following way but unfortunately it is not filtering the data but returning all pojos. Any suggestions please.

*PojoRepository<CustomPojo, Long> customPojoRepo= getDbClient()
            .newPojoRepository(CustomPojo.class, Long.class);
PojoQueryBuilder<CustomPojo> qb = customPojoRepo.getQueryBuilder();
StructuredQueryDefinition sqdef=
             qb.and(qb.range("testDate", PojoQueryBuilder.Operator.GE, startCal.getTime()),
             qb.range("testDate", PojoQueryBuilder.Operator.LE, endCal.getTime()));
PojoPage<CustomPojo> matchingObjs =
customPojoRepo.search(sqdef,
                    start);*

Thanks, Jagan

derloopkat
  • 6,232
  • 16
  • 38
  • 45
Er. Jagan
  • 1
  • 1
  • Do you have a range query defined in MarkLogic Server? If so, can you share the configuration of it? Did you use GenerateIndexConfig? http://docs.marklogic.com/guide/java/binding#id_29989 – Sam Mefford Jan 29 '18 at 16:06
  • I agree with @DALDEI that we need to see your CustomPojo definition and range index config to diagnose. Even better, you could share the output of sqdef.serialize() http://docs.marklogic.com/guide/java/binding#id_85506 – Sam Mefford Jan 29 '18 at 16:10

2 Answers2

0

Could you post the definition of CustomPojo, and a sample of the JSON doc which is stored in the db. The definition of PojoRepository (as documented) is intended for simple CRUD methods, in particular the exact serialiation (data mapping) from your Pojo to JSON is undefined. Using queries you need to know the serialized name of the field as ML does not know anything about java. Also a range index is typed, without the definition of the range index, the Pojo, the JSON and endCal.getTime() It’s not possible to detetermine which of the most likely issues you are having.

DALDEI
  • 3,722
  • 13
  • 9
  • Please find customPojoa and sample json below. public class CustomPojo{ @Id public Long id; @JsonTypeInfo(use=JsonTypeInfo.Id.NONE, include=JsonTypeInfo.As.EXTERNAL_PROPERTY) public Date testDate; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Date getTestDate() { return this.testDate; } public void setTestDate(Date testDate) { this.testDate= testDate; } } json data { "com.test.repository.ml.pojo.CustomPojo": { "id": 1, "title": "LIFE", "testDate": "2017-02-05T20:00:00.000Z" } – Er. Jagan Jan 30 '18 at 06:52
0

I know this doesn't directly answer your question, but please note that there is a working example of doing range queries on dates in PojoFacadeTest.java which is using TimeTest as the Pojo. To support this bootstrap.xqy (which is run as a prerequisite to unit tests) creates three dateTime range indexes:

  • com.marklogic.client.test.TimeTest/calendarTest
  • com.marklogic.client.test.TimeTest/calendarTestCet
  • com.marklogic.client.test.TimeTest/dateTest
Sam Mefford
  • 2,465
  • 10
  • 15