com.groupdocs.search.events

Class EventHub



  • public abstract class EventHub
    extends Object

    Provides index events for subscribing.

    The example demonstrates a typical usage of the class.

     String indexFolder = "c:\\MyIndex\\";
     String documentsFolder = "c:\\MyDocuments\\";
     String query = "Einstein";
     // Creating an index
     Index index = new Index(indexFolder);
     // Subscribing to the event
     index.getEvents().ErrorOccurred.add(new EventHandler<IndexErrorEventArgs>() {
         public void invoke(Object sender, IndexErrorEventArgs args) {
             System.out.println(args.getMessage());
         }
     });
     // Indexing documents from the specified folder
     index.add(documentsFolder);
     // Searching in the index
     SearchResult result = index.search(query);
     
    • Field Detail

      • OperationFinished

        public final Event<EventHandler<OperationFinishedEventArgs>> OperationFinished

        Occurs when an index operation is finished.

        The example demonstrates how to use the event.

         String indexFolder = "c:\\MyIndex\\";
         String documentsFolder = "c:\\MyDocuments\\";
         // Creating an index
         Index index = new Index(indexFolder);
         // Subscribing to the event
         index.getEvents().OperationFinished.add(new EventHandler<OperationFinishedEventArgs>() {
             public void invoke(Object sender, OperationFinishedEventArgs args) {
                 System.out.println("Operation finished: " + args.getOperationType());
                 System.out.println("Message: " + args.getMessage());
                 System.out.println("Index folder: " + args.getIndexFolder());
                 DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
                 System.out.println("Time: " + df.format(args.getTime()));
             }
         });
         // Indexing documents from the specified folder
         index.add(documentsFolder);
         
      • ErrorOccurred

        public final Event<EventHandler<IndexErrorEventArgs>> ErrorOccurred

        Occurs when an error happens during an index operation.

        The example demonstrates how to use the event.

         String indexFolder = "c:\\MyIndex\\";
         String documentsFolder = "c:\\MyDocuments\\";
         String query = "Einstein";
         // Creating an index
         Index index = new Index(indexFolder);
         // Subscribing to the event
         index.getEvents().ErrorOccurred.add(new EventHandler<IndexErrorEventArgs>() {
             public void invoke(Object sender, IndexErrorEventArgs args) {
                 System.out.println(args.getMessage());
             }
         });
         // Indexing documents from the specified folder
         index.add(documentsFolder);
         // Searching in the index
         SearchResult result = index.search(query);
         
      • OperationProgressChanged

        public final Event<EventHandler<OperationProgressEventArgs>> OperationProgressChanged

        Occurs when the progress of indexing or update operation is changed.

        The example demonstrates how to use the event.

         String indexFolder = "c:\\MyIndex\\";
         String documentsFolder = "c:\\MyDocuments\\";
         // Creating an index
         Index index = new Index(indexFolder);
         // Subscribing to the event
         index.getEvents().OperationProgressChanged.add(new EventHandler<OperationProgressEventArgs>() {
             public void invoke(Object sender, OperationProgressEventArgs args) {
                 System.out.println("Last processed: " + args.getLastDocumentPath());
                 System.out.println("Result: " + args.getLastDocumentStatus());
                 System.out.println("Processed documents: " + args.getTotalDocuments());
                 System.out.println("Progress percentage: " + args.getProgressPercentage());
             }
         });
         // Indexing documents from the specified folder
         index.add(documentsFolder);
         
      • PasswordRequired

        public final Event<EventHandler<PasswordRequiredEventArgs>> PasswordRequired

        Occurs when a document requires password for opening.

        The example demonstrates how to use the event.

         String indexFolder = "c:\\MyIndex\\";
         String documentsFolder = "c:\\MyDocuments\\";
         // Creating an index
         Index index = new Index(indexFolder);
         // Subscribing to the event
         index.getEvents().PasswordRequired.add(new EventHandler<PasswordRequiredEventArgs>() {
             public void invoke(Object sender, PasswordRequiredEventArgs args)
         {
             if (args.getDocumentFullPath().endsWith("ProtectedDocument.pdf"))
             {
                 args.setPassword("123456");
             }
         }
         });
         // Indexing documents from the specified folder
         index.add(documentsFolder);
         
      • FileIndexing

        public final Event<EventHandler<FileIndexingEventArgs>> FileIndexing

        Occurs when a document is going to be indexed.

        The example demonstrates how to use the event.

         String indexFolder = "c:\\MyIndex\\";
         String documentsFolder = "c:\\MyDocuments\\";
         // Creating an index
         Index index = new Index(indexFolder);
         // Subscribing to the event
         index.getEvents().FileIndexing.add(new EventHandler<FileIndexingEventArgs>() {
             public void invoke(Object sender, FileIndexingEventArgs args) {
             if (args.getDocumentFullPath().endsWith("Protected.pdf")) {
                 args.setAdditionalFields(new DocumentField[] {
                     new DocumentField("Tags", "Protected")
                 });
             }
             if (!args.getDocumentFullPath().toLowerCase().contains("important")) {
                 args.setSkipIndexing(true);
             }
         }
         });
         // Indexing documents from the specified folder
         index.add(documentsFolder);
         
      • StatusChanged

        public final Event<EventHandler<BaseIndexEventArgs>> StatusChanged

        Occurs when the index status changes.

        The example demonstrates how to use the event.

         String indexFolder = "c:\\MyIndex\\";
         String documentsFolder = "c:\\MyDocuments\\";
         // Creating an index
         Index index = new Index(indexFolder);
         // Subscribing to the event
         index.getEvents().StatusChanged.add(new EventHandler<BaseIndexEventArgs>() {
             public void invoke(Object sender, BaseIndexEventArgs args)
         {
             if (args.getStatus() != IndexStatus.InProgress)
             {
                 // A notification of the operation completion should be here
             }
         }
         });
         // Setting the flag for asynchronous indexing
         IndexingOptions options = new IndexingOptions();
         options.setAsync(true);
         // Asynchronous indexing documents from the specified folder
         // The method terminates before the operation completes
         index.add(documentsFolder, options);
         
      • SearchPhaseCompleted

        public final Event<EventHandler<SearchPhaseEventArgs>> SearchPhaseCompleted

        Occurs when the search phase is completed.

        The example demonstrates how to use the event.

         String indexFolder = "c:\\MyIndex\\";
         String documentsFolder = "c:\\MyDocuments\\";
         // Creating an index
         Index index = new Index(indexFolder);
         // Indexing documents from the specified folder
         index.add(documentsFolder);
         // Subscribing to the event
         index.getEvents().SearchPhaseCompleted.add(new EventHandler<SearchPhaseEventArgs>() {
             public void invoke(Object sender, SearchPhaseEventArgs args) {
                 System.out.println("Search phase: " + args.getSearchPhase());
                 System.out.println("Words: " + args.getWords().length);
             }
         });
         SearchOptions options = new SearchOptions();
         options.setUseSynonymSearch(true);
         options.setUseWordFormsSearch(true);
         options.getFuzzySearch().setEnabled(true);
         options.setUseHomophoneSearch(true);
         SearchResult result = index.search("Einstein", options);
         
    • Constructor Detail

      • EventHub

        public EventHub()