Как добавить папку в индекс с помощью GroupDocs.Search в Java

Если вам нужен java full text search, который может масштабироваться до миллионов документов, вы попали в нужное место. В этом руководстве вы узнаете, как add folder to index с помощью GroupDocs.Search, настроить хранилище с высокой компрессией и выполнять молниеносные запросы. К концу у вас будет готовое к производству решение, которое можно внедрить в любой проект Java.

Быстрые ответы

  • Какова основная библиотека? GroupDocs.Search for Java
  • Как добавить папку в индекс? Use index.add(folderPath)
  • Можно ли настроить компрессию текста? Yes, via TextStorageSettings(Compression.High)
  • Какая версия Java требуется? JDK 8 or higher
  • Где получить пробную лицензию? From the GroupDocs website or the repository page

Что такое java full text search и почему это важно?

Java full text search преобразует необработанные документы в обратный индекс, позволяя за доли секунды находить любой термин среди тысяч файлов. Эта возможность критична для юридических репозиториев, исследовательских библиотек и корпоративных баз знаний, где пользователи ожидают мгновенных результатов. Она также повышает продуктивность современных приложений.

GroupDocs.Search обеспечивает высокопроизводительное индексирование и выполнение запросов, предлагая встроенную высокую компрессию. Он поддерживает 50+ input and output formats — включая PDF, DOCX, EML и HTML — и может обрабатывать документы в сотни страниц без загрузки полного файла в память, удерживая объём памяти ниже 200 MB для типовых нагрузок.

Предварительные требования

  • GroupDocs.Search for Java (version 25.4 or later) – основная библиотека, обеспечивающая индексацию и поиск.
  • JDK 8+ установлен и настроен – минимальная среда выполнения для SDK.
  • Maven для управления зависимостями – упрощает добавление библиотеки в ваш проект.
  • IDE, например IntelliJ IDEA или Eclipse – для написания и отладки кода Java.

Настройка GroupDocs.Search для java

Настройка Maven

Add the repository and dependency to your pom.xml file:

<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>

Прямое скачивание

Alternatively, download the latest version from выпуски GroupDocs.Search для Java.

Приобретение лицензии

  • Free trial – исследуйте все функции без обязательств.
  • Temporary license – расширенный период тестирования.
  • Purchase – разблокировать полные производственные возможности.

Базовая инициализация и настройка

Index — основной класс, используемый для создания, открытия и управления поисковым индексом.

import com.groupdocs.search.Index;

public class InitializeSearch {
    public static void main(String[] args) {
        // Path to store index data
        String indexPath = "path/to/index";
        
        // Creating an index at specified location
        Index index = new Index(indexPath);
        
        System.out.println("GroupDocs.Search initialized successfully!");
    }
}

Индексировать текст с пользовательской компрессией

Шаг 1: определить папку индекса

Choose a directory where the index files will reside:

String indexFolder = "YOUR_DOCUMENT_DIRECTORY\\output\\AdvancedUsage\\Indexing\\StoringTextOfIndexedDocuments";

Шаг 2: настроить параметры индекса

TextStorageSettings configures how text is stored in the index, including compression level. Compression is an enum that specifies the desired compression algorithm.

import com.groupdocs.search.Index;
import com.groupdocs.search.IndexSettings;
import com.groupdocs.search.options.TextStorageSettings;
import com.groupdocs.search.compression.Compression;

IndexSettings settings = new IndexSettings();
settings.setTextStorageSettings(new TextStorageSettings(Compression.High));

Шаг 3: создать индекс с пользовательскими настройками

Instantiate the index using the configuration defined above:

Index index = new Index(indexFolder, settings);
System.out.println("Index created with high compression.");

Как добавить папку в индекс

Index is the main class representing the searchable index.

Load the existing index (or create a new one) and then call the add method on the Index object. The add operation scans the supplied directory, extracts text from each supported file, and stores it in the compressed index, ready for instant search.

String documentsFolder = "YOUR_DOCUMENT_DIRECTORY"; // Replace with actual document path.
Index index = new Index(indexFolder);

Как искать проиндексированные документы

SearchResult represents a single match with document path and relevance.

Define a search query string that represents the term or phrase you want to locate, then invoke the search method on the Index instance. The method returns a collection of SearchResult objects, each containing the document path, relevance score, and snippet highlighting the match.

index.add(documentsFolder);
System.out.println("Documents added successfully.");

Практические применения

Real‑world scenarios where java full text search shines:

  1. Legal document management – мгновенный поиск судебных дел.
  2. Academic research libraries – быстрый поиск статей и диссертаций.
  3. Enterprise knowledge bases – быстрый доступ к руководствам и FAQ.
  4. Content management systems – эффективное обнаружение контента для крупных сайтов.
  5. Customer service archives – быстрый поиск прошлых тикетов и чатов.

Соображения по производительности

  • Compression vs. speed: High compression saves up to 70 % disk space but adds a modest indexing overhead; run benchmark tests for your data volume.
  • Memory management: Allocate at least 2 GB of heap for indexes larger than 10 GB to avoid OutOfMemoryError.
  • Index updates: Incrementally add new documents with index.add() and periodically call index.optimize() to keep the index compact.
  • Query optimization: Use the advanced query syntax (wildcards, proximity, fuzzy search) to narrow results and reduce response time.

Распространённые подводные камни и профессиональные советы

  • Pitfall: Forgetting to call index.optimize() after bulk additions.
    Pro tip: Run index.optimize() nightly to keep the index compact.

  • Pitfall: Using the default (low) compression on massive datasets.
    Pro tip: Switch to Compression.High for production environments to cut storage costs.

  • Pitfall: Not handling IOException when adding files from a network share.
    Pro tip: Wrap index.add() in a try‑catch block and log any failures for later review.

Часто задаваемые вопросы

Q: What is GroupDocs.Search?
A: It is a robust Java library that provides advanced full‑text search capabilities, including indexing, compression, and complex query support.

Q: How do I handle large datasets with GroupDocs.Search?
A: Enable high compression (Compression.High) and periodically commit changes to keep the index lean. Also, allocate sufficient heap memory (e.g., 4 GB for indexes over 20 GB).

Q: Can I integrate GroupDocs.Search with existing enterprise systems?
A: Yes, the library can be embedded in any Java‑based backend, REST services, or micro‑services architecture.

Q: What if my index becomes outdated?
A: Use the index.add() method to append new files and index.delete() to remove obsolete ones, then re‑run index.optimize() if needed.

Q: Where can I get help or support?
A: Visit the community forum at GroupDocs forums for troubleshooting and best‑practice tips.

Дополнительные ресурсы


Последнее обновление: 2026-11-02
Тестировано с: GroupDocs.Search 25.4
Автор: GroupDocs


String query = "sample";  
import com.groupdocs.search.results.SearchResult;

SearchResult result = index.search(query);
System.out.println("Search completed. Results found: " + result.getDocumentCount());

Связанные руководства