public
Description: semantic repository service is intended for indexing content from different sources and maintain multi indexes for different types of content and perform different types of search. yet another solr type indexing service on top of lucene but it will gradually support content versioning and more semantic search result.
Homepage: http://hasan.we4tech.com
Clone URL: git://github.com/we4tech/semantic-repository.git
Search Repo:
semantic-repository / development / idea-repository-core / src / main / java / com / ideabase / repository / core / index / impl / RepositoryItemIndexImpl.java
100644 112 lines (101 sloc) 3.527 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* $Id:RepositoryItemIndexImpl.java 249 2007-12-02 08:32:47Z hasan $
******************************************************************************
* Copyright (C) 2007 somewhere in .Net ltd.
* All Rights Reserved. No use, copying or distribution of this
* work may be made except in accordance with a valid license
* agreement from somewhere in .Net LTD. This notice must be included on
* all copies, modifications and derivatives of this work.
******************************************************************************
* $LastChangedBy:hasan $
* $LastChangedDate:2007-12-02 14:32:47 +0600 (Sun, 02 Dec 2007) $
* $LastChangedRevision:249 $
******************************************************************************
*/
package com.ideabase.repository.core.index.impl;
 
import java.io.IOException;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.Collection;
 
import org.springmodules.lucene.index.support.LuceneIndexSupport;
import org.springmodules.lucene.index.factory.LuceneIndexReader;
import org.apache.log4j.Logger;
import org.apache.log4j.LogManager;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermDocs;
import org.apache.lucene.index.TermEnum;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.store.Directory;
import com.ideabase.repository.core.index.RepositoryItemIndex;
 
/**
* Implementation of {@code RepositoryItemIndex}.
* @author <a href="mailto:hasan@somewherein.net">nhm tanveer hossain khan (hasan)</a>
*/
public class RepositoryItemIndexImpl extends LuceneIndexSupport
    implements RepositoryItemIndex {
 
  private final Logger LOG =
      LogManager.getLogger(RepositoryItemIndexImpl.class);
 
  /**
* Executor service is used to process all same index related work in a
* queued manner. so the caller won't wait for the processing instead it
* will do it afterwords.
*/
  private final Executor mIndexTaskExecutor =
      Executors.newSingleThreadExecutor();
 
  /**
* {@inheritDoc}
* @param pDocument {@inheritDoc}
*/
  public void addDocument(final Document pDocument) {
    mIndexTaskExecutor.execute(
        new Runnable() {
          public void run() {
            getLuceneIndexTemplate().addDocument(pDocument);
          }
        }
    );
  }
 
  /**
* {@inheritDoc}
*/
  public void updateDocument(final Term pTerm,
                             final Document pDocument) {
    mIndexTaskExecutor.execute(
        new Runnable() {
          public void run() {
            getLuceneIndexTemplate().deleteDocuments(pTerm);
            getLuceneIndexTemplate().addDocument(pDocument);
          }
        }
    );
  }
 
  /**
* {@inheritDoc}
*/
  public void deleteDocument(final Term pIdTerm) {
    mIndexTaskExecutor.execute(
        new Runnable() {
          public void run() {
            getLuceneIndexTemplate().deleteDocuments(pIdTerm);
          }
        }
    );
  }
 
  /**
* {@inheritDoc}
*/
  public void optimize() {
    mIndexTaskExecutor.execute(
        new Runnable() {
          public void run() {
            getLuceneIndexTemplate().optimize();
          }
        }
    );
  }
 
  public void deleteIndexFiles(final boolean pConfirmation) throws IOException {
    throw new UnsupportedOperationException(
              "This method is not yet implemented.");
  }
}