public LuceneIndexEditorProvider(@Nullable IndexCopier indexCopier) { //Disable the cache by default in ExtractedTextCache this(indexCopier, new ExtractedTextCache(0, 0)); }
public LuceneIndexEditorProvider(@Nullable IndexCopier indexCopier) { //Disable the cache by default in ExtractedTextCache this(indexCopier, new ExtractedTextCache(0, 0)); }
public LuceneIndexEditorProvider(@Nullable IndexCopier indexCopier, @Nullable IndexTracker indexTracker, ExtractedTextCache extractedTextCache, @Nullable IndexAugmentorFactory augmentorFactory, MountInfoProvider mountInfoProvider, @NotNull ActiveDeletedBlobCollectorFactory.ActiveDeletedBlobCollector activeDeletedBlobCollector, @Nullable LuceneIndexMBean mbean, @Nullable StatisticsProvider statisticsProvider) { this.indexCopier = indexCopier; this.indexTracker = indexTracker; this.extractedTextCache = extractedTextCache != null ? extractedTextCache : new ExtractedTextCache(0, 0); this.augmentorFactory = augmentorFactory; this.mountInfoProvider = checkNotNull(mountInfoProvider); this.activeDeletedBlobCollector = activeDeletedBlobCollector; this.mbean = mbean; this.statisticsProvider = statisticsProvider; }
public LuceneIndexEditorProvider(@Nullable IndexCopier indexCopier, @Nullable IndexTracker indexTracker, ExtractedTextCache extractedTextCache, @Nullable IndexAugmentorFactory augmentorFactory, MountInfoProvider mountInfoProvider, @NotNull ActiveDeletedBlobCollectorFactory.ActiveDeletedBlobCollector activeDeletedBlobCollector, @Nullable LuceneIndexMBean mbean, @Nullable StatisticsProvider statisticsProvider) { this.indexCopier = indexCopier; this.indexTracker = indexTracker; this.extractedTextCache = extractedTextCache != null ? extractedTextCache : new ExtractedTextCache(0, 0); this.augmentorFactory = augmentorFactory; this.mountInfoProvider = checkNotNull(mountInfoProvider); this.activeDeletedBlobCollector = activeDeletedBlobCollector; this.mbean = mbean; this.statisticsProvider = statisticsProvider; }
private void initializeExtractedTextCache(BundleContext bundleContext, Map<String, ?> config) { int cacheSizeInMB = PropertiesUtil.toInteger(config.get(PROP_EXTRACTED_TEXT_CACHE_SIZE), PROP_EXTRACTED_TEXT_CACHE_SIZE_DEFAULT); int cacheExpiryInSecs = PropertiesUtil.toInteger(config.get(PROP_EXTRACTED_TEXT_CACHE_EXPIRY), PROP_EXTRACTED_TEXT_CACHE_EXPIRY_DEFAULT); boolean alwaysUsePreExtractedCache = PropertiesUtil.toBoolean(config.get(PROP_PRE_EXTRACTED_TEXT_ALWAYS_USE), PROP_PRE_EXTRACTED_TEXT_ALWAYS_USE_DEFAULT); extractedTextCache = new ExtractedTextCache( cacheSizeInMB * ONE_MB, cacheExpiryInSecs, alwaysUsePreExtractedCache, indexDir); if (extractedTextProvider != null){ registerExtractedTextProvider(extractedTextProvider); } CacheStats stats = extractedTextCache.getCacheStats(); if (stats != null){ oakRegs.add(registerMBean(whiteboard, CacheStatsMBean.class, stats, CacheStatsMBean.TYPE, stats.getName())); log.info("Extracted text caching enabled with maxSize {} MB, expiry time {} secs", cacheSizeInMB, cacheExpiryInSecs); } }
private void initializeExtractedTextCache(BundleContext bundleContext, Map<String, ?> config) { int cacheSizeInMB = PropertiesUtil.toInteger(config.get(PROP_EXTRACTED_TEXT_CACHE_SIZE), PROP_EXTRACTED_TEXT_CACHE_SIZE_DEFAULT); int cacheExpiryInSecs = PropertiesUtil.toInteger(config.get(PROP_EXTRACTED_TEXT_CACHE_EXPIRY), PROP_EXTRACTED_TEXT_CACHE_EXPIRY_DEFAULT); boolean alwaysUsePreExtractedCache = PropertiesUtil.toBoolean(config.get(PROP_PRE_EXTRACTED_TEXT_ALWAYS_USE), PROP_PRE_EXTRACTED_TEXT_ALWAYS_USE_DEFAULT); extractedTextCache = new ExtractedTextCache( cacheSizeInMB * ONE_MB, cacheExpiryInSecs, alwaysUsePreExtractedCache, indexDir); if (extractedTextProvider != null){ registerExtractedTextProvider(extractedTextProvider); } CacheStats stats = extractedTextCache.getCacheStats(); if (stats != null){ oakRegs.add(registerMBean(whiteboard, CacheStatsMBean.class, stats, CacheStatsMBean.TYPE, stats.getName())); log.info("Extracted text caching enabled with maxSize {} MB, expiry time {} secs", cacheSizeInMB, cacheExpiryInSecs); } }
@Test public void preExtractionAlwaysUse() throws Exception{ ExtractedTextCache cache = new ExtractedTextCache(10 * FileUtils.ONE_MB, 100, true, null); PreExtractedTextProvider provider = mock(PreExtractedTextProvider.class); cache.setExtractedTextProvider(provider); when(provider.getText(anyString(), any(Blob.class))) .thenReturn(new ExtractedText(ExtractionResult.SUCCESS, "bar")); Blob b = new IdBlob("hello", "a"); String text = cache.get("/a", "foo", b, false); assertEquals("bar", text); }
@Test public void preExtractionReindex() throws Exception{ ExtractedTextCache cache = new ExtractedTextCache(10 * FileUtils.ONE_MB, 100); PreExtractedTextProvider provider = mock(PreExtractedTextProvider.class); cache.setExtractedTextProvider(provider); when(provider.getText(anyString(), any(Blob.class))) .thenReturn(new ExtractedText(ExtractionResult.SUCCESS, "bar")); Blob b = new IdBlob("hello", "a"); String text = cache.get("/a", "foo", b, true); assertEquals("bar", text); }
@Test public void cacheDisabling() throws Exception { ExtractedTextCache cache = new ExtractedTextCache(0, 0); assertNull(cache.getCacheStats()); }
@Test public void preExtractionNoReindex() throws Exception{ ExtractedTextCache cache = new ExtractedTextCache(10 * FileUtils.ONE_MB, 100); PreExtractedTextProvider provider = mock(PreExtractedTextProvider.class); cache.setExtractedTextProvider(provider); Blob b = new IdBlob("hello", "a"); String text = cache.get("/a", "foo", b, false); assertNull(text); verifyZeroInteractions(provider); }
@Test public void preExtractionNoReindexNoProvider() throws Exception{ ExtractedTextCache cache = new ExtractedTextCache(10 * FileUtils.ONE_MB, 100); Blob b = new IdBlob("hello", "a"); String text = cache.get("/a", "foo", b, true); assertNull(text); }
@Override protected ContentRepository createRepository() { LuceneIndexEditorProvider editorProvider = new LuceneIndexEditorProvider(null, new ExtractedTextCache(0, 0), factory, Mounts.defaultMountInfoProvider()); LuceneIndexProvider provider = new LuceneIndexProvider(tracker, ScorerProviderFactory.DEFAULT, factory); return new Oak() .with(new OpenSecurityProvider()) .with((QueryIndexProvider) provider) .with((Observer) provider) .with(editorProvider) .createContentRepository(); }
@Test public void cacheEnabledNonIdBlob() throws Exception { ExtractedTextCache cache = new ExtractedTextCache(10 * FileUtils.ONE_MB, 100); Blob b = new ArrayBasedBlob("hello".getBytes()); String text = cache.get("/a", "foo", b, false); assertNull(text); cache.put(b, new ExtractedText(ExtractionResult.SUCCESS, "test hello")); text = cache.get("/a", "foo", b, false); assertNull(text); }
@Test public void rememberTimeout() throws Exception{ ExtractedTextCache cache = new ExtractedTextCache(0, 0, false, null); Blob b = new IdBlob("hello", "a"); cache.put(b, ExtractedText.ERROR); assertNull(cache.get("/a", "foo", b, false)); cache.putTimeout(b, ExtractedText.ERROR); assertEquals(FulltextIndexEditor.TEXT_EXTRACTION_ERROR, cache.get("/a", "foo", b, false)); }
@Test public void nullContentIdentityBlob() throws Exception { ExtractedTextCache cache = new ExtractedTextCache(0, 0); Blob b = new IdBlob("hello", null); cache.put(b, ExtractedText.ERROR); assertNull(cache.get("/a", "foo", b, false)); cache.putTimeout(b, ExtractedText.ERROR); assertNull("Cache returned non null text for blob with null content identity", cache.get("/a", "foo", b, false)); }
@Test public void cacheEnabledErrorInTextExtraction() throws Exception { ExtractedTextCache cache = new ExtractedTextCache(10 * FileUtils.ONE_MB, 100); Blob b = new IdBlob("hello", "a"); String text = cache.get("/a", "foo", b, false); assertNull(text); cache.put(b, new ExtractedText(ExtractionResult.ERROR, "test hello")); text = cache.get("/a", "foo", b, false); assertEquals(FulltextIndexEditor.TEXT_EXTRACTION_ERROR, text); }
@Test public void multiplexingWriter() throws Exception{ newLucenePropertyIndex("lucene", "foo"); MountInfoProvider mip = Mounts.newBuilder() .mount("foo", "/libs", "/apps").build(); EditorHook hook = new EditorHook( new IndexUpdateProvider( new LuceneIndexEditorProvider(null, new ExtractedTextCache(0, 0), null, mip))); NodeState indexed = hook.processCommit(EMPTY_NODE, builder.getNodeState(), CommitInfo.EMPTY); builder = indexed.builder(); NodeState before = indexed; builder.child("content").child("en").setProperty("foo", "bar"); builder.child("libs").child("install").setProperty("foo", "bar"); NodeState after = builder.getNodeState(); indexed = hook.processCommit(before, after, CommitInfo.EMPTY); builder = indexed.builder(); assertEquals(1, numDocs(mip.getMountByName("foo"))); assertEquals(1, numDocs(mip.getDefaultMount())); }
@Override protected ContentRepository createRepository() { IndexCopier copier = createIndexCopier(); editorProvider = new LuceneIndexEditorProvider(copier, new ExtractedTextCache(10* FileUtils.ONE_MB, 100)); provider = new LuceneIndexProvider(copier); queryIndexProvider = new ResultCountingIndexProvider(provider); nodeStore = new MemoryNodeStore(InitialContentHelper.INITIAL_CONTENT); return new Oak(nodeStore) .with(new OpenSecurityProvider()) .with(queryIndexProvider) .with((Observer) provider) .with(editorProvider) .with(optionalEditorProvider) .with(new PropertyIndexEditorProvider()) .with(new NodeTypeIndexProvider()) .createContentRepository(); }
@Test public void cacheEnabled() throws Exception { ExtractedTextCache cache = new ExtractedTextCache(10 * FileUtils.ONE_MB, 100); assertNotNull(cache.getCacheStats()); Blob b = new IdBlob("hello", "a"); String text = cache.get("/a", "foo", b, false); assertNull(text); cache.put(b, new ExtractedText(ExtractionResult.SUCCESS, "test hello")); text = cache.get("/a", "foo", b, false); assertEquals("test hello", text); }
@Override protected ContentRepository createRepository() { IndexCopier copier = null; try { copier = new IndexCopier(executorService, temporaryFolder.getRoot()); } catch (IOException e) { throw new RuntimeException(e); } LuceneIndexEditorProvider editorProvider = new LuceneIndexEditorProvider(copier, new ExtractedTextCache(10*FileUtils.ONE_MB, 100), null, mip); LuceneIndexProvider provider = new LuceneIndexProvider(new IndexTracker(new DefaultIndexReaderFactory(mip, copier))); nodeStore = new MemoryNodeStore(); return new Oak(nodeStore) .with(new InitialContent()) .with(new OpenSecurityProvider()) .with((QueryIndexProvider) provider) .with((Observer) provider) .with(editorProvider) .with(new PropertyIndexEditorProvider()) .with(new NodeTypeIndexProvider()) .createContentRepository(); }