List of usage examples for java.util Locale CHINESE
Locale CHINESE
To view the source code for java.util Locale CHINESE.
Click Source Link
From source file:com.borax12.materialdaterangepicker.date.MonthView.java
protected void drawMonthDayLabels(Canvas canvas) { int y = getMonthHeaderSize() - (MONTH_DAY_LABEL_TEXT_SIZE / 2); int dayWidthHalf = (mWidth - mEdgePadding * 2) / (mNumDays * 2); for (int i = 0; i < mNumDays; i++) { int x = (2 * i + 1) * dayWidthHalf + mEdgePadding; int calendarDay = (i + mWeekStart) % mNumDays; mDayLabelCalendar.set(Calendar.DAY_OF_WEEK, calendarDay); Locale locale = Locale.getDefault(); String localWeekDisplayName = mDayLabelCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, locale);//from w w w . ja v a 2 s .com String weekString = localWeekDisplayName.toUpperCase(locale).substring(0, 1); if (locale.equals(Locale.CHINA) || locale.equals(Locale.CHINESE) || locale.equals(Locale.SIMPLIFIED_CHINESE) || locale.equals(Locale.TRADITIONAL_CHINESE)) { int len = localWeekDisplayName.length(); weekString = localWeekDisplayName.substring(len - 1, len); } if (locale.getLanguage().equals("he") || locale.getLanguage().equals("iw")) { if (mDayLabelCalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) { int len = localWeekDisplayName.length(); weekString = localWeekDisplayName.substring(len - 2, len - 1); } else { // I know this is duplication, but it makes the code easier to grok by // having all hebrew code in the same block weekString = localWeekDisplayName.toUpperCase(locale).substring(0, 1); } } canvas.drawText(weekString, x, y, mMonthDayLabelPaint); } }
From source file:com.customdatepicker.date.MonthView.java
/** * Return a 1 or 2 letter String for use as a weekday label * * @param day The day for which to generate a label * @return The weekday label/* ww w . jav a2s . c o m*/ */ private String getWeekDayLabel(Calendar day) { Locale locale = Locale.getDefault(); // Localised short version of the string is not available on API < 18 if (Build.VERSION.SDK_INT < 18) { String dayName = new SimpleDateFormat("E", locale).format(day.getTime()); String dayLabel = dayName.toUpperCase(locale).substring(0, 1); // Chinese labels should be fetched right to left if (locale.equals(Locale.CHINA) || locale.equals(Locale.CHINESE) || locale.equals(Locale.SIMPLIFIED_CHINESE) || locale.equals(Locale.TRADITIONAL_CHINESE)) { int len = dayName.length(); dayLabel = dayName.substring(len - 1, len); } // Most hebrew labels should select the second to last character if (locale.getLanguage().equals("he") || locale.getLanguage().equals("iw")) { if (mDayLabelCalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) { int len = dayName.length(); dayLabel = dayName.substring(len - 2, len - 1); } else { // I know this is duplication, but it makes the code easier to grok by // having all hebrew code in the same block dayLabel = dayName.toUpperCase(locale).substring(0, 1); } } // Catalan labels should be two digits in lowercase if (locale.getLanguage().equals("ca")) dayLabel = dayName.toLowerCase().substring(0, 2); // Correct single character label in Spanish is X if (locale.getLanguage().equals("es") && day.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY) dayLabel = "X"; return dayLabel; } // Getting the short label is a one liner on API >= 18 if (weekDayLabelFormatter == null) { weekDayLabelFormatter = new SimpleDateFormat("EEEEE", locale); } return weekDayLabelFormatter.format(day.getTime()); }
From source file:org.openmrs.module.auditlog.CollectionsAuditLogBehaviorTest.java
@Test @NotTransactional/*from w ww . j a v a 2 s . co m*/ public void shouldNotLinkTheLogsOfCollectionItemsToThatOfTheUpdatedParentIfCascadeOptionIsNotDeleteOrphan() throws Exception { //TODO Add check that the cascade options is not delete option Concept concept = conceptService.getConcept(7); assertEquals(0, getAllLogs(concept.getId(), Concept.class, Collections.singletonList(UPDATED)).size()); int originalDescriptionCount = concept.getDescriptions().size(); assertTrue(originalDescriptionCount > 3); startAuditing(ConceptDescription.class); concept = conceptService.saveConcept(concept); //Ensure that no log will be created unless we actually perform an update assertEquals(0, getAllLogs(concept.getId(), Concept.class, Collections.singletonList(UPDATED)).size()); assertTrue(auditLogService.isAudited(ConceptDescription.class)); Iterator<ConceptDescription> it = concept.getDescriptions().iterator(); //update some existing descriptions ConceptDescription cd1 = it.next(); cd1.setDescription("another descr1"); ConceptDescription cd2 = it.next(); cd2.setDescription("another descr2"); //remove the next 2 ConceptDescription cd3 = it.next(); it.remove(); ConceptDescription cd4 = it.next(); it.remove(); ConceptDescription cd5 = new ConceptDescription("yes in japanese", Locale.JAPANESE); cd5.setUuid("6e9226f4-999d-11e2-a6ac-b499bae1ce4e"); cd5.setDateCreated(new Date()); cd5.setCreator(Context.getAuthenticatedUser()); ConceptDescription cd6 = new ConceptDescription("yes in chinese", Locale.CHINESE); cd6.setUuid("781f01b0-999d-11e2-a6ac-b499bae1ce4e"); cd6.setDateCreated(new Date()); cd6.setCreator(Context.getAuthenticatedUser()); concept.addDescription(cd5); concept.addDescription(cd6); concept = conceptService.saveConcept(concept); assertEquals(originalDescriptionCount, concept.getDescriptions().size()); List<AuditLog> descriptionAuditLogs1 = getAllLogs(cd1.getId(), ConceptDescription.class, Collections.singletonList(UPDATED)); assertEquals(1, descriptionAuditLogs1.size()); AuditLog descriptionAuditLog1 = descriptionAuditLogs1.get(0); assertNotNull(descriptionAuditLog1.getParentAuditLog()); List<AuditLog> descriptionAuditLogs2 = getAllLogs(cd2.getId(), ConceptDescription.class, Collections.singletonList(UPDATED)); assertEquals(1, descriptionAuditLogs2.size()); AuditLog descriptionAuditLog2 = descriptionAuditLogs2.get(0); assertNotNull(descriptionAuditLog2.getParentAuditLog()); List<AuditLog> descriptionAuditLogs3 = getAllLogs(cd3.getId(), ConceptDescription.class, Collections.singletonList(DELETED)); //This is because concept.descriptions cascade option doesn't say delete-orphan assertEquals(0, descriptionAuditLogs3.size()); List<AuditLog> descriptionAuditLogs4 = getAllLogs(cd4.getId(), ConceptDescription.class, Collections.singletonList(DELETED)); assertEquals(0, descriptionAuditLogs4.size());//same here List<AuditLog> descriptionAuditLogs5 = getAllLogs(cd5.getId(), ConceptDescription.class, Collections.singletonList(CREATED)); assertEquals(1, descriptionAuditLogs5.size()); AuditLog descriptionAuditLog5 = descriptionAuditLogs5.get(0); assertNotNull(descriptionAuditLog5.getParentAuditLog()); List<AuditLog> descriptionAuditLogs6 = getAllLogs(cd6.getId(), ConceptDescription.class, Collections.singletonList(CREATED)); assertEquals(1, descriptionAuditLogs6.size()); AuditLog descriptionAuditLog6 = descriptionAuditLogs6.get(0); assertNotNull(descriptionAuditLog6.getParentAuditLog()); List<AuditLog> conceptAuditLogs = getAllLogs(concept.getId(), Concept.class, Collections.singletonList(UPDATED)); assertEquals(1, conceptAuditLogs.size()); assertEquals(4, conceptAuditLogs.get(0).getChildAuditLogs().size()); assertEquals(conceptAuditLogs.get(0), descriptionAuditLog1.getParentAuditLog()); assertEquals(conceptAuditLogs.get(0), descriptionAuditLog2.getParentAuditLog()); }
From source file:org.alfresco.repo.search.impl.lucene.ADMLuceneTest.java
public void setUp() throws Exception { dialect = (Dialect) ctx.getBean("dialect"); nodeService = (NodeService) ctx.getBean("dbNodeService"); dictionaryService = (DictionaryService) ctx.getBean("dictionaryService"); dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO"); luceneFTS = (FullTextSearchIndexer) ctx.getBean("LuceneFullTextSearchIndexer"); contentService = (ContentService) ctx.getBean("contentService"); queryRegisterComponent = (QueryRegisterComponent) ctx.getBean("queryRegisterComponent"); namespacePrefixResolver = (DictionaryNamespaceComponent) ctx.getBean("namespaceService"); transformerDebug = (TransformerDebug) ctx.getBean("transformerDebug"); indexerAndSearcher = (IndexerAndSearcher) ctx.getBean("admLuceneIndexerAndSearcherFactory"); luceneConfig = (LuceneConfig) ctx.getBean("admLuceneIndexerAndSearcherFactory"); ((LuceneConfig) indexerAndSearcher).setMaxAtomicTransformationTime(1000000); transactionService = (TransactionService) ctx.getBean("transactionComponent"); retryingTransactionHelper = (RetryingTransactionHelper) ctx.getBean("retryingTransactionHelper"); tenantService = (TenantService) ctx.getBean("tenantService"); queryEngine = (QueryEngine) ctx.getBean("adm.luceneQueryEngineImpl"); nodeBulkLoader = (NodeBulkLoader) ctx.getBean("nodeDAO"); serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); namespaceDao = (NamespaceDAO) ctx.getBean("namespaceDAO"); I18NUtil.setLocale(Locale.UK); this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); queryRegisterComponent.loadQueryCollection("testQueryRegister.xml"); assertEquals(true, ctx.isSingleton("LuceneFullTextSearchIndexer")); testTX = transactionService.getUserTransaction(); testTX.begin();/*from w ww. ja v a 2 s .c om*/ this.authenticationComponent.setSystemUserAsCurrentUser(); // load in the test model ClassLoader cl = BaseNodeServiceTest.class.getClassLoader(); InputStream modelStream = cl .getResourceAsStream("org/alfresco/repo/search/impl/lucene/LuceneTest_model.xml"); assertNotNull(modelStream); model = M2Model.createModel(modelStream); dictionaryDAO.registerListener(this); dictionaryDAO.reset(); assertNotNull(dictionaryDAO.getClass(testSuperType)); StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); rootNodeRef = nodeService.getRootNode(storeRef); n1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), testSuperType, getOrderProperties()).getChildRef(); nodeService.setProperty(n1, QName.createQName("{namespace}property-1"), "ValueOne"); n2 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}two"), testSuperType, getOrderProperties()).getChildRef(); nodeService.setProperty(n2, QName.createQName("{namespace}property-1"), "valueone"); nodeService.setProperty(n2, QName.createQName("{namespace}property-2"), "valuetwo"); n3 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}three"), testSuperType, getOrderProperties()).getChildRef(); ObjectOutputStream oos; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); oos.writeObject(n3); oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); Object o = ois.readObject(); ois.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } Map<QName, Serializable> testProperties = new HashMap<QName, Serializable>(); testProperties.put(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic"), "TEXT THAT IS INDEXED STORED AND TOKENISED ATOMICALLY KEYONE"); testProperties.put(QName.createQName(TEST_NAMESPACE, "text-indexed-unstored-tokenised-atomic"), "TEXT THAT IS INDEXED STORED AND TOKENISED ATOMICALLY KEYUNSTORED"); testProperties.put(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-nonatomic"), "TEXT THAT IS INDEXED STORED AND TOKENISED BUT NOT ATOMICALLY KEYTWO"); testProperties.put(QName.createQName(TEST_NAMESPACE, "int-ista"), Integer.valueOf(1)); testProperties.put(QName.createQName(TEST_NAMESPACE, "long-ista"), Long.valueOf(2)); testProperties.put(QName.createQName(TEST_NAMESPACE, "float-ista"), Float.valueOf(3.4f)); testProperties.put(QName.createQName(TEST_NAMESPACE, "double-ista"), Double.valueOf(5.6)); //testDate = new Date(((new Date().getTime() - 10000))); Calendar c = new GregorianCalendar(); c.setTime(new Date(((new Date().getTime() - 10000)))); //c.add(Calendar.MINUTE, -1); //c.set(Calendar.MINUTE, 0); //c.set(Calendar.MILLISECOND, 999); //c.set(Calendar.SECOND, 1); //c.set(Calendar.MILLISECOND, 0); //c.set(Calendar.SECOND, 0); //c.set(Calendar.MINUTE, 0); //c.set(Calendar.HOUR_OF_DAY, 0); // c.set(Calendar.YEAR, 2000); // c.set(Calendar.MONTH, 12); // c.set(Calendar.DAY_OF_MONTH, 31); // c.set(Calendar.HOUR_OF_DAY, 23); // c.set(Calendar.MINUTE, 59); // c.set(Calendar.SECOND, 59); // c.set(Calendar.MILLISECOND, 999); testDate = c.getTime(); testProperties.put(QName.createQName(TEST_NAMESPACE, "date-ista"), testDate); testProperties.put(QName.createQName(TEST_NAMESPACE, "datetime-ista"), testDate); testProperties.put(QName.createQName(TEST_NAMESPACE, "boolean-ista"), Boolean.valueOf(true)); testProperties.put(QName.createQName(TEST_NAMESPACE, "qname-ista"), QName.createQName("{wibble}wobble")); testProperties.put(QName.createQName(TEST_NAMESPACE, "category-ista"), new NodeRef(storeRef, "CategoryId")); testProperties.put(QName.createQName(TEST_NAMESPACE, "noderef-ista"), n1); testProperties.put(QName.createQName(TEST_NAMESPACE, "path-ista"), nodeService.getPath(n3)); testProperties.put(QName.createQName(TEST_NAMESPACE, "locale-ista"), Locale.UK); testProperties.put(QName.createQName(TEST_NAMESPACE, "period-ista"), new Period("period|12")); testProperties.put(QName.createQName(TEST_NAMESPACE, "null"), null); testProperties.put(QName.createQName(TEST_NAMESPACE, "list"), new ArrayList<Object>()); MLText mlText = new MLText(); mlText.addValue(Locale.ENGLISH, "banana"); mlText.addValue(Locale.FRENCH, "banane"); mlText.addValue(Locale.CHINESE, ""); mlText.addValue(new Locale("nl"), "banaan"); mlText.addValue(Locale.GERMAN, "banane"); mlText.addValue(new Locale("el"), ""); mlText.addValue(Locale.ITALIAN, "banana"); mlText.addValue(new Locale("ja"), "?"); mlText.addValue(new Locale("ko"), ""); mlText.addValue(new Locale("pt"), "banana"); mlText.addValue(new Locale("ru"), ""); mlText.addValue(new Locale("es"), "pltano"); testProperties.put(QName.createQName(TEST_NAMESPACE, "ml"), mlText); // Any multivalued ArrayList<Serializable> anyValues = new ArrayList<Serializable>(); anyValues.add(Integer.valueOf(100)); anyValues.add("anyValueAsString"); anyValues.add(new UnknownDataType()); testProperties.put(QName.createQName(TEST_NAMESPACE, "any-many-ista"), anyValues); // Content multivalued // - note only one the first value is used from the collection // - andit has to go in type d:any as d:content is not allowed to be multivalued ArrayList<Serializable> contentValues = new ArrayList<Serializable>(); contentValues.add(new ContentData(null, "text/plain", 0L, "UTF-16", Locale.UK)); testProperties.put(QName.createQName(TEST_NAMESPACE, "content-many-ista"), contentValues); // MLText multivalued MLText mlText1 = new MLText(); mlText1.addValue(Locale.ENGLISH, "cabbage"); mlText1.addValue(Locale.FRENCH, "chou"); MLText mlText2 = new MLText(); mlText2.addValue(Locale.ENGLISH, "lemur"); mlText2.addValue(new Locale("ru"), ""); ArrayList<Serializable> mlValues = new ArrayList<Serializable>(); mlValues.add(mlText1); mlValues.add(mlText2); testProperties.put(QName.createQName(TEST_NAMESPACE, "mltext-many-ista"), mlValues); // null in multi valued ArrayList<Object> testList = new ArrayList<Object>(); testList.add(null); testProperties.put(QName.createQName(TEST_NAMESPACE, "nullist"), testList); ArrayList<Object> testList2 = new ArrayList<Object>(); testList2.add("woof"); testList2.add(null); n4 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}four"), testType, testProperties).getChildRef(); ContentWriter multiWriter = contentService.getWriter(n4, QName.createQName(TEST_NAMESPACE, "content-many-ista"), true); multiWriter.setEncoding("UTF-16"); multiWriter.setMimetype("text/plain"); multiWriter.putContent("multicontent"); nodeService.getProperties(n1); nodeService.getProperties(n2); nodeService.getProperties(n3); nodeService.getProperties(n4); n5 = nodeService.createNode(n1, ASSOC_TYPE_QNAME, QName.createQName("{namespace}five"), testSuperType, getOrderProperties()).getChildRef(); n6 = nodeService.createNode(n1, ASSOC_TYPE_QNAME, QName.createQName("{namespace}six"), testSuperType, getOrderProperties()).getChildRef(); n7 = nodeService.createNode(n2, ASSOC_TYPE_QNAME, QName.createQName("{namespace}seven"), testSuperType, getOrderProperties()).getChildRef(); n8 = nodeService.createNode(n2, ASSOC_TYPE_QNAME, QName.createQName("{namespace}eight-2"), testSuperType, getOrderProperties()).getChildRef(); n9 = nodeService.createNode(n5, ASSOC_TYPE_QNAME, QName.createQName("{namespace}nine"), testSuperType, getOrderProperties()).getChildRef(); n10 = nodeService.createNode(n5, ASSOC_TYPE_QNAME, QName.createQName("{namespace}ten"), testSuperType, getOrderProperties()).getChildRef(); n11 = nodeService.createNode(n5, ASSOC_TYPE_QNAME, QName.createQName("{namespace}eleven"), testSuperType, getOrderProperties()).getChildRef(); n12 = nodeService.createNode(n5, ASSOC_TYPE_QNAME, QName.createQName("{namespace}twelve"), testSuperType, getOrderProperties()).getChildRef(); n13 = nodeService.createNode(n12, ASSOC_TYPE_QNAME, QName.createQName("{namespace}thirteen"), testSuperType, getOrderProperties()).getChildRef(); Map<QName, Serializable> properties = new HashMap<QName, Serializable>(); MLText desc1 = new MLText(); desc1.addValue(Locale.ENGLISH, "Alfresco tutorial"); desc1.addValue(Locale.US, "Alfresco tutorial"); Date explicitCreatedDate = new Date(); Thread.sleep(2000); properties.put(ContentModel.PROP_CONTENT, new ContentData(null, "text/plain", 0L, "UTF-8", Locale.UK)); properties.put(ContentModel.PROP_DESCRIPTION, desc1); properties.put(ContentModel.PROP_CREATED, explicitCreatedDate); //Calendar c = new GregorianCalendar(); //c.setTime(new Date()); //c.set(Calendar.MILLISECOND, 0); //c.set(Calendar.SECOND, 0); //c.set(Calendar.MINUTE, 0); //c.set(Calendar.HOUR_OF_DAY, 0); //testDate = c.getTime(); //properties.put(QName.createQName(TEST_NAMESPACE, "date-ista"), testDate); //properties.put(QName.createQName(TEST_NAMESPACE, "datetime-ista"), testDate); // note: cm:content - hence auditable aspect will be applied with any missing mandatory properties (cm:modified, cm:creator, cm:modifier) n14 = nodeService.createNode(n13, ASSOC_TYPE_QNAME, QName.createQName("{namespace}fourteen"), ContentModel.TYPE_CONTENT, properties).getChildRef(); // nodeService.addAspect(n14, DictionaryBootstrap.ASPECT_QNAME_CONTENT, // properties); assertEquals(explicitCreatedDate, nodeService.getProperty(n14, ContentModel.PROP_CREATED)); // note: cm:thumbnail - hence auditable aspect will be applied with mandatory properties (cm:created, cm:modified, cm:creator, cm:modifier) n15 = nodeService.createNode(n13, ASSOC_TYPE_QNAME, QName.createQName("{namespace}fifteen"), ContentModel.TYPE_THUMBNAIL, getOrderProperties()).getChildRef(); nodeService.setProperty(n15, ContentModel.PROP_CONTENT, new ContentData(null, "text/richtext", 0L, "UTF-8", Locale.FRENCH)); ContentWriter writer = contentService.getWriter(n14, ContentModel.PROP_CONTENT, true); writer.setEncoding("UTF-8"); // InputStream is = // this.getClass().getClassLoader().getResourceAsStream("test.doc"); // writer.putContent(is); writer.putContent( "The quick brown fox jumped over the lazy dog and ate the Alfresco Tutorial, in pdf format, along with the following stop words; a an and are" + " as at be but by for if in into is it no not of on or such that the their then there these they this to was will with: " + " and random charcters \u00E0\u00EA\u00EE\u00F0\u00F1\u00F6\u00FB\u00FF"); // System.out.println("Size is " + writer.getSize()); writer = contentService.getWriter(n15, ContentModel.PROP_CONTENT, true); writer.setEncoding("UTF-8"); // InputStream is = // this.getClass().getClassLoader().getResourceAsStream("test.doc"); // writer.putContent(is); writer.putContent(" "); nodeService.addChild(rootNodeRef, n8, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}eight-0")); nodeService.addChild(n1, n8, ASSOC_TYPE_QNAME, QName.createQName("{namespace}eight-1")); nodeService.addChild(n2, n13, ASSOC_TYPE_QNAME, QName.createQName("{namespace}link")); nodeService.addChild(n1, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); nodeService.addChild(n2, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); nodeService.addChild(n5, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); nodeService.addChild(n6, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); nodeService.addChild(n12, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); nodeService.addChild(n13, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); documentOrder = new NodeRef[] { rootNodeRef, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n3, n1, n2 }; }
From source file:com.borax12.materialdaterangepicker.single.date.MonthView.java
/** * Return a 1 or 2 letter String for use as a weekday label * @param day The day for which to generate a label * @return The weekday label//from w w w. ja va 2 s. co m */ private String getWeekDayLabel(Calendar day) { Locale locale = Locale.getDefault(); // Localised short version of the string is not available on API < 18 if (Build.VERSION.SDK_INT < 18) { String dayName = new SimpleDateFormat("E", locale).format(day.getTime()); String dayLabel = dayName.toUpperCase(locale).substring(0, 1); // Chinese labels should be fetched right to left if (locale.equals(Locale.CHINA) || locale.equals(Locale.CHINESE) || locale.equals(Locale.SIMPLIFIED_CHINESE) || locale.equals(Locale.TRADITIONAL_CHINESE)) { int len = dayName.length(); dayLabel = dayName.substring(len - 1, len); } // Most hebrew labels should select the second to last character if (locale.getLanguage().equals("he") || locale.getLanguage().equals("iw")) { if (mDayLabelCalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) { int len = dayName.length(); dayLabel = dayName.substring(len - 2, len - 1); } else { // I know this is duplication, but it makes the code easier to grok by // having all hebrew code in the same block dayLabel = dayName.toUpperCase(locale).substring(0, 1); } } // Catalan labels should be two digits in lowercase if (locale.getLanguage().equals("ca")) dayLabel = dayName.toLowerCase().substring(0, 2); // Correct single character label in Spanish is X if (locale.getLanguage().equals("es") && day.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY) dayLabel = "X"; return dayLabel; } // Getting the short label is a one liner on API >= 18 return new SimpleDateFormat("EEEEE", locale).format(day.getTime()); }
From source file:com.jarklee.materialdatetimepicker.date.MonthView.java
/** * Return a 1 or 2 letter String for use as a weekday label * * @param day The day for which to generate a label * @return The weekday label//from w w w.j a v a 2 s . com */ private String getWeekDayLabel(Calendar day) { Locale locale = getLocale(); // Localised short version of the string is not available on API < 18 if (Build.VERSION.SDK_INT < 18) { String dayName = new SimpleDateFormat("E", locale).format(day.getTime()); String dayLabel = dayName.toUpperCase(locale).substring(0, 1); // Chinese labels should be fetched right to left if (locale.equals(Locale.CHINA) || locale.equals(Locale.CHINESE) || locale.equals(Locale.SIMPLIFIED_CHINESE) || locale.equals(Locale.TRADITIONAL_CHINESE)) { int len = dayName.length(); dayLabel = dayName.substring(len - 1, len); } // Most hebrew labels should select the second to last character if (locale.getLanguage().equals("he") || locale.getLanguage().equals("iw")) { if (mDayLabelCalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) { int len = dayName.length(); dayLabel = dayName.substring(len - 2, len - 1); } else { // I know this is duplication, but it makes the code easier to grok by // having all hebrew code in the same block dayLabel = dayName.toUpperCase(locale).substring(0, 1); } } // Catalan labels should be two digits in lowercase if (locale.getLanguage().equals("ca")) dayLabel = dayName.toLowerCase().substring(0, 2); // Correct single character label in Spanish is X if (locale.getLanguage().equals("es") && day.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY) dayLabel = "X"; return dayLabel; } // Getting the short label is a one liner on API >= 18 return new SimpleDateFormat("EEEEE", locale).format(day.getTime()); }
From source file:org.filteredpush.qc.date.DateUtils.java
/** * Given a string that may represent a date or range of dates, or date time or range of date times, * attempt to extract a standard date from that string. * //from www.j a va2s .co m * @param verbatimEventDate a string containing a verbatim event date. * @param yearsBeforeSuspect Dates that parse to a year prior to this year are marked as suspect. * @param assumemmddyyyy if true, assume that dates in the form nn-nn-nnnn are mm-dd-yyyy, if false, assume * that these are dd-mm-yyyy, if null, such dates are tested for ambiguity. * * @return an EventResult with a resultState for the nature of the match and result for the resulting date. */ public static EventResult extractDateFromVerbatimER(String verbatimEventDate, int yearsBeforeSuspect, Boolean assumemmddyyyy) { EventResult result = new EventResult(); String resultDate = null; // Remove some common no data comments if (verbatimEventDate != null && verbatimEventDate.contains("[no date]")) { verbatimEventDate = verbatimEventDate.replace("[no date]", ""); } if (verbatimEventDate != null && verbatimEventDate.contains("[no year]")) { verbatimEventDate = verbatimEventDate.replace("[no year]", ""); } // Strip off leading and trailing [] if (verbatimEventDate != null && verbatimEventDate.startsWith("[") && verbatimEventDate.endsWith("]")) { verbatimEventDate = verbatimEventDate.substring(1); verbatimEventDate = verbatimEventDate.substring(0, verbatimEventDate.length() - 1); } if (verbatimEventDate != null && verbatimEventDate.matches(".*\\[[0-9]+\\].*")) { verbatimEventDate = verbatimEventDate.replace("[", "").replace("]", ""); } // Strip off leading and trailing quotation marks if (verbatimEventDate != null && verbatimEventDate.startsWith("\"") && verbatimEventDate != null && verbatimEventDate.endsWith("\"")) { verbatimEventDate = verbatimEventDate.substring(1, verbatimEventDate.length() - 1); } // strip off leading and trailing whitespace if (verbatimEventDate != null && (verbatimEventDate.startsWith(" ") || verbatimEventDate.endsWith(" "))) { verbatimEventDate = verbatimEventDate.trim(); } // strip off trailing period after number if (verbatimEventDate != null && verbatimEventDate.endsWith(".") && verbatimEventDate.matches(".*[0-9]\\.$")) { verbatimEventDate = verbatimEventDate.substring(0, verbatimEventDate.length() - 1); logger.debug(verbatimEventDate); } // Stop before doing work if provided verbatim string is null. if (isEmpty(verbatimEventDate)) { return result; } if (verbatimEventDate.matches("^[0-9]{4}[-][0-9]{2}[-][0-9]{2}/[0-9]{4}[-][0-9]{2}[-][0-9]{2}$")) { // if verbatim date is a ISO formatted range with identical first and last dates (/), use just one. // Example: 1982-12-11/1982-12-11 changed to 1982-12-11 String[] bits = verbatimEventDate.split("/"); if (bits.length == 2 && bits[0].equals(bits[1])) { verbatimEventDate = bits[0]; } } if (verbatimEventDate.matches("^[0-9]{4}[/][0-9]{2}[/][0-9]{2}-[0-9]{4}[/][0-9]{2}[/][0-9]{2}$")) { // if verbatim date is a range with identical first and last dates (-), use just one. // Example: 1982/12/11-1982/12/11 changed to 1982/12/11 String[] bits = verbatimEventDate.split("-"); if (bits.length == 2 && bits[0].equals(bits[1])) { verbatimEventDate = bits[0]; } } if (verbatimEventDate .matches("^[0-9]{1,2}[-. ][0-9]{1,2}[-. ][0-9]{4}/[0-9]{1,2}[-. ][0-9]{1,2}[-. ][0-9]{4}$")) { // if verbatim date is a range with identical first and last dates (/), use just one. // Example: 12-11-1982/12-11-1982 changed to 12-11-1982 String[] bits = verbatimEventDate.split("/"); if (bits.length == 2 && bits[0].equals(bits[1])) { verbatimEventDate = bits[0]; } } if (verbatimEventDate .matches("^[0-9]{1,2}[./ ][0-9]{1,2}[./ ][0-9]{4}[-][0-9]{1,2}[./ ][0-9]{1,2}[./ ][0-9]{4}$")) { // if verbatim date is a range with identical first and last dates (-), use just one. // Example: 12/11/1982-12/11/1982 changed to 12/11/1982 String[] bits = verbatimEventDate.split("-"); if (bits.length == 2 && bits[0].equals(bits[1])) { verbatimEventDate = bits[0]; } } if (verbatimEventDate.matches("^[0-9]{4}[-]([0-9]{1,2}|[A-Za-z]+)[-][0-9]{1,2}.*")) { // Both separators are the same. // Example 1982-02-05 // Example 1982-Feb-05 // Example 1982-02-05 // Example 1982-02-05T05:03:06 try { DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyy/MM/dd").getParser(), DateTimeFormat.forPattern("yyyy/MMM/dd").getParser(), DateTimeFormat.forPattern("yyyy-MMM-dd").getParser(), ISODateTimeFormat.dateOptionalTimeParser().getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); DateMidnight parseDate = LocalDate.parse(verbatimEventDate, formatter).toDateMidnight(); resultDate = parseDate.toString("yyyy-MM-dd"); result.setResultState(EventResult.EventQCResultState.DATE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } if (verbatimEventDate.matches("^[0-9]{4}[/]([0-9]{1,2}|[A-Za-z]+)[/][0-9]{1,2}.*")) { // Both separators are the same. // Example 1982/02/05 // Example 1982/Feb/05 // Example 1982-02-05 // Example 1982/02/05T05:03:06 try { DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyy/MM/dd").getParser(), DateTimeFormat.forPattern("yyyy/MMM/dd").getParser(), DateTimeFormat.forPattern("yyyy-MMM-dd").getParser(), ISODateTimeFormat.dateOptionalTimeParser().getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); DateMidnight parseDate = LocalDate.parse(verbatimEventDate, formatter).toDateMidnight(); resultDate = parseDate.toString("yyyy-MM-dd"); result.setResultState(EventResult.EventQCResultState.DATE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } if (verbatimEventDate.matches("^[0-9]{4}[.,][0-9]{1,2}[.,][0-9]{1,2}$")) { // Example 1982.02.05 // Example 1982,02,05 // Cases where the 1-2 digit numbers are both smaller than 12 are treated as ambiguous. String resultDateMD = null; String resultDateDM = null; DateMidnight parseDate1 = null; DateMidnight parseDate2 = null; try { DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyy.MM.dd").getParser(), DateTimeFormat.forPattern("yyyy,MM,dd").getParser(), DateTimeFormat.forPattern("yyyy,MM.dd").getParser(), DateTimeFormat.forPattern("yyyy.MM,dd").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); parseDate1 = LocalDate.parse(verbatimEventDate, formatter).toDateMidnight(); resultDateMD = parseDate1.toString("yyyy-MM-dd"); } catch (Exception e) { logger.debug(e.getMessage()); } try { DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyy.dd.MM").getParser(), DateTimeFormat.forPattern("yyyy,dd,MM").getParser(), DateTimeFormat.forPattern("yyyy,dd.MM").getParser(), DateTimeFormat.forPattern("yyyy.dd,MM").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); parseDate2 = LocalDate.parse(verbatimEventDate, formatter).toDateMidnight(); resultDateDM = parseDate2.toString("yyyy-MM-dd"); } catch (Exception e) { logger.debug(e.getMessage()); } if (resultDateMD != null && resultDateDM == null) { result.setResultState(EventResult.EventQCResultState.DATE); result.setResult(resultDateMD); } else if (resultDateMD == null && resultDateDM != null) { result.setResultState(EventResult.EventQCResultState.DATE); result.setResult(resultDateDM); } else if (resultDateMD != null && resultDateDM != null) { if (resultDateMD.equals(resultDateDM)) { result.setResultState(EventResult.EventQCResultState.DATE); result.setResult(resultDateDM); } else { result.setResultState(EventResult.EventQCResultState.AMBIGUOUS); Interval range = null; if (parseDate1.isBefore(parseDate2)) { result.setResult(resultDateMD + "/" + resultDateDM); } else { result.setResult(resultDateDM + "/" + resultDateMD); } } } } if (verbatimEventDate.matches("^[0-9]{1,2}[-/ ][0-9]{4}")) { // Example 02/1982 try { DateTimeParser[] parsers = { DateTimeFormat.forPattern("MM-yyyy").getParser(), DateTimeFormat.forPattern("MM/yyyy").getParser(), DateTimeFormat.forPattern("MM yyyy").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); DateMidnight parseDate = LocalDate.parse(verbatimEventDate, formatter).toDateMidnight(); resultDate = parseDate.toString("yyyy-MM"); result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } if (verbatimEventDate.matches("^[0-9]{4}[0-9]{1,2}[0-9]{1,2}[?]$")) { // Example: 19720325 try { DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyyMMdd").getParser(), DateTimeFormat.forPattern("yyyyMMdd?").getParser(), ISODateTimeFormat.dateOptionalTimeParser().getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter() .withLocale(Locale.CHINESE); DateMidnight parseDate = LocalDate.parse(verbatimEventDate, formatter).toDateMidnight(); resultDate = parseDate.toString("yyyy-MM-dd"); result.setResultState(EventResult.EventQCResultState.DATE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } if (verbatimEventDate.matches("^[0-9]{4}[-][0-9]{3}/[0-9]{4}[-][0-9]{3}$")) { // Example: 1982-145 try { String[] bits = verbatimEventDate.split("/"); DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyy-D").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); LocalDate parseStartDate = LocalDate.parse(bits[0], formatter); LocalDate parseEndDate = LocalDate.parse(bits[1], formatter); resultDate = parseStartDate.toString("yyyy-MM-dd") + "/" + parseEndDate.toString("yyyy-MM-dd"); logger.debug(resultDate); result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN) && verbatimEventDate.matches("^[0-9]{4}0000$")) { // case 19800000 verbatimEventDate = verbatimEventDate.substring(0, 4); } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN) && verbatimEventDate.matches("^[0-9]{4}$")) { // Example: 1962 try { DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyy").getParser(), }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); DateMidnight parseDate = LocalDate.parse(verbatimEventDate, formatter).toDateMidnight(); resultDate = parseDate.toString("yyyy"); result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN) && verbatimEventDate.matches("^[12][0-9]{1}00[']{0,1}s$")) { // Example: 1900s try { String verbatimEventDateDelta = verbatimEventDate.replace("'s", "s"); DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyy's").getParser(), }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); DateMidnight parseDate = LocalDate.parse(verbatimEventDateDelta, formatter).toDateMidnight(); DateMidnight endDate = parseDate.plusYears(100).minusDays(1); resultDate = parseDate.toString("yyyy") + "-01-01/" + endDate.toString("yyyy") + "-12-31"; result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN) && verbatimEventDate.matches("^[12][0-9]{2}0[']{0,1}s$")) { // Example: 1970s try { String verbatimEventDateDelta = verbatimEventDate.replace("'s", "s"); DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyy's").getParser(), }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); DateMidnight parseDate = LocalDate.parse(verbatimEventDateDelta, formatter).toDateMidnight(); DateMidnight endDate = parseDate.plusYears(10).minusDays(1); resultDate = parseDate.toString("yyyy") + "-01-01/" + endDate.toString("yyyy") + "-12-31"; result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN) && verbatimEventDate.matches("^[A-Za-z]{3,9}[.]{0,1}[ ]{0,1}[-/ ][0-9]{4}$")) { // Example: Jan-1980 // Example: Jan./1980 // Example: January 1980 try { DateTimeParser[] parsers = { DateTimeFormat.forPattern("MMM-yyyy").getParser(), DateTimeFormat.forPattern("MMM/yyyy").getParser(), DateTimeFormat.forPattern("MMM /yyyy").getParser(), DateTimeFormat.forPattern("MMM yyyy").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); String cleaned = verbatimEventDate.replace(".", ""); DateMidnight parseDate = LocalDate.parse(cleaned, formatter).toDateMidnight(); resultDate = parseDate.toString("yyyy-MM"); result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN)) { // Example: 04/03/1994 (ambiguous) // Example: 04/20/1994 // Example: 20/04/1994 String resultDateMD = null; String resultDateDM = null; DateMidnight parseDate1 = null; DateMidnight parseDate2 = null; if (assumemmddyyyy == null || assumemmddyyyy) { try { DateTimeParser[] parsers = { DateTimeFormat.forPattern("MM/dd/yyyy").getParser(), DateTimeFormat.forPattern("MM/dd yyyy").getParser(), DateTimeFormat.forPattern("MM/dd-yyyy").getParser(), DateTimeFormat.forPattern("MM/dd, yyyy").getParser(), DateTimeFormat.forPattern("MM/dd,yyyy").getParser(), DateTimeFormat.forPattern("MM dd yyyy").getParser(), DateTimeFormat.forPattern("MM-dd-yyyy").getParser(), DateTimeFormat.forPattern("MM.dd.yyyy").getParser(), DateTimeFormat.forPattern("MM. dd. yyyy").getParser(), DateTimeFormat.forPattern("MM. dd. yyyy.").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers) .toFormatter(); parseDate1 = LocalDate.parse(verbatimEventDate, formatter).toDateMidnight(); resultDateMD = parseDate1.toString("yyyy-MM-dd"); } catch (Exception e) { logger.debug(e.getMessage()); } } if (assumemmddyyyy == null || !assumemmddyyyy) { try { DateTimeParser[] parsers = { DateTimeFormat.forPattern("dd/MM/yyyy").getParser(), DateTimeFormat.forPattern("dd/MM yyyy").getParser(), DateTimeFormat.forPattern("dd/MM-yyyy").getParser(), DateTimeFormat.forPattern("dd/MM, yyyy").getParser(), DateTimeFormat.forPattern("dd/MM,yyyy").getParser(), DateTimeFormat.forPattern("dd MM yyyy").getParser(), DateTimeFormat.forPattern("dd-MM-yyyy").getParser(), DateTimeFormat.forPattern("dd.MM.yyyy").getParser(), DateTimeFormat.forPattern("dd. MM. yyyy").getParser(), DateTimeFormat.forPattern("dd. MM. yyyy.").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers) .toFormatter(); parseDate2 = LocalDate.parse(verbatimEventDate, formatter).toDateMidnight(); resultDateDM = parseDate2.toString("yyyy-MM-dd"); } catch (Exception e) { logger.debug(e.getMessage()); } } if (resultDateMD != null && resultDateDM == null) { result.setResultState(EventResult.EventQCResultState.DATE); result.setResult(resultDateMD); } else if (resultDateMD == null && resultDateDM != null) { result.setResultState(EventResult.EventQCResultState.DATE); result.setResult(resultDateDM); } else if (resultDateMD != null && resultDateDM != null) { if (resultDateMD.equals(resultDateDM)) { result.setResultState(EventResult.EventQCResultState.DATE); result.setResult(resultDateDM); } else { result.setResultState(EventResult.EventQCResultState.AMBIGUOUS); Interval range = null; if (parseDate1.isBefore(parseDate2)) { result.setResult(resultDateMD + "/" + resultDateDM); } else { result.setResult(resultDateDM + "/" + resultDateMD); } } } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN) && verbatimEventDate.matches("^([0-9]{1,2}|[A-Za-z]+)[-/.]([0-9]{1,2}|[A-Za-z]+)[-/. ][0-9]{4}$")) { // Example: 03/Jan/1982 // Example: Jan-03-1982 try { DateTimeParser[] parsers = { DateTimeFormat.forPattern("MMM/dd/yyyy").getParser(), DateTimeFormat.forPattern("dd/MMM/yyyy").getParser(), DateTimeFormat.forPattern("MMM/dd yyyy").getParser(), DateTimeFormat.forPattern("dd/MMM yyyy").getParser(), DateTimeFormat.forPattern("MMM-dd-yyyy").getParser(), DateTimeFormat.forPattern("dd-MMM-yyyy").getParser(), DateTimeFormat.forPattern("MMM-dd yyyy").getParser(), DateTimeFormat.forPattern("dd-MMM yyyy").getParser(), DateTimeFormat.forPattern("MMM.dd.yyyy").getParser(), DateTimeFormat.forPattern("dd.MMM.yyyy").getParser(), DateTimeFormat.forPattern("MM.dd.yyyy").getParser(), DateTimeFormat.forPattern("dd.MM.yyyy").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); DateMidnight parseDate = LocalDate.parse(verbatimEventDate, formatter.withLocale(Locale.ENGLISH)) .toDateMidnight(); resultDate = parseDate.toString("yyyy-MM-dd"); result.setResultState(EventResult.EventQCResultState.DATE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN) && verbatimEventDate.matches("^[X*]{2}[-/. ]([0-9]{1,2}|[A-Za-z]+)[-/. ][0-9]{4}$")) { // Example: XX-04-1982 (XX for day) // Example: XX-Jan-1995 try { DateTimeParser[] parsers = { DateTimeFormat.forPattern("MMM/yyyy").getParser(), DateTimeFormat.forPattern("MMM yyyy").getParser(), DateTimeFormat.forPattern("MMM-yyyy").getParser(), DateTimeFormat.forPattern("MMM yyyy").getParser(), DateTimeFormat.forPattern("MMM.yyyy").getParser(), DateTimeFormat.forPattern("MM.yyyy").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); DateMidnight parseDate = LocalDate .parse(verbatimEventDate.substring(3), formatter.withLocale(Locale.ENGLISH)) .toDateMidnight(); resultDate = parseDate.toString("yyyy-MM"); result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN) && verbatimEventDate.matches("^[X*]{2}[-/. ][X*]{2,3}[-/. ][0-9]{4}$")) { // Example: XX-XXX-1995 // Example: **-**-1995 try { DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyy").getParser(), }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); String yearBit = verbatimEventDate.substring(verbatimEventDate.length() - 4); DateMidnight parseDate = LocalDate.parse(yearBit, formatter.withLocale(Locale.ENGLISH)) .toDateMidnight(); resultDate = parseDate.toString("yyyy"); result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } if (verbatimEventDate.matches("^[0-9]{4}[-][0-9]{3}$")) { // Example: 1994-128 (three digits after year = day of year). if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN)) { try { DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyy-D").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers) .toFormatter(); LocalDate parseDate = LocalDate.parse(verbatimEventDate, formatter); resultDate = parseDate.toString("yyyy-MM-dd"); logger.debug(resultDate); result.setResultState(EventResult.EventQCResultState.DATE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN)) { try { // Example: 1983-15 (two digits after year may fall into subsequent blocks). // Example: 1933-Mar DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyy/M").getParser(), DateTimeFormat.forPattern("yyyy-M").getParser(), DateTimeFormat.forPattern("yyyy-MMM").getParser(), DateTimeFormat.forPattern("yyyy.MMM").getParser(), DateTimeFormat.forPattern("yyyy.MMM.").getParser(), DateTimeFormat.forPattern("yyyy MMM.").getParser(), DateTimeFormat.forPattern("yyyy MMM").getParser(), DateTimeFormat.forPattern("yyyy. MMM.").getParser(), DateTimeFormat.forPattern("yyyy. MMM").getParser(), DateTimeFormat.forPattern("yyyy/MMM").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); String cleaned = cleanMonth(verbatimEventDate); LocalDate parseDate = LocalDate.parse(cleaned, formatter.withLocale(Locale.ENGLISH)); resultDate = parseDate.toString("yyyy-MM"); // resultDate = parseDate.dayOfMonth().withMinimumValue() + "/" + parseDate.dayOfMonth().withMaximumValue(); logger.debug(resultDate); if (verbatimEventDate.matches("^[0-9]{4}[-][0-9]{2}$")) { String century = verbatimEventDate.substring(0, 2); String startBit = verbatimEventDate.substring(0, 4); String endBit = verbatimEventDate.substring(5, 7); // 1815-16 won't parse here, passes to next block // 1805-06 could be month or abbreviated year // 1805-03 should to be month if (Integer.parseInt(startBit) >= Integer.parseInt(century + endBit)) { result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } else { result.setResultState(EventResult.EventQCResultState.SUSPECT); result.setResult(resultDate); } } else { result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN) && verbatimEventDate.matches("^[0-9]{4}[-][0-9]{2}$")) { // Example: 1884-85 (two digits look like year later in century). try { String century = verbatimEventDate.substring(0, 2); String startBit = verbatimEventDate.substring(0, 4); String endBit = verbatimEventDate.substring(5, 7); String assembly = startBit + "/" + century + endBit; logger.debug(assembly); Interval parseDate = Interval.parse(assembly); logger.debug(parseDate); resultDate = parseDate.getStart().toString("yyyy") + "/" + parseDate.getEnd().toString("yyyy"); result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN) && verbatimEventDate.matches("^[0-9]{4}[0-9]{2}[0-9]{2}$") && !verbatimEventDate.endsWith("0000")) { // Example: 19950315 try { DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyyMMdd").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); DateMidnight parseDate = LocalDate.parse(verbatimEventDate, formatter.withLocale(Locale.ENGLISH)) .toDateMidnight(); resultDate = parseDate.toString("yyyy-MM-dd"); result.setResultState(EventResult.EventQCResultState.DATE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN)) { // Example: 1845 try { DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyy").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); LocalDate parseDate = LocalDate.parse(verbatimEventDate, formatter); resultDate = parseDate.dayOfYear().withMinimumValue() + "/" + parseDate.dayOfYear().withMaximumValue(); logger.debug(resultDate); result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN)) { // Multiple yyyy-mmm-ddd, mmm-dd-yyyy, dd-mmm-yyyy patterns. try { DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyy MMM dd").getParser(), DateTimeFormat.forPattern("yyyy MMM. dd").getParser(), DateTimeFormat.forPattern("yyyy, MMM dd").getParser(), DateTimeFormat.forPattern("yyyy, MMM. dd").getParser(), DateTimeFormat.forPattern("yyyy.MMM.dd").getParser(), DateTimeFormat.forPattern("yyyy.MMM.dd.").getParser(), DateTimeFormat.forPattern("yyyy. MMM. dd").getParser(), DateTimeFormat.forPattern("yyyy. MMM. dd.").getParser(), DateTimeFormat.forPattern("yyyy. MMM dd.").getParser(), DateTimeFormat.forPattern("yyyy. MMM dd").getParser(), DateTimeFormat.forPattern("yyyy MMM. dd.").getParser(), DateTimeFormat.forPattern("yyyy: MMM. dd.").getParser(), DateTimeFormat.forPattern("yyyy: MMM. dd").getParser(), DateTimeFormat.forPattern("yyyy: MMM dd").getParser(), DateTimeFormat.forPattern("yyyy:MMM dd").getParser(), DateTimeFormat.forPattern("yyyy:MMM. dd").getParser(), DateTimeFormat.forPattern("yyyy:MMM.dd").getParser(), DateTimeFormat.forPattern("yyyy MMM dd'st'").getParser(), DateTimeFormat.forPattern("yyyy MMM. dd'st'").getParser(), DateTimeFormat.forPattern("yyyy MMM dd'nd'").getParser(), DateTimeFormat.forPattern("yyyy MMM. dd'nd'").getParser(), DateTimeFormat.forPattern("yyyy MMM dd'rd'").getParser(), DateTimeFormat.forPattern("yyyy MMM. dd'rd'").getParser(), DateTimeFormat.forPattern("yyyy MMM dd'th'").getParser(), DateTimeFormat.forPattern("yyyy MMM. dd'th'").getParser(), DateTimeFormat.forPattern("MMM dd, yyyy").getParser(), DateTimeFormat.forPattern("MMM dd., yyyy").getParser(), DateTimeFormat.forPattern("MMMdd, yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'st', yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'nd', yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'rd', yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'd', yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'th', yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd, yyyy").getParser(), DateTimeFormat.forPattern("MMM.dd, yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'st', yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'nd', yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'rd', yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'th', yyyy").getParser(), DateTimeFormat.forPattern("MMM.dd,yyyy").getParser(), DateTimeFormat.forPattern("MMM.dd'st',yyyy").getParser(), DateTimeFormat.forPattern("MMM.dd'nd',yyyy").getParser(), DateTimeFormat.forPattern("MMM.dd'rd',yyyy").getParser(), DateTimeFormat.forPattern("MMM.dd'd',yyyy").getParser(), DateTimeFormat.forPattern("MMM.dd'th',yyyy").getParser(), DateTimeFormat.forPattern("MMM.dd.yyyy").getParser(), DateTimeFormat.forPattern("MMM.dd'st'.yyyy").getParser(), DateTimeFormat.forPattern("MMM.dd'nd'.yyyy").getParser(), DateTimeFormat.forPattern("MMM.dd'rd'.yyyy").getParser(), DateTimeFormat.forPattern("MMM.dd'd'.yyyy").getParser(), DateTimeFormat.forPattern("MMM.dd'th'.yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'st'. yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'nd'. yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'rd'. yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'd'. yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'th'. yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'st'. yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'nd'. yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'rd'. yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'd'. yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'th'. yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'st'.yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'nd'.yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'rd'.yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'd'.yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'th'.yyyy").getParser(), DateTimeFormat.forPattern("MMM-dd-yyyy").getParser(), DateTimeFormat.forPattern("MMM-dd yyyy").getParser(), DateTimeFormat.forPattern("MMM-dd, yyyy").getParser(), DateTimeFormat.forPattern("dd-MMM-yyyy").getParser(), DateTimeFormat.forPattern("dd.MMM.yyyy").getParser(), DateTimeFormat.forPattern("dd,MMM,yyyy").getParser(), DateTimeFormat.forPattern("dd.MMM.,yyyy").getParser(), DateTimeFormat.forPattern("dd. MMM.,yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd. yyyy").getParser(), DateTimeFormat.forPattern("MMM, dd yyyy").getParser(), DateTimeFormat.forPattern("MMM, dd. yyyy").getParser(), DateTimeFormat.forPattern("MMM, dd, yyyy").getParser(), DateTimeFormat.forPattern("MMM, dd., yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd, yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd/yyyy").getParser(), DateTimeFormat.forPattern("MMM dd,yyyy").getParser(), DateTimeFormat.forPattern("MMM dd, yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd,yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd-yyyy").getParser(), DateTimeFormat.forPattern("MMM.dd-yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd, yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd., yyyy").getParser(), DateTimeFormat.forPattern("MMM., dd, yyyy").getParser(), DateTimeFormat.forPattern("MMM.,dd, yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'' yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'' yyyy").getParser(), DateTimeFormat.forPattern("dd. MMM. yyyy").getParser(), DateTimeFormat.forPattern("dd. MMM.yyyy").getParser(), DateTimeFormat.forPattern("dd MMM., yyyy").getParser(), DateTimeFormat.forPattern("dd MMM.,yyyy").getParser(), DateTimeFormat.forPattern("dd MMM,.yyyy").getParser(), DateTimeFormat.forPattern("dd MMM,. yyyy").getParser(), DateTimeFormat.forPattern("dd MMM..yyyy").getParser(), DateTimeFormat.forPattern("dd MMM, yyyy").getParser(), DateTimeFormat.forPattern("dd MMM yyyy").getParser(), DateTimeFormat.forPattern("dd MMM,yyyy").getParser(), DateTimeFormat.forPattern("dd MMM.yyyy").getParser(), DateTimeFormat.forPattern("ddMMM.yyyy").getParser(), DateTimeFormat.forPattern("ddMMM. yyyy").getParser(), DateTimeFormat.forPattern("dd.MMM-yyyy").getParser(), DateTimeFormat.forPattern("dd-MMM-yyyy").getParser(), DateTimeFormat.forPattern("dd.MMM yyyy").getParser(), DateTimeFormat.forPattern("dd. MMM yyyy").getParser(), DateTimeFormat.forPattern("dd, MMM, yyyy").getParser(), DateTimeFormat.forPattern("dd, MMM; yyyy").getParser(), DateTimeFormat.forPattern("dd. MMM; yyyy").getParser(), DateTimeFormat.forPattern("dd MMM-yyyy").getParser(), DateTimeFormat.forPattern("dd-MMM yyyy").getParser(), DateTimeFormat.forPattern("ddMMMyyyy").getParser(), DateTimeFormat.forPattern("MMM dd yyyy").getParser(), DateTimeFormat.forPattern("MMM dd/yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'st' yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'nd' yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'rd' yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'd' yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'th' yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'st' yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'nd' yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'rd' yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'd' yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'th' yyyy").getParser(), DateTimeFormat.forPattern("MMMdd yyyy").getParser(), DateTimeFormat.forPattern("MMM.dd yyyy").getParser(), DateTimeFormat.forPattern("dd MMM, yyyy").getParser(), DateTimeFormat.forPattern("dd'st' MMM, yyyy").getParser(), DateTimeFormat.forPattern("dd'nd' MMM, yyyy").getParser(), DateTimeFormat.forPattern("dd'rd' MMM, yyyy").getParser(), DateTimeFormat.forPattern("dd'd' MMM, yyyy").getParser(), DateTimeFormat.forPattern("dd'th MMM', yyyy").getParser(), DateTimeFormat.forPattern("dd MMM., yyyy").getParser(), DateTimeFormat.forPattern("dd'st' MMM., yyyy").getParser(), DateTimeFormat.forPattern("dd'nd' MMM., yyyy").getParser(), DateTimeFormat.forPattern("dd'rd' MMM., yyyy").getParser(), DateTimeFormat.forPattern("dd'th' MMM., yyyy").getParser(), DateTimeFormat.forPattern("dd MMM yyyy").getParser(), DateTimeFormat.forPattern("dd'st' MMM yyyy").getParser(), DateTimeFormat.forPattern("dd'nd' MMM yyyy").getParser(), DateTimeFormat.forPattern("dd'rd' MMM yyyy").getParser(), DateTimeFormat.forPattern("dd'd' MMM yyyy").getParser(), DateTimeFormat.forPattern("dd'th' MMM yyyy").getParser(), DateTimeFormat.forPattern("dd MMM. yyyy").getParser(), DateTimeFormat.forPattern("dd'st' MMM. yyyy").getParser(), DateTimeFormat.forPattern("dd'nd' MMM. yyyy").getParser(), DateTimeFormat.forPattern("dd'rd' MMM. yyyy").getParser(), DateTimeFormat.forPattern("dd'd' MMM. yyyy").getParser(), DateTimeFormat.forPattern("dd'th' MMM. yyyy").getParser(), DateTimeFormat.forPattern("dd'st' MMM, yyyy").getParser(), DateTimeFormat.forPattern("dd'nd' MMM, yyyy").getParser(), DateTimeFormat.forPattern("dd'rd' MMM, yyyy").getParser(), DateTimeFormat.forPattern("dd'd' MMM, yyyy").getParser(), DateTimeFormat.forPattern("dd'th' MMM, yyyy").getParser(), DateTimeFormat.forPattern("dd/MMM/yyyy").getParser(), DateTimeFormat.forPattern("dd/MMM yyyy").getParser(), DateTimeFormat.forPattern("MMM/dd yyyy").getParser(), DateTimeFormat.forPattern("MMM/dd/yyyy").getParser(), DateTimeFormat.forPattern("MMM dd. yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'st'. yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'nd'. yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'rd'. yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'th'. yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd. yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'st'. yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'nd'. yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'rd'. yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'th'. yyyy").getParser(), DateTimeFormat.forPattern("MMM dd.yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd.yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd-yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'st'-yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'nd'-yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'rd'-yyyy").getParser(), DateTimeFormat.forPattern("MMM. dd'th'-yyyy").getParser(), DateTimeFormat.forPattern("MMM dd-yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'st'-yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'nd'-yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'rd'-yyyy").getParser(), DateTimeFormat.forPattern("MMM dd'th'-yyyy").getParser(), DateTimeFormat.forPattern("yyyy-MMM-dd").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); String cleaned = cleanMonth(verbatimEventDate); cleaned = cleaned.replace("''", "'"); try { // Specify English locale, or local default will be used LocalDate parseDate = LocalDate.parse(cleaned, formatter.withLocale(Locale.ENGLISH)); resultDate = parseDate.toString("yyyy-MM-dd"); } catch (Exception e) { try { logger.debug(e.getMessage()); LocalDate parseDate = LocalDate.parse(cleaned, formatter.withLocale(Locale.FRENCH)); resultDate = parseDate.toString("yyyy-MM-dd"); } catch (Exception e1) { try { logger.debug(e1.getMessage()); LocalDate parseDate = LocalDate.parse(cleaned, formatter.withLocale(Locale.ITALIAN)); resultDate = parseDate.toString("yyyy-MM-dd"); } catch (Exception e2) { try { logger.debug(e2.getMessage()); LocalDate parseDate = LocalDate.parse(cleaned, formatter.withLocale(Locale.GERMAN)); resultDate = parseDate.toString("yyyy-MM-dd"); } catch (Exception e3) { try { logger.debug(e2.getMessage()); LocalDate parseDate = LocalDate.parse(cleaned, formatter.withLocale(Locale.forLanguageTag("es"))); resultDate = parseDate.toString("yyyy-MM-dd"); } catch (Exception e4) { logger.debug(e2.getMessage()); LocalDate parseDate = LocalDate.parse(cleaned, formatter.withLocale(Locale.forLanguageTag("pt"))); resultDate = parseDate.toString("yyyy-MM-dd"); } } } } } logger.debug(resultDate); result.setResultState(EventResult.EventQCResultState.DATE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } logger.debug(result.getResultState()); if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN)) { // Example: jan.-1992 // Example: January 1992 if (verbatimEventDate.matches(".*[0-9]{4}.*")) { try { DateTimeParser[] parsers = { DateTimeFormat.forPattern("MMM, yyyy").getParser(), DateTimeFormat.forPattern("MMM., yyyy").getParser(), DateTimeFormat.forPattern("MMM.,yyyy").getParser(), DateTimeFormat.forPattern("MMM.-yyyy").getParser(), DateTimeFormat.forPattern("MMM.yyyy").getParser(), DateTimeFormat.forPattern("MMM. yyyy").getParser(), DateTimeFormat.forPattern("MMM-yyyy").getParser(), DateTimeFormat.forPattern("MMM -yyyy").getParser(), DateTimeFormat.forPattern("MMM yyyy").getParser(), DateTimeFormat.forPattern("MMM/yyyy").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers) .toFormatter(); String cleaned = cleanMonth(verbatimEventDate); // Strip off a trailing period after a final year if (cleaned.matches("^.*[0-9]{4}[.]$")) { cleaned = cleaned.replaceAll("[.]$", ""); } LocalDate parseDate = LocalDate.parse(cleaned, formatter.withLocale(Locale.ENGLISH)); resultDate = parseDate.toString("yyyy-MM"); logger.debug(resultDate); result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN) && verbatimEventDate.matches("^[0-9]{4}([- ]+| to |[/ ]+)[0-9]{4}$")) { // Example: 1882-1995 // Example: 1882 to 1885 // Example: 1882/1885 try { String cleaned = verbatimEventDate.replace(" ", ""); cleaned = cleaned.replace("-", "/"); if (cleaned.matches("^[0-9]{4}to[0-9]{4}$")) { int len = verbatimEventDate.length(); int lastYear = len - 4; cleaned = verbatimEventDate.substring(0, 4) + "/" + verbatimEventDate.substring(lastYear, len); } logger.debug(cleaned); Interval parseDate = Interval.parse(cleaned); logger.debug(parseDate); resultDate = parseDate.getStart().toString("yyyy") + "/" + parseDate.getEnd().toString("yyyy"); result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN) && verbatimEventDate .matches("^[A-Za-z]+[.]{0,1}( and | to |[-][ ]{0,1}| [-] )[A-Za-z]+[.]{0,1}(, |[/ .])[0-9]{4}$")) { logger.debug(verbatimEventDate); // Example: Jan to Feb 1882 // Example: Jan-Feb/1882 verbatimEventDate = verbatimEventDate.replace(", ", " "); if (verbatimEventDate.matches("^[A-Za-z]+[.]{0,1}[-][A-Za-z]+[.]{0,1}[.][0-9]{4}$")) { // transform case with multiple periods to slash before year. verbatimEventDate = verbatimEventDate.substring(0, verbatimEventDate.length() - 5) + "/" + verbatimEventDate.substring(verbatimEventDate.length() - 4); logger.debug(verbatimEventDate); } if (verbatimEventDate.matches("^[A-Za-z]+[.]{0,1}[ ][-][ ]{1}[A-Za-z]+[.]{0,1}[/ .][0-9]{4}$")) { // remove space around dash. verbatimEventDate = verbatimEventDate.replace(" - ", "-"); logger.debug(verbatimEventDate); } if (verbatimEventDate.matches("^[A-Za-z]+[.]{0,1}[-][ ]{1}[A-Za-z]+[.]{0,1}[/ .][0-9]{4}$")) { // remove space trailing after dash. verbatimEventDate = verbatimEventDate.replace("- ", "-"); logger.debug(verbatimEventDate); } if (verbatimEventDate.matches("^[A-Za-z]+[.]{0,1} and {1}[A-Za-z]+[.]{0,1}[/ .][0-9]{4}$")) { // replace and with dash verbatimEventDate = verbatimEventDate.replace(" and ", "-"); logger.debug(verbatimEventDate); } if (verbatimEventDate.matches("^[A-Za-z]+[.]{0,1} to {1}[A-Za-z]+[.]{0,1}[/ .][0-9]{4}$")) { // replace to with dash verbatimEventDate = verbatimEventDate.replace(" to ", "-"); logger.debug(verbatimEventDate); } try { String[] bits = verbatimEventDate.replace(" ", "/").split("-"); if (bits != null && bits.length == 2) { String year = verbatimEventDate.substring(verbatimEventDate.length() - 4, verbatimEventDate.length()); String startBit = bits[0] + "/" + year; DateTimeParser[] parsers = { DateTimeFormat.forPattern("MMM/yyyy").getParser(), DateTimeFormat.forPattern("MMM./yyyy").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers) .toFormatter(); LocalDate parseStartDate = LocalDate.parse(cleanMonth(startBit), formatter.withLocale(Locale.ENGLISH)); LocalDate parseEndDate = LocalDate.parse(cleanMonth(bits[1]), formatter.withLocale(Locale.ENGLISH)); resultDate = parseStartDate.toString("yyyy-MM") + "/" + parseEndDate.toString("yyyy-MM"); logger.debug(resultDate); result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN) && verbatimEventDate.matches( "^[0-9]{1,2}[ /.]{0,1}[A-Za-z]+[.]{0,1}( - |[-])[0-9]{1,2}[ /.]{0,1}[A-Za-z]+[.]{0,1}[/ -.][0-9]{4}$")) { logger.debug(verbatimEventDate); // Example: 05/Jan/1882-03/Feb/1885 if (verbatimEventDate.matches( "^[0-9]{1,2}[ /.]{0,1}[A-Za-z]+[.]{0,1}[-][0-9]{1,2}[ /.]{0,1}[A-Za-z]+[.]{0,1}[-][0-9]{4}$")) { // transform case with multiple dashes to slash before year. verbatimEventDate = verbatimEventDate.substring(0, verbatimEventDate.length() - 5) + "/" + verbatimEventDate.substring(verbatimEventDate.length() - 4); logger.debug(verbatimEventDate); } if (verbatimEventDate.matches( "^[0-9]{1,2}[ /.]{0,1}[A-Za-z]+[.]{0,1}[-][0-9]{1,2}[ /.]{0,1}[A-Za-z]+[.]{0,1}[.][0-9]{4}$")) { // transform case with multiple periods to slash before year. verbatimEventDate = verbatimEventDate.substring(0, verbatimEventDate.length() - 5) + "/" + verbatimEventDate.substring(verbatimEventDate.length() - 4); logger.debug(verbatimEventDate); } try { String[] bits = verbatimEventDate.replace(" - ", "-").replace(" ", "/").split("-"); if (bits != null && bits.length == 2) { String year = verbatimEventDate.substring(verbatimEventDate.length() - 4, verbatimEventDate.length()); String startBit = bits[0] + "/" + year; logger.debug(cleanMonth(startBit)); logger.debug(cleanMonth(bits[1])); DateTimeParser[] parsers = { DateTimeFormat.forPattern("dd MMM/yyyy").getParser(), DateTimeFormat.forPattern("dd.MMM/yyyy").getParser(), DateTimeFormat.forPattern("dd/MMM/yyyy").getParser(), DateTimeFormat.forPattern("ddMMM/yyyy").getParser(), DateTimeFormat.forPattern("dd MMM./yyyy").getParser(), DateTimeFormat.forPattern("dd.MMM./yyyy").getParser(), DateTimeFormat.forPattern("dd/MMM./yyyy").getParser(), DateTimeFormat.forPattern("ddMMM./yyyy").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers) .toFormatter(); LocalDate parseStartDate = LocalDate.parse(cleanMonth(startBit), formatter.withLocale(Locale.ENGLISH)); LocalDate parseEndDate = LocalDate.parse(cleanMonth(bits[1]), formatter.withLocale(Locale.ENGLISH)); resultDate = parseStartDate.toString("yyyy-MM-dd") + "/" + parseEndDate.toString("yyyy-MM-dd"); logger.debug(resultDate); result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN) && verbatimEventDate.matches( "^[A-Za-z]+[.]{0,1}[ ]{0,1}[0-9]{1,2}( - |[-]| to | and | et )[A-Za-z]+[.]{0,1}[ ]{0,1}[0-9]{1,2}[/ .,][ ]{0,1}[0-9]{4}$")) { logger.debug(verbatimEventDate); // Example: Aug. 5 - Sept. 8, 1943 try { String[] bits = verbatimEventDate.replace(" to ", "-").replace(" - ", "-").replace(" and ", "-") .replace(" et ", "-").replace(", ", " ").replace(" ", "/").split("-"); if (bits != null && bits.length == 2) { String year = verbatimEventDate.substring(verbatimEventDate.length() - 4, verbatimEventDate.length()); String startBit = bits[0] + "/" + year; logger.debug(cleanMonth(startBit)); logger.debug(cleanMonth(bits[1])); DateTimeParser[] parsers = { DateTimeFormat.forPattern("MMM/dd/yyyy").getParser(), DateTimeFormat.forPattern("MMM./dd/yyyy").getParser(), DateTimeFormat.forPattern("MMM.dd/yyyy").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers) .toFormatter(); LocalDate parseStartDate = LocalDate.parse(cleanMonth(startBit), formatter.withLocale(Locale.ENGLISH)); LocalDate parseEndDate = LocalDate.parse(cleanMonth(bits[1]), formatter.withLocale(Locale.ENGLISH)); resultDate = parseStartDate.toString("yyyy-MM-dd") + "/" + parseEndDate.toString("yyyy-MM-dd"); logger.debug(resultDate); result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN) && verbatimEventDate.matches( "^[0-9]{1,2}([ ]{0,1}[-][ ]{0,1}| and | et | to )[0-9]{1,2}[ /.]{0,1}[A-Za-z]+[.]{0,1}[/ -.][0-9]{4}$")) { // Example: 11 et 14 VII 1910 // Example: 05-02 Jan./1992 String toCheck = verbatimEventDate; toCheck = toCheck.replace(" - ", "-").replace(" et ", "-").replace(" and ", "-").replace(" to ", "-"); // Note: "and" has different semantics than "to", may imply that a specimen record // represents two occurrences (e.g. flower on one date, fruit on another) rather than // a range, but dwc:eventDate representation for both forms on one event is a range. if (toCheck.matches("^[0-9]{1,2}[-][0-9]{1,2}[ /.]{0,1}[A-Za-z]+[.]{0,1}[-][0-9]{4}$")) { // transform case with multiple dashes to slash before year. toCheck = toCheck.substring(0, toCheck.length() - 5) + "/" + toCheck.substring(toCheck.length() - 4); logger.debug(toCheck); } if (toCheck.matches("^[0-9]{1,2}[-][0-9]{1,2}[ /.]{0,1}[A-Za-z]+[.]{0,1}[.][0-9]{4}$")) { // transform case with multiple periods to slash before year. toCheck = toCheck.substring(0, toCheck.length() - 5) + "/" + toCheck.substring(toCheck.length() - 4); logger.debug(toCheck); } try { String[] bits = toCheck.replace(" ", "/").split("-"); if (bits != null && bits.length == 2) { String year = toCheck.substring(toCheck.length() - 4, toCheck.length()); logger.debug(cleanMonth(bits[1])); DateTimeParser[] parsers = { DateTimeFormat.forPattern("dd MMM/yyyy").getParser(), DateTimeFormat.forPattern("dd.MMM/yyyy").getParser(), DateTimeFormat.forPattern("dd/MMM/yyyy").getParser(), DateTimeFormat.forPattern("ddMMM/yyyy").getParser(), DateTimeFormat.forPattern("dd MMM./yyyy").getParser(), DateTimeFormat.forPattern("dd.MMM./yyyy").getParser(), DateTimeFormat.forPattern("dd/MMM./yyyy").getParser(), DateTimeFormat.forPattern("ddMMM./yyyy").getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers) .toFormatter(); LocalDate parseEndDate = LocalDate.parse(cleanMonth(bits[1]), formatter.withLocale(Locale.ENGLISH)); String startMonthYear = parseEndDate.toString("MMM/yyyy"); String startBit = bits[0] + "/" + startMonthYear; logger.debug(startBit); LocalDate parseStartDate = LocalDate.parse(startBit, formatter.withLocale(Locale.ENGLISH)); resultDate = parseStartDate.toString("yyyy-MM-dd") + "/" + parseEndDate.toString("yyyy-MM-dd"); logger.debug(resultDate); result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN) && verbatimEventDate.matches("^[0-9]{2}[-. ]XXX[-. ][0-9]{4}$")) { // Example: 05-XXX-1884 try { String start = verbatimEventDate.substring(verbatimEventDate.length() - 4) + "-01-" + verbatimEventDate.substring(0, 2); String end = verbatimEventDate.substring(verbatimEventDate.length() - 4) + "-12-" + verbatimEventDate.substring(0, 2); EventResult compositeResult = DateUtils.extractDateFromVerbatimER(start + "/" + end, yearsBeforeSuspect, assumemmddyyyy); logger.debug(compositeResult.getResultState()); if (compositeResult.getResultState().equals(EventResult.EventQCResultState.RANGE)) { result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(compositeResult.getResult()); logger.debug(result.getResult()); } } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN) && verbatimEventDate.matches("^[0-9]{4}-[0-9]{2}/[0-9]{4}-[0-9]{2}$")) { // Example: 1885-03/1886-04 try { Interval parseDate = Interval.parse(verbatimEventDate); logger.debug(parseDate); resultDate = parseDate.getStart().toString("yyyy-MM") + "/" + parseDate.getEnd().toString("yyyy-MM"); result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN)) { // Example: 1995-03-05/1996-05-08 try { Interval parseDate = Interval.parse(verbatimEventDate); logger.debug(parseDate); resultDate = parseDate.getStart().toString("yyyy-MM-dd") + "/" + parseDate.getEnd().toString("yyyy-MM-dd"); result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultDate); } catch (Exception e) { logger.debug(e.getMessage()); } } if (result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN)) { // Example: Jan,15-18 1882 // Example: Jan. 17 and 18 1882 String cleaned = verbatimEventDate.trim(); if (verbatimEventDate.matches("^[A-Za-z.]+[ ,]+[0-9]{1,2} and [0-9]{0,2}[ ,]+[0-9]{4}$")) { // Note: "and" has different semantics than "to", may imply that a specimen record // represents two occurrences (e.g. flower on one date, fruit on another) rather than // a range, but dwc:eventDate representation for both forms on one event is a range. cleaned = cleaned.replace(" and ", " to "); } if (verbatimEventDate.matches("^[A-Za-z.]+[ ,]+[0-9]{1,2}-[0-9]{0,2}[ ,]+[0-9]{4}$")) { cleaned = cleaned.replace("-", " to "); } if (cleaned.contains(" to ")) { String[] bits = cleaned.split(" to "); String yearRegex = ".*([0-9]{4}).*"; Matcher yearMatcher = Pattern.compile(yearRegex).matcher(cleaned); String monthRegex = "([A-Za-z.]+).*"; Matcher monthMatcher = Pattern.compile(monthRegex).matcher(cleaned); if (yearMatcher.matches() && monthMatcher.matches()) { String year = yearMatcher.group(1); String month = monthMatcher.group(1); if (bits.length == 2) { if (!bits[0].contains(year)) { bits[0] = bits[0] + " " + year; } if (!bits[1].contains(year)) { bits[1] = bits[1] + " " + year; } if (!bits[1].contains(month)) { bits[1] = month + " " + bits[1]; } Map<String, String> resultBit0 = DateUtils.extractDateFromVerbatim(bits[0]); if (resultBit0.size() > 0 && resultBit0.get("resultState").equals("date")) { Map<String, String> resultBit1 = DateUtils.extractDateFromVerbatim(bits[1]); if (resultBit1.size() > 0 && resultBit1.get("resultState").equals("date")) { result.setResultState(EventResult.EventQCResultState.RANGE); result.setResult(resultBit0.get("result") + "/" + resultBit1.get("result")); } } logger.debug(bits[0]); logger.debug(bits[1]); } } } } // Now test to see if result is sane. if (result != null && !result.getResultState().equals(EventResult.EventQCResultState.NOT_RUN)) { Interval testExtract = DateUtils.extractDateInterval(result.getResult()); if (testExtract == null || testExtract.getStart().getYear() < yearsBeforeSuspect) { result.setResultState(EventResult.EventQCResultState.SUSPECT); logger.debug(result.getResult()); logger.debug(testExtract); } else { logger.debug(result.getResult()); } if (!verbatimEventDate.matches(".*[0-9]{4}.*") && yearsBeforeSuspect > 999) { result = new EventResult(); logger.debug(result.getResult()); } } return result; }
From source file:org.alfresco.repo.search.impl.lucene.ADMLuceneTest.java
private void runBaseTests() throws LuceneIndexException, IOException { ADMLuceneSearcherImpl searcher = buildSearcher(); ResultSet results;/*from w w w . j a v a 2 s . c o m*/ results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/.\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:three\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:four\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:eight-0\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:five\"", null); assertEquals(0, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:one\"", null); assertEquals(0, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:two\"", null); assertEquals(0, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:one\"", null); assertEquals(0, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:two\"", null); assertEquals(0, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:six\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:seven\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-1\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-2\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-2\"", null); assertEquals(0, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-1\"", null); assertEquals(0, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-0\"", null); assertEquals(0, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-0\"", null); assertEquals(0, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:nine\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:ten\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:eleven\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen/namespace:fourteen\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen/namespace:common\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:common\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*\"", null); assertEquals(5, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/namespace:*/namespace:*\"", null); assertEquals(8, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*\"", null); assertEquals(6, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:five\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/namespace:*/namespace:*/namespace:*\"", null); assertEquals(9, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*/namespace:*\"", null); assertEquals(6, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:*\"", null); assertEquals(4, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:five/namespace:*\"", null); assertEquals(5, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:*/namespace:nine\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*\"", null); assertEquals(5, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/*/*\"", null); assertEquals(8, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*\"", null); assertEquals(6, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/*/*/*\"", null); assertEquals(9, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*/*\"", null); assertEquals(6, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*\"", null); assertEquals(4, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five/*\"", null); assertEquals(5, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*/namespace:nine\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//.\"", null); assertEquals(28, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//.\"", null); assertEquals(16, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*\"", null); assertEquals(15, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*\"", null); assertEquals(27, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/.\"", null); assertEquals(15, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*/.\"", null); assertEquals(27, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/./.\"", null); assertEquals(15, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*/./.\"", null); assertEquals(27, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//./*\"", null); assertEquals(27, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//./*\"", null); assertEquals(15, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//././*/././.\"", null); assertEquals(15, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//././*/././.\"", null); assertEquals(27, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//common\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//common\"", null); assertEquals(7, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//common\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/one//common\"", null); assertEquals(5, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//*\"", null); assertEquals(7, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/one/five//*\"", null); assertEquals(10, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//.\"", null); assertEquals(8, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/one/five//.\"", null); assertEquals(11, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//five/nine\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen/.\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen//.\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen//.//.\"", null); assertEquals(1, results.length()); results.close(); // QNames results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "QNAME:\"nine\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PRIMARYASSOCTYPEQNAME:\"lucene-test:assoc\"", null); assertEquals(11, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "ASSOCTYPEQNAME:\"lucene-test:assoc\"", null); assertEquals(11, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PRIMARYASSOCTYPEQNAME:\"sys:children\"", null); assertEquals(4, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "ASSOCTYPEQNAME:\"sys:children\"", null); assertEquals(5, results.length()); results.close(); // Type search tests QName qname = QName.createQName(TEST_NAMESPACE, "int-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"1\"", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "int-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":1", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "int-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"01\"", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "int-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":01", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "int-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + escapeQName(qname) + ":\"001\"", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "int-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@lucene-test\\:int\\-ista:\"0001\"", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "int-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[A TO 2]", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "int-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[0 TO 2]", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "int-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[0 TO A]", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "int-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{A TO 1}", null); assertEquals(0, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "int-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{0 TO 1}", null); assertEquals(0, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "int-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{0 TO A}", null); assertEquals(1, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "int-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{A TO 2}", null); assertEquals(1, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "int-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{1 TO 2}", null); assertEquals(0, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "int-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{1 TO A}", null); assertEquals(0, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "long-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"2\"", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "long-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"02\"", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "long-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"002\"", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "long-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"0002\"", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "long-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[A TO 2]", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "long-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[0 TO 2]", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "long-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[0 TO A]", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "long-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{A TO 2}", null); assertEquals(0, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "long-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{0 TO 2}", null); assertEquals(0, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "long-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{0 TO A}", null); assertEquals(1, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "long-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{A TO 3}", null); assertEquals(1, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "long-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{2 TO 3}", null); assertEquals(0, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "long-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{2 TO A}", null); assertEquals(0, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "float-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"3.4\"", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "float-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[A TO 4]", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "float-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[3 TO 4]", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "float-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[3 TO A]", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "float-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[A TO 3.4]", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "float-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[3.3 TO 3.4]", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "float-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[3.3 TO A]", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "float-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{A TO 3.4}", null); assertEquals(0, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "float-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[3.3 TO 3.4]", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "float-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[3.3 TO A]", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "float-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"3.40\"", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "float-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"03.4\"", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "float-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"03.40\"", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "double-ista")) + ":\"5.6\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "double-ista")) + ":\"05.6\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "double-ista")) + ":\"5.60\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "double-ista")) + ":\"05.60\"", null); assertEquals(1, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "double-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[A TO 5.7]", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "double-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[5.5 TO 5.7]", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "double-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[5.5 TO A]", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); qname = QName.createQName(TEST_NAMESPACE, "double-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{A TO 5.6}", null); assertEquals(0, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "double-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{5.5 TO 5.6}", null); assertEquals(0, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "double-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{5.5 TO A}", null); assertEquals(1, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "double-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{A TO 5.7}", null); assertEquals(1, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "double-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{5.6 TO 5.7}", null); assertEquals(0, results.length()); results.close(); qname = QName.createQName(TEST_NAMESPACE, "double-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{5.6 TO A}", null); assertEquals(0, results.length()); results.close(); // Dates PropertyDefinition propertyDef = dictionaryService .getProperty(QName.createQName(TEST_NAMESPACE, "datetime-ista")); DataTypeDefinition dataType = propertyDef.getDataType(); String analyserClassName = propertyDef.resolveAnalyserClassName(); boolean usesDateTimeAnalyser = analyserClassName.equals(DateTimeAnalyser.class.getCanonicalName()); Date date = new Date(); for (SimpleDateFormatAndResolution df : CachingDateFormat.getLenientFormatters()) { if (!usesDateTimeAnalyser && (df.getResolution() < Calendar.DAY_OF_MONTH)) { continue; } System.out.println("Date format: " + df.getSimpleDateFormat()); // if(usesDateTimeAnalyser && (df.getSimpleDateFormat().format(date).length() < 22)) // { // continue; // } // String sDate = df.getSimpleDateFormat().format(date); // results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "DATE-ista")) + ":\"" + sDate + "\"", null); // assertEquals(1, results.length()); // results.close(); // // results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":\"" + sDate + "\"", null); // assertEquals(usesDateTimeAnalyser ? 0 : 1, results.length()); // results.close(); String sDate = df.getSimpleDateFormat().format(testDate); if (sDate.length() >= 9) { results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "date-ista")) + ":\"" + sDate + "\"", null); assertEquals(1, results.length()); results.close(); } results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":\"" + sDate + "\"", null); assertEquals(1, results.length()); results.close(); // short and long field ranges // note: expected 2 results = n14 (cm:content) and n15 (cm:thumbnail) sDate = df.getSimpleDateFormat().format(date); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@cm\\:CrEaTeD:[MIN TO " + sDate + "]", null); assertEquals(2, results.length()); assertTrue("n14 not in results", (results.getNodeRef(0).equals(n14) || results.getNodeRef(1).equals(n14))); assertTrue("n15 not in results", (results.getNodeRef(0).equals(n15) || results.getNodeRef(1).equals(n15))); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@cm\\:created:[MIN TO NOW]", null); assertEquals(2, results.length()); assertTrue("n14 not in results", (results.getNodeRef(0).equals(n14) || results.getNodeRef(1).equals(n14))); assertTrue("n15 not in results", (results.getNodeRef(0).equals(n15) || results.getNodeRef(1).equals(n15))); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@cm\\:created:[MIN TO NOW]", null); assertEquals(2, results.length()); assertTrue("n14 not in results", (results.getNodeRef(0).equals(n14) || results.getNodeRef(1).equals(n14))); assertTrue("n15 not in results", (results.getNodeRef(0).equals(n15) || results.getNodeRef(1).equals(n15))); results.close(); sDate = df.getSimpleDateFormat().format(date); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(ContentModel.PROP_CREATED) + ":[MIN TO " + sDate + "]", null); assertEquals(2, results.length()); assertTrue("n14 not in results", (results.getNodeRef(0).equals(n14) || results.getNodeRef(1).equals(n14))); assertTrue("n15 not in results", (results.getNodeRef(0).equals(n15) || results.getNodeRef(1).equals(n15))); results.close(); // Date ranges // Test date collapses but date time does not if (sDate.length() >= 9) { sDate = df.getSimpleDateFormat().format(testDate); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "date-ista")) + ":[" + sDate + " TO " + sDate + "]", null); assertEquals(1, results.length()); results.close(); sDate = df.getSimpleDateFormat().format(testDate); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "date-ista")) + ":[MIN TO " + sDate + "]", null); assertEquals(1, results.length()); results.close(); sDate = df.getSimpleDateFormat().format(testDate); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "date-ista")) + ":[" + sDate + " TO MAX]", null); assertEquals(1, results.length()); results.close(); } if (!usesDateTimeAnalyser) { // with date time the result is indeterminate sDate = CachingDateFormat.getDateFormat().format(testDate); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":[" + sDate + " TO " + sDate + "]", null); assertEquals(1, results.length()); results.close(); } sDate = CachingDateFormat.getDateFormat().format(testDate); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":[MIN TO " + sDate + "]", null); assertEquals(1, results.length()); results.close(); sDate = CachingDateFormat.getDateFormat().format(testDate); System.out.println("SD = " + sDate); System.out.println("D = " + date); if (!usesDateTimeAnalyser) { results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":\"" + sDate + "\"", null); //TODO: Fix date time resolution - uses 000 MS assertEquals(1, results.length()); results.close(); } if (!usesDateTimeAnalyser) { results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":[" + sDate + " TO MAX]", null); assertEquals(1, results.length()); results.close(); } if (usesDateTimeAnalyser) { sDate = df.getSimpleDateFormat().format(testDate); System.out.println("Test Date = " + testDate); System.out.println("Formatted = " + sDate); for (long i : new long[] { 333, 20000, 20 * 60 * 1000, 8 * 60 * 60 * 1000, 10 * 24 * 60 * 60 * 1000, 4 * 30 * 24 * 60 * 60 * 1000, 10 * 12 * 30 * 24 * 60 * 60 * 1000 }) { System.out.println("I = " + i); String startDate = df.getSimpleDateFormat().format(new Date(testDate.getTime() - i)); System.out.println("\tStart = " + startDate); String endDate = df.getSimpleDateFormat().format(new Date(testDate.getTime() + i)); System.out.println("\tEnd = " + endDate); boolean equalsStart = startDate.equals(sDate); boolean equalsEnd = endDate.equals(sDate); boolean equalsStartOrEnd = equalsStart || equalsEnd; results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":[" + startDate + " TO " + endDate + "]", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":[" + sDate + " TO " + endDate + "]", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":[" + startDate + " TO " + sDate + "]", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":{" + sDate + " TO " + endDate + "}", null); assertEquals(0, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":{" + startDate + " TO " + sDate + "}", null); assertEquals(0, results.length()); results.close(); } } } results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "boolean-ista")) + ":\"true\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "qname-ista")) + ":\"{wibble}wobble\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "category-ista")) + ":\"" + DefaultTypeConverter.INSTANCE.convert(String.class, new NodeRef(rootNodeRef.getStoreRef(), "CategoryId")) + "\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "noderef-ista")) + ":\"" + n1 + "\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "path-ista")) + ":\"" + nodeService.getPath(n3) + "\"", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "path-ista"))); results.close(); // d:any results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "any-many-ista")) + ":\"100\"", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "any-many-ista"))); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "any-many-ista")) + ":\"anyValueAsString\"", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "any-many-ista"))); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "any-many-ista")) + ":\"nintc\"", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "any-many-ista"))); results.close(); // proximity searches results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"Tutorial Alfresco\"~0", null); assertEquals(0, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"Tutorial Alfresco\"~1", null); assertEquals(0, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"Tutorial Alfresco\"~2", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"Tutorial Alfresco\"~3", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"Alfresco Tutorial\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"Tutorial Alfresco\"", null); assertEquals(0, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"Tutorial Alfresco\"~0", null); assertEquals(0, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"Tutorial Alfresco\"~1", null); assertEquals(0, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"Tutorial Alfresco\"~2", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"Tutorial Alfresco\"~3", null); assertEquals(1, results.length()); results.close(); // multi ml text QName multimlQName = QName.createQName(TEST_NAMESPACE, "mltext-many-ista"); SearchParameters sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":"); sp.addLocale(new Locale("ru")); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":lemur"); sp.addLocale(new Locale("en")); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":chou"); sp.addLocale(new Locale("fr")); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":cabbage"); sp.addLocale(new Locale("en")); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":cabba*"); sp.addLocale(new Locale("en")); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":ca*ge"); sp.addLocale(new Locale("en")); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":*bage"); sp.addLocale(new Locale("en")); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":cabage~"); sp.addLocale(new Locale("en")); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":*b?ag?"); sp.addLocale(new Locale("en")); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":cho*"); sp.setMlAnalaysisMode(MLAnalysisMode.LOCALE_AND_ALL_CONTAINED_LOCALES); sp.addLocale(new Locale("fr")); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); // multivalued content in type d:any // This should not be indexed as we can not know what to do with content here. sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery( QName.createQName(TEST_NAMESPACE, "content-many-ista").toString()) + ":multicontent"); results = searcher.query(sp); assertEquals(0, results.length()); results.close(); // locale results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "locale-ista")) + ":\"en_GB_\"", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "path-ista"))); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "locale-ista")) + ":en_GB_", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "path-ista"))); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "locale-ista")) + ":en_*", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "path-ista"))); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "locale-ista")) + ":*_GB_*", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "path-ista"))); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "locale-ista")) + ":*_gb_*", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "path-ista"))); results.close(); // Period results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "period-ista")) + ":\"period|12\"", null); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "path-ista"))); results.close(); // Type results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"" + testType.toString() + "\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"" + testType.toPrefixString(namespacePrefixResolver) + "\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "EXACTTYPE:\"" + testType.toString() + "\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "EXACTTYPE:\"" + testType.toPrefixString(namespacePrefixResolver) + "\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"" + testSuperType.toString() + "\"", null); assertEquals(13, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"" + testSuperType.toPrefixString(namespacePrefixResolver) + "\"", null); assertEquals(13, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"" + ContentModel.TYPE_CONTENT.toString() + "\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"cm:content\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"cm:CONTENT\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"CM:CONTENT\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"CONTENT\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"content\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"" + ContentModel.TYPE_THUMBNAIL.toString() + "\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"" + ContentModel.TYPE_THUMBNAIL.toString() + "\" TYPE:\"" + ContentModel.TYPE_CONTENT.toString() + "\"", null); assertEquals(2, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "EXACTTYPE:\"" + testSuperType.toString() + "\"", null); assertEquals(12, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "EXACTTYPE:\"" + testSuperType.toPrefixString(namespacePrefixResolver) + "\"", null); assertEquals(12, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "ASPECT:\"" + testAspect.toString() + "\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "ASPECT:\"" + testAspect.toPrefixString(namespacePrefixResolver) + "\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "EXACTASPECT:\"" + testAspect.toString() + "\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "EXACTASPECT:\"" + testAspect.toPrefixString(namespacePrefixResolver) + "\"", null); assertEquals(1, results.length()); results.close(); // Test for AR-384 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:fox AND TYPE:\"" + ContentModel.PROP_CONTENT.toString() + "\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:fox cm\\:name:fox", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:fo AND TYPE:\"" + ContentModel.PROP_CONTENT.toString() + "\"", null); assertEquals(0, results.length()); results.close(); // Test stop words are equivalent results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"the\"", null); assertEquals(0, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"and\"", null); assertEquals(0, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"over the lazy\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"over a lazy\"", null); assertEquals(1, results.length()); results.close(); // Test wildcards in text //ALF-2389 //results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic"))+":*en*", null); //assertEquals(0, results.length()); //results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":*a*", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":*A*", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":\"*a*\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":\"*A\"*", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":*s*", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":*S*", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":\"*s*\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":\"*S\"*", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:*A*", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"*a*\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"*A*\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:*a*", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:*Z*", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:*z*", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"*Z*\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"*z*\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:laz*", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:laz~", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:la?y", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:?a?y", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:*azy", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:*az*", null); assertEquals(1, results.length()); results.close(); // Accents results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"\u00E0\u00EA\u00EE\u00F0\u00F1\u00F6\u00FB\u00FF\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"aeidnouy\"", null); assertEquals(1, results.length()); results.close(); // FTS test results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"fox\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ":\"fox\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ".mimetype:\"text/plain\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ".locale:\"en_GB\"", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ".locale:en_*", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ".locale:e*_GB", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ".size:\"298\"", null); assertEquals(1, results.length()); results.close(); QName queryQName = QName.createQName("alf:test1", namespacePrefixResolver); results = searcher.query(rootNodeRef.getStoreRef(), queryQName, null); assertEquals(1, results.length()); results.close(); // Configuration of TEXT sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ":\"fox\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"fox\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"fox\""); sp.addTextAttribute("@" + ContentModel.PROP_NAME.toString()); results = searcher.query(sp); assertEquals(0, results.length()); results.close(); sp.addTextAttribute("@" + ContentModel.PROP_CONTENT.toString()); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"cabbage\""); sp.addTextAttribute("@" + orderText.toString()); results = searcher.query(sp); assertEquals(13, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"cab*\""); sp.addTextAttribute("@" + orderText.toString()); results = searcher.query(sp); assertEquals(13, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"*bage\""); sp.addTextAttribute("@" + orderText.toString()); results = searcher.query(sp); assertEquals(13, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"*ba*\""); sp.addTextAttribute("@" + orderText.toString()); results = searcher.query(sp); assertEquals(13, results.length()); results.close(); // term sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:cabbage"); sp.addTextAttribute("@" + orderText.toString()); results = searcher.query(sp); assertEquals(13, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:*cab*"); sp.addTextAttribute("@" + orderText.toString()); sp.addLocale(Locale.ENGLISH); results = searcher.query(sp); assertEquals(13, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:*bage"); sp.addTextAttribute("@" + orderText.toString()); results = searcher.query(sp); assertEquals(13, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:*ba*"); sp.addTextAttribute("@" + orderText.toString()); results = searcher.query(sp); assertEquals(13, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:dabbage~0.8"); sp.addTextAttribute("@" + orderText.toString()); results = searcher.query(sp); assertEquals(13, results.length()); results.close(); // Wild cards in TEXT phrase sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"alfresc?\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"alfres??\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"alfre???\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"alfr????\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"alf?????\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"al??????\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"a???????\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"a??re???\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"alfresco\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"?lfresco\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"??fresco\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"???resco\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"???res?o\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"????e?co\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"????e?c?\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"???????o\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"???re???\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"alfresc*\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"alfres*\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"alfre*\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"alfr*\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"alf*\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"al*\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"a*\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"a****\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"*lfresco\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"*fresco\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"*resco\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"*esco\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"*sco\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"*co\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"*o\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"****lf**sc***\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"*??*lf**sc***\""); results = searcher.query(sp); assertEquals(0, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"alfresc*tutorial\""); results = searcher.query(sp); assertEquals(0, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"alf* tut*\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("TEXT:\"*co *al\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); // Wild cards in ML phrases sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alfresc?\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alfres??\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alfre???\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alfr????\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alf?????\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"al??????\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"a???????\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"a??re???\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alfresco\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"?lfresco\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"??fresco\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"???resco\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"???res?o\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"????e?co\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"????e?c?\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"???????o\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"???re???\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alfresc*\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alfres*\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alfre*\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alfr*\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alf*\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"al*\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"a*\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"a****\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"*lfresco\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"*fresco\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"*resco\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"*esco\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"*sco\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"*co\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"*o\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"****lf**sc***\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"*??*lf**sc***\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"Alfresc*tutorial\""); results = searcher.query(sp); assertEquals(0, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"Alf* tut*\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"*co *al\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); // ALL and its configuration sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("ALL:\"fox\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("ALL:\"fox\""); sp.addAllAttribute("@" + ContentModel.PROP_NAME.toString()); results = searcher.query(sp); assertEquals(0, results.length()); results.close(); sp.addAllAttribute("@" + ContentModel.PROP_CONTENT.toString()); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("ALL:\"5.6\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); // Search by data type sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("d\\:double:\"5.6\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("d\\:content:\"fox\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); // locale serach in en_US for en_UK sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("d\\:content:\"fox\""); sp.addLocale(Locale.US); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); // Direct ML tests QName mlQName = QName.createQName(TEST_NAMESPACE, "ml"); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setMlAnalaysisMode(MLAnalysisMode.ALL_ONLY); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":and"); results = searcher.query(sp); assertEquals(0, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setMlAnalaysisMode(MLAnalysisMode.ALL_ONLY); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":\"and\""); results = searcher.query(sp); assertEquals(0, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setMlAnalaysisMode(MLAnalysisMode.ALL_ONLY); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banana"); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banana"); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banana"); sp.addLocale(Locale.UK); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banana"); sp.setMlAnalaysisMode(MLAnalysisMode.LOCALE_AND_ALL_CONTAINING_LOCALES); sp.addLocale(Locale.UK); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banana"); sp.addLocale(Locale.ENGLISH); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banane"); sp.addLocale(Locale.FRENCH); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":"); sp.addLocale(Locale.CHINESE); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banaan"); sp.addLocale(new Locale("nl")); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banane"); sp.addLocale(Locale.GERMAN); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":"); sp.addLocale(new Locale("el")); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banana"); sp.addLocale(Locale.ITALIAN); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":?"); sp.addLocale(new Locale("ja")); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":"); sp.addLocale(new Locale("ko")); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banana"); sp.addLocale(new Locale("pt")); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":"); sp.addLocale(new Locale("ru")); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":pltano"); sp.addLocale(new Locale("es")); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); // Test ISNULL/ISUNSET/ISNOTNULL sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("ISUNSET:\"" + QName.createQName(TEST_NAMESPACE, "null").toString() + "\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("ISNULL:\"" + QName.createQName(TEST_NAMESPACE, "null").toString() + "\""); results = searcher.query(sp); // assertEquals(62, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("ISUNSET:\"" + QName.createQName(TEST_NAMESPACE, "path-ista").toString() + "\""); results = searcher.query(sp); assertEquals(0, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("ISNULL:\"" + QName.createQName(TEST_NAMESPACE, "path-ista").toString() + "\""); results = searcher.query(sp); // assertEquals(61, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("ISNOTNULL:\"" + QName.createQName(TEST_NAMESPACE, "null").toString() + "\""); results = searcher.query(sp); assertEquals(0, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("ISNOTNULL:\"" + QName.createQName(TEST_NAMESPACE, "path-ista").toString() + "\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("ISUNSET:\"" + QName.createQName(TEST_NAMESPACE, "aspectProperty").toString() + "\""); results = searcher.query(sp); assertEquals(1, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("ISNULL:\"" + QName.createQName(TEST_NAMESPACE, "aspectProperty").toString() + "\""); results = searcher.query(sp); // assertEquals(62, results.length()); results.close(); sp = new SearchParameters(); sp.addStore(rootNodeRef.getStoreRef()); sp.setLanguage("lucene"); sp.setQuery("ISNOTNULL:\"" + QName.createQName(TEST_NAMESPACE, "aspectProperty").toString() + "\""); results = searcher.query(sp); assertEquals(0, results.length()); results.close(); // Test non field queries results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:fox", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:fo*", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:f*x", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:*ox", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ":fox", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ":fo*", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ":f*x", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ":*ox", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion .escapeLuceneQuery(ContentModel.PROP_CONTENT.toPrefixString(namespacePrefixResolver)) + ":fox", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion .escapeLuceneQuery(ContentModel.PROP_CONTENT.toPrefixString(namespacePrefixResolver)) + ":fo*", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion .escapeLuceneQuery(ContentModel.PROP_CONTENT.toPrefixString(namespacePrefixResolver)) + ":f*x", null); assertEquals(1, results.length()); results.close(); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion .escapeLuceneQuery(ContentModel.PROP_CONTENT.toPrefixString(namespacePrefixResolver)) + ":*ox", null); assertEquals(1, results.length()); results.close(); // Parameters queryQName = QName.createQName("alf:test2", namespacePrefixResolver); results = searcher.query(rootNodeRef.getStoreRef(), queryQName, null); assertEquals(1, results.length()); results.close(); queryQName = QName.createQName("alf:test2", namespacePrefixResolver); QueryParameter qp = new QueryParameter(QName.createQName("alf:banana", namespacePrefixResolver), "woof"); results = searcher.query(rootNodeRef.getStoreRef(), queryQName, new QueryParameter[] { qp }); assertEquals(0, results.length()); results.close(); queryQName = QName.createQName("alf:test3", namespacePrefixResolver); qp = new QueryParameter(QName.createQName("alf:banana", namespacePrefixResolver), "/one/five//*"); results = searcher.query(rootNodeRef.getStoreRef(), queryQName, new QueryParameter[] { qp }); assertEquals(7, results.length()); results.close(); // TODO: should not have a null property type definition QueryParameterDefImpl paramDef = new QueryParameterDefImpl( QName.createQName("alf:lemur", namespacePrefixResolver), (DataTypeDefinition) null, true, "fox"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"${alf:lemur}\"", new QueryParameterDefinition[] { paramDef }); assertEquals(1, results.length()); results.close(); paramDef = new QueryParameterDefImpl(QName.createQName("alf:intvalue", namespacePrefixResolver), (DataTypeDefinition) null, true, "1"); qname = QName.createQName(TEST_NAMESPACE, "int-ista"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"${alf:intvalue}\"", new QueryParameterDefinition[] { paramDef }); assertEquals(1, results.length()); assertNotNull(results.getRow(0).getValue(qname)); results.close(); // Open ended ranges qname = QName.createQName("{namespace}property-1"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[v TO w]", null); assertEquals(2, results.length()); results.close(); qname = QName.createQName("{namespace}property-1"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[v TO \uFFFF]", null); assertEquals(2, results.length()); results.close(); qname = QName.createQName("{namespace}property-1"); results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[\u0000 TO w]", null); assertEquals(2, results.length()); results.close(); }