Skip to content

Commit f774e3a

Browse files
committed
Added the getText method
1 parent f4d35ab commit f774e3a

File tree

1 file changed

+25
-0
lines changed
  • logicaldoc-core/src/main/java/com/logicaldoc/core/automation

1 file changed

+25
-0
lines changed

logicaldoc-core/src/main/java/com/logicaldoc/core/automation/DocTool.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import com.logicaldoc.core.metadata.Template;
3232
import com.logicaldoc.core.metadata.TemplateDAO;
3333
import com.logicaldoc.core.parser.ParsingException;
34+
import com.logicaldoc.core.searchengine.Hit;
35+
import com.logicaldoc.core.searchengine.SearchEngine;
3436
import com.logicaldoc.core.security.Tenant;
3537
import com.logicaldoc.core.security.TenantDAO;
3638
import com.logicaldoc.core.security.authorization.PermissionException;
@@ -986,4 +988,27 @@ public String parse(Document document, String fileVersion) {
986988
return null;
987989
}
988990
}
991+
992+
/**
993+
* Same as {@link #DocTool.parse()} but first it tries to get the text from
994+
* the already built fulltext index
995+
*
996+
* @param document The document to elaborate
997+
*
998+
* @return the extracted texts
999+
*/
1000+
public String getText(Document document) {
1001+
String text = null;
1002+
1003+
if (document.getIndexed() == AbstractDocument.INDEX_INDEXED) {
1004+
SearchEngine indexer = Context.get(SearchEngine.class);
1005+
Hit hit = indexer.getHit(document.getId());
1006+
if (hit != null)
1007+
text = hit.getContent();
1008+
}
1009+
1010+
if (StringUtils.isEmpty(text))
1011+
text = parse(document, null);
1012+
return text;
1013+
}
9891014
}

0 commit comments

Comments
 (0)