mirror of
https://github.com/sismics/docs.git
synced 2024-11-21 21:47:57 +01:00
Null check on Lucene documents, fix documents search query
This commit is contained in:
parent
7ed976b27a
commit
8378b346e9
@ -145,10 +145,9 @@ public class DocumentDao {
|
|||||||
Map<String, Object> parameterMap = new HashMap<String, Object>();
|
Map<String, Object> parameterMap = new HashMap<String, Object>();
|
||||||
List<String> criteriaList = new ArrayList<String>();
|
List<String> criteriaList = new ArrayList<String>();
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder("select d.DOC_ID_C c0, d.DOC_TITLE_C c1, d.DOC_DESCRIPTION_C c2, d.DOC_CREATEDATE_D c3, d.DOC_LANGUAGE_C c4, s.SHA_ID_C is not null c5 ");
|
StringBuilder sb = new StringBuilder("select distinct d.DOC_ID_C c0, d.DOC_TITLE_C c1, d.DOC_DESCRIPTION_C c2, d.DOC_CREATEDATE_D c3, d.DOC_LANGUAGE_C c4, s.SHA_ID_C is not null c5 ");
|
||||||
sb.append(" from T_DOCUMENT d ");
|
sb.append(" from T_DOCUMENT d ");
|
||||||
sb.append(" left join T_SHARE s on s.SHA_IDDOCUMENT_C = d.DOC_ID_C and s.SHA_DELETEDATE_D is null ");
|
sb.append(" left join T_SHARE s on s.SHA_IDDOCUMENT_C = d.DOC_ID_C and s.SHA_DELETEDATE_D is null ");
|
||||||
sb.append(" left join T_FILE f on f.FIL_IDDOC_C = d.DOC_ID_C and f.FIL_DELETEDATE_D is null ");
|
|
||||||
|
|
||||||
// Adds search criteria
|
// Adds search criteria
|
||||||
if (criteria.getUserId() != null) {
|
if (criteria.getUserId() != null) {
|
||||||
|
@ -23,6 +23,8 @@ import org.apache.lucene.search.IndexSearcher;
|
|||||||
import org.apache.lucene.search.ScoreDoc;
|
import org.apache.lucene.search.ScoreDoc;
|
||||||
import org.apache.lucene.search.TopDocs;
|
import org.apache.lucene.search.TopDocs;
|
||||||
import org.apache.lucene.util.Version;
|
import org.apache.lucene.util.Version;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.sismics.docs.core.model.context.AppContext;
|
import com.sismics.docs.core.model.context.AppContext;
|
||||||
import com.sismics.docs.core.model.jpa.Document;
|
import com.sismics.docs.core.model.jpa.Document;
|
||||||
@ -36,6 +38,10 @@ import com.sismics.docs.core.util.LuceneUtil.LuceneRunnable;
|
|||||||
* @author bgamard
|
* @author bgamard
|
||||||
*/
|
*/
|
||||||
public class LuceneDao {
|
public class LuceneDao {
|
||||||
|
/**
|
||||||
|
* Logger.
|
||||||
|
*/
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(LuceneDao.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy and rebuild index.
|
* Destroy and rebuild index.
|
||||||
@ -172,13 +178,17 @@ public class LuceneDao {
|
|||||||
TermsFilter userFilter = new TermsFilter(terms);
|
TermsFilter userFilter = new TermsFilter(terms);
|
||||||
|
|
||||||
// Search
|
// Search
|
||||||
|
Set<String> documentIdList = new HashSet<String>();
|
||||||
|
if (!DirectoryReader.indexExists(AppContext.getInstance().getLuceneDirectory())) {
|
||||||
|
log.warn("Lucene directory not yet initialized");
|
||||||
|
return documentIdList;
|
||||||
|
}
|
||||||
IndexReader reader = DirectoryReader.open(AppContext.getInstance().getLuceneDirectory());
|
IndexReader reader = DirectoryReader.open(AppContext.getInstance().getLuceneDirectory());
|
||||||
IndexSearcher searcher = new IndexSearcher(reader);
|
IndexSearcher searcher = new IndexSearcher(reader);
|
||||||
TopDocs topDocs = searcher.search(query, userFilter, Integer.MAX_VALUE);
|
TopDocs topDocs = searcher.search(query, userFilter, Integer.MAX_VALUE);
|
||||||
ScoreDoc[] docs = topDocs.scoreDocs;
|
ScoreDoc[] docs = topDocs.scoreDocs;
|
||||||
|
|
||||||
// Extract document IDs
|
// Extract document IDs
|
||||||
Set<String> documentIdList = new HashSet<String>();
|
|
||||||
for (int i = 0; i < docs.length; i++) {
|
for (int i = 0; i < docs.length; i++) {
|
||||||
org.apache.lucene.document.Document document = searcher.doc(docs[i].doc);
|
org.apache.lucene.document.Document document = searcher.doc(docs[i].doc);
|
||||||
String type = document.get("type");
|
String type = document.get("type");
|
||||||
@ -205,8 +215,12 @@ public class LuceneDao {
|
|||||||
luceneDocument.add(new StringField("id", document.getId(), Field.Store.YES));
|
luceneDocument.add(new StringField("id", document.getId(), Field.Store.YES));
|
||||||
luceneDocument.add(new StringField("user_id", document.getUserId(), Field.Store.YES));
|
luceneDocument.add(new StringField("user_id", document.getUserId(), Field.Store.YES));
|
||||||
luceneDocument.add(new StringField("type", "document", Field.Store.YES));
|
luceneDocument.add(new StringField("type", "document", Field.Store.YES));
|
||||||
luceneDocument.add(new TextField("title", document.getTitle(), Field.Store.NO));
|
if (document.getTitle() != null) {
|
||||||
luceneDocument.add(new TextField("description", document.getDescription(), Field.Store.NO));
|
luceneDocument.add(new TextField("title", document.getTitle(), Field.Store.NO));
|
||||||
|
}
|
||||||
|
if (document.getDescription() != null) {
|
||||||
|
luceneDocument.add(new TextField("description", document.getDescription(), Field.Store.NO));
|
||||||
|
}
|
||||||
|
|
||||||
return luceneDocument;
|
return luceneDocument;
|
||||||
}
|
}
|
||||||
@ -224,7 +238,9 @@ public class LuceneDao {
|
|||||||
luceneDocument.add(new StringField("user_id", document.getUserId(), Field.Store.YES));
|
luceneDocument.add(new StringField("user_id", document.getUserId(), Field.Store.YES));
|
||||||
luceneDocument.add(new StringField("type", "file", Field.Store.YES));
|
luceneDocument.add(new StringField("type", "file", Field.Store.YES));
|
||||||
luceneDocument.add(new StringField("document_id", file.getDocumentId(), Field.Store.YES));
|
luceneDocument.add(new StringField("document_id", file.getDocumentId(), Field.Store.YES));
|
||||||
luceneDocument.add(new TextField("content", file.getContent(), Field.Store.NO));
|
if (file.getContent() != null) {
|
||||||
|
luceneDocument.add(new TextField("content", file.getContent(), Field.Store.NO));
|
||||||
|
}
|
||||||
|
|
||||||
return luceneDocument;
|
return luceneDocument;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ public class RebuildIndexAsyncListener {
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onArticleCreated(final RebuildIndexAsyncEvent rebuildIndexAsyncEvent) throws Exception {
|
public void on(final RebuildIndexAsyncEvent rebuildIndexAsyncEvent) throws Exception {
|
||||||
if (log.isInfoEnabled()) {
|
if (log.isInfoEnabled()) {
|
||||||
log.info("Rebuild index event: " + rebuildIndexAsyncEvent.toString());
|
log.info("Rebuild index event: " + rebuildIndexAsyncEvent.toString());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user