Custom Date Format Java | ग्रुपडॉक्स के साथ डेट रेंज सर्च
डेट के आधार पर दस्तावेज़ों की खोज एक सामान्य आवश्यकता है—चाहे आप एक अभिलेखीय प्रणाली, एक वित्तीय रिपोर्टिंग टूल, या एक कंटेंट‑मैनेजमेंट पोर्टल बना रहे हों। इस ट्यूटोरियल में आप GroupDocs.Search का उपयोग करके custom date format java तकनीकों को सीखेंगे, जिसमें डेट रेंज क्वेरीज़, कस्टम पैटर्न परिभाषाएँ, और optimize search performance को अनुकूलित करने के टिप्स शामिल हैं। अंत तक, आप उपयोगकर्ताओं को किसी भी डेट अंतराल में पड़ने वाले रिकॉर्ड्स को पुनः प्राप्त करने में सक्षम होंगे, चाहे वे कोई भी फ़ॉर्मेट उपयोग करें।
त्वरित उत्तर
- इंडेक्सिंग के लिए मुख्य क्लास कौन सी है?
Indexfrom thecom.groupdocs.searchpackage. - कस्टम डेट पैटर्न कैसे परिभाषित करें? Use
DateFormatwithDateFormatElementobjects and a separator. - क्या मैं टेक्स्ट क्वेरी के साथ खोज सकता हूँ? Yes, the
daterange(start ~~ end)syntax works directly in the query string. - कौन से Maven कोऑर्डिनेट्स आवश्यक हैं?
com.groupdocs:groupdocs-search:25.4(or newer). - क्या विकास के लिए लाइसेंस चाहिए? A free trial or temporary license is sufficient for testing; a commercial license is required for production.
क्या है custom date format java?
एक custom date format java GroupDocs.Search को बताता है कि वह उन डेट स्ट्रिंग्स को कैसे समझे जो डिफ़ॉल्ट ISO पैटर्न (YYYY‑MM‑DD) का पालन नहीं करतीं। अपना खुद का पैटर्न परिभाषित करके—जैसे MM/dd/yyyy या dd‑MM‑yyyy—आप इंजन को उन दस्तावेज़ों में एम्बेडेड डेट्स को पहचानने में सक्षम बनाते हैं जो क्षेत्रीय या लेगेसी फ़ॉर्मेट का उपयोग करते हैं।
डेट रेंज क्वेरीज़ के लिए GroupDocs.Search क्यों उपयोग करें?
- स्पीड: Built‑in indexing makes look‑ups O(log n).
- लचीलापन: Supports both text‑based and object‑based query creation.
- मल्टी‑फ़ॉर्मेट सपोर्ट: Handles PDFs, Word, Excel, plain text, and more without extra code.
GroupDocs.Search के साथ search documents by date कैसे करें
नीचे आपको एक चरण‑दर‑चरण गाइड मिलेगा जो लाइब्रेरी सेटअप, फ़ाइलों को इंडेक्स करने, और साधारण तथा उन्नत डेट रेंज सर्च को निष्पादित करने की प्रक्रिया दिखाता है।
पूर्वापेक्षाएँ
- Java 8 या उससे नया स्थापित हो।
- निर्भरता प्रबंधन के लिए Maven।
- GroupDocs.Search लाइसेंस तक पहुँच (ट्रायल या टेम्पररी विकास के लिए काम करता है)।
Java के लिए GroupDocs.Search सेटअप करना
Maven का उपयोग करके इंस्टॉलेशन
Add the repository and dependency to your pom.xml:
<repositories>
<repository>
<id>repository.groupdocs.com</id>
<name>GroupDocs Repository</name>
<url>https://releases.groupdocs.com/search/java/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-search</artifactId>
<version>25.4</version>
</dependency>
</dependencies>
डायरेक्ट डाउनलोड
वैकल्पिक रूप से, आप नवीनतम संस्करण सीधे GroupDocs.Search for Java releases से डाउनलोड कर सकते हैं।
बेसिक इनिशियलाइज़ेशन और सेटअप
Create an Index instance and add your documents:
import com.groupdocs.search.*;
String indexFolder = "YOUR_INDEX_DIRECTORY";
String documentsFolder = "YOUR_DOCUMENTS_DIRECTORY";
// Creating an index in the specified folder
Index index = new Index(indexFolder);
// Indexing documents from the specified folder
index.add(documentsFolder);
फीचर 1: डेट रेंज सर्च क्वेरीज़ बनाना
टेक्स्ट फ़ॉर्म क्वेरी का उपयोग
The simplest way is to embed the date range directly in the query string:
import com.groupdocs.search.*;
import com.groupdocs.search.results.*;
// Define directories (as previously shown)
Index index = new Index(indexFolder);
index.add(documentsFolder);
// Create a text-based query for the specified date range
String query1 = "daterange(2017-01-01 ~~ 2019-12-31)";
SearchResult result1 = index.search(query1);
व्याख्या: The daterange syntax expects dates in YYYY‑MM‑DD. It returns all documents whose indexed dates fall within the interval.
क्वेरी ऑब्जेक्ट का उपयोग
For programmatic control and custom parsing, build a SearchQuery object:
import com.groupdocs.search.*;
import com.groupdocs.search.options.*;
import com.groupdocs.search.results.*;
// Define directories (as previously shown)
Index index = new Index(indexFolder);
index.add(documentsFolder);
// Create a date range query using the Query API
SearchQuery query2 = SearchQuery.createDateRangeQuery(Utils.createDate(2017, 1, 1), Utils.createDate(2019, 12, 31));
SearchResult result2 = index.search(query2);
व्याख्या: createDateRangeQuery lets you supply java.util.Date objects, giving you full flexibility over time zones and locale‑specific handling.
फीचर 2: custom date format java पैटर्न निर्दिष्ट करना
कस्टम डेट फ़ॉर्मेट सेट करना
Define a DateFormat that matches your document’s date representation:
import com.groupdocs.search.*;
import com.groupdocs.search.options.*;
import com.groupdocs.search.results.*;
// Define directories (as previously shown)
Index index = new Index(indexFolder);
index.add(documentsFolder);
// Configure search options with custom date formats
SearchOptions options = new SearchOptions();
options.getDateFormats().clear(); // Remove default formats
DateFormatElement[] elements = new DateFormatElement[]{
DateFormatElement.getMonthTwoDigits(),
DateFormatElement.getDateSeparator(),
DateFormatElement.getDayOfMonthTwoDigits(),
DateFormatElement.getDateSeparator(),
DateFormatElement.getYearFourDigits()
};
// Create a custom date format pattern 'MM/dd/yyyy'
DateFormat dateFormat = new DateFormat(elements, "/");
options.getDateFormats().addItem(dateFormat);
String query = "daterange(01/01/2017 ~~ 12/31/2019)";
SearchResult result = index.search(query, options);
व्याख्या: By clearing the default formats and adding a DateFormat that uses / as the separator, the engine now understands dates written as MM/dd/yyyy. This is essential for search documents by date in regions that prefer month‑first notation.
optimize search performance के लिए टिप्स
- इंडेक्स इंक्रीमेंटली: Add new files to the existing index instead of rebuilding from scratch.
- पुराने डेटा को प्रून करें: Periodically remove documents that are no longer needed.
- मेमोरी सेटिंग्स समायोजित करें: Increase the JVM heap (
-Xmx) when working with large indexes.
सामान्य समस्याएँ और समाधान
- डेट पार्सिंग एरर: Verify that the document’s date strings exactly match the custom pattern you defined.
- मिसिंग रिज़ल्ट्स: Ensure the indexed fields contain date metadata; otherwise, the engine cannot match date queries.
- इंडेक्स एक्सेस एक्सेप्शन: Confirm that the
indexFolderpath is writable and not locked by another process.
व्यावहारिक अनुप्रयोग
- Archival Systems – Retrieve records from a specific historical period.
- Content Management – Support regional date formats like
dd/MM/yyyyfor European audiences. - Financial Software – Filter transactions by fiscal quarter or year quickly.
निष्कर्ष
अब आपके पास custom date format java टूलबॉक्स है जो GroupDocs.Search के साथ शक्तिशाली डेट‑रेंज सर्च बनाने में मदद करता है। इन पैटर्न को लागू करें, प्रदर्शन को फाइन‑ट्यून करें, और आपका एप्लिकेशन किसी भी समय-संबंधी क्वेरी के लिए तेज़, सटीक परिणाम देगा।
अक्सर पूछे जाने वाले प्रश्न
Q: टेक्स्ट फ़ॉर्म और ऑब्जेक्ट‑बेस्ड डेट क्वेरीज़ में क्या अंतर है?
A: Text form is quick and easy but limited to the default ISO format; object‑based queries let you supply Date objects and custom formats for greater flexibility.
Q: क्या मैं एक ही क्वेरी में कई डेट रेंज खोज सकता हूँ?
A: Yes, combine daterange clauses with logical operators like AND or OR to build complex queries.
Q: क्या कस्टम डेट फ़ॉर्मेट सर्च को धीमा कर देंगे?
A: There is a minor overhead for additional parsing, but the impact is negligible for typical workloads and is outweighed by the accuracy gains.
Q: क्या GroupDocs.Search बड़े‑पैमाने पर डिप्लॉयमेंट के लिए उपयुक्त है?
A: Absolutely. With proper indexing strategies and JVM tuning, it scales to millions of documents.
Q: मैं और अधिक जावा उदाहरण कहाँ पा सकता हूँ?
A: Explore the GroupDocs GitHub repository for additional samples and use‑case implementations.
संसाधन
- Documentation: GroupDocs Search Documentation
- API Reference: GroupDocs API Reference
- Download: Get the latest version here
- GitHub Repository: View on GitHub
- Free Support Forum: Join the discussion
- Temporary License: Acquire a temporary license here
Last Updated: 2025-12-18
Tested With: GroupDocs.Search Java 25.4
Author: GroupDocs