You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2024/10/11 16:43:54 UTC
(jackrabbit-oak) branch 1.22 updated: OAK-10694: Remove oak-search-mt
This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch 1.22
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/1.22 by this push:
new e684e279f1 OAK-10694: Remove oak-search-mt
e684e279f1 is described below
commit e684e279f1e0d357937ec62c356f15281dcf4549
Author: Julian Reschke <re...@apache.org>
AuthorDate: Fri Oct 11 17:43:43 2024 +0100
OAK-10694: Remove oak-search-mt
---
Jenkinsfile | 2 +-
...e.jackrabbit.oak.jcr.osgi.RepositoryManager.cfg | 30 ++---
...krabbit.oak.segment.SegmentNodeStoreService.cfg | 32 ++---
.../index/mt/MTFulltextQueryTermsProvider.java | 144 ---------------------
.../mt/MTFulltextQueryTermsProviderFactory.java | 144 ---------------------
.../index/mt/MTFulltextQueryTermsProviderTest.java | 64 ---------
pom.xml | 1 -
7 files changed, 32 insertions(+), 385 deletions(-)
diff --git a/Jenkinsfile b/Jenkinsfile
index 58c86186fd..9af84b69d9 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -20,7 +20,7 @@
// schedule oak-jcr:ut,oak-search-elastic,oak-segment-tar,oak-store-document first
// because they are longest running modules
-def OAK_MODULES = 'oak-jcr:ut,oak-search-elastic,oak-segment-tar,oak-store-document,oak-api,oak-auth-external,oak-auth-ldap,oak-authorization-cug,oak-authorization-principalbased,oak-benchmarks,oak-blob,oak-blob-cloud,oak-blob-cloud-azure,oak-blob-plugins,oak-commons,oak-core,oak-core-spi,oak-examples,oak-exercise,oak-http,oak-it,oak-it-osgi,oak-jackrabbit-api,oak-jcr:it,oak-lucene,oak-pojosr,oak-query-spi,oak-run,oak-run-commons,oak-search,oak-search-mt,oak-security-spi,oak-segment-azur [...]
+def OAK_MODULES = 'oak-jcr:ut,oak-search-elastic,oak-segment-tar,oak-store-document,oak-api,oak-auth-external,oak-auth-ldap,oak-authorization-cug,oak-authorization-principalbased,oak-benchmarks,oak-blob,oak-blob-cloud,oak-blob-cloud-azure,oak-blob-plugins,oak-commons,oak-core,oak-core-spi,oak-examples,oak-exercise,oak-http,oak-it,oak-it-osgi,oak-jackrabbit-api,oak-jcr:it,oak-lucene,oak-pojosr,oak-query-spi,oak-run,oak-run-commons,oak-search,oak-security-spi,oak-segment-azure,oak-solr-cor [...]
properties([buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10'))])
diff --git a/oak-it-osgi/src/test/config/org.apache.jackrabbit.oak.jcr.osgi.RepositoryManager.cfg b/oak-it-osgi/src/test/config/org.apache.jackrabbit.oak.jcr.osgi.RepositoryManager.cfg
index 9de8f50d9c..f8181f92fb 100644
--- a/oak-it-osgi/src/test/config/org.apache.jackrabbit.oak.jcr.osgi.RepositoryManager.cfg
+++ b/oak-it-osgi/src/test/config/org.apache.jackrabbit.oak.jcr.osgi.RepositoryManager.cfg
@@ -1,15 +1,15 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#Empty config to trigger default setup
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#Empty config to trigger default setup
diff --git a/oak-it-osgi/src/test/config/org.apache.jackrabbit.oak.segment.SegmentNodeStoreService.cfg b/oak-it-osgi/src/test/config/org.apache.jackrabbit.oak.segment.SegmentNodeStoreService.cfg
index d05269419a..ccc6a4fde9 100644
--- a/oak-it-osgi/src/test/config/org.apache.jackrabbit.oak.segment.SegmentNodeStoreService.cfg
+++ b/oak-it-osgi/src/test/config/org.apache.jackrabbit.oak.segment.SegmentNodeStoreService.cfg
@@ -1,16 +1,16 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-name=Oak
-repository.home=target/tarmk
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+name=Oak
+repository.home=target/tarmk
diff --git a/oak-search-mt/src/main/java/org/apache/jackrabbit/oak/plugins/index/mt/MTFulltextQueryTermsProvider.java b/oak-search-mt/src/main/java/org/apache/jackrabbit/oak/plugins/index/mt/MTFulltextQueryTermsProvider.java
deleted file mode 100644
index 26bb30cc29..0000000000
--- a/oak-search-mt/src/main/java/org/apache/jackrabbit/oak/plugins/index/mt/MTFulltextQueryTermsProvider.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.jackrabbit.oak.plugins.index.mt;
-
-import java.io.StringReader;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.jackrabbit.oak.plugins.index.lucene.OakAnalyzer;
-import org.apache.jackrabbit.oak.plugins.index.lucene.spi.FulltextQueryTermsProvider;
-import org.apache.jackrabbit.oak.plugins.index.search.FieldNames;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.joshua.decoder.Decoder;
-import org.apache.joshua.decoder.StructuredTranslation;
-import org.apache.joshua.decoder.Translation;
-import org.apache.joshua.decoder.segment_file.Sentence;
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.analysis.TokenStream;
-import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.queryparser.simple.SimpleQueryParser;
-import org.apache.lucene.search.BooleanClause;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.util.Version;
-import org.jetbrains.annotations.NotNull;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * {@link FulltextQueryTermsProvider} that performs machine translation on full text returning a query containing
- * translated tokens.
- * @deprecated see OAK-10694
- */
-@Deprecated
-public class MTFulltextQueryTermsProvider implements FulltextQueryTermsProvider {
-
- private final Logger log = LoggerFactory.getLogger(getClass());
-
- private final Decoder decoder;
- private final Set<String> nodeTypes;
- private final float minScore;
- private final SimpleQueryParser qp;
-
- public MTFulltextQueryTermsProvider(Decoder decoder, Set<String> nodeTypes, float minScore) {
- this.decoder = decoder;
- this.nodeTypes = nodeTypes;
- this.minScore = minScore;
- this.qp = new SimpleQueryParser(new OakAnalyzer(Version.LUCENE_47), FieldNames.FULLTEXT);
- }
-
- @Override
- public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) {
-
- BooleanQuery query = new BooleanQuery();
- try {
- Sentence sentence = new Sentence(text, text.hashCode(), decoder.getJoshuaConfiguration());
- Translation translation = decoder.decode(sentence);
- log.debug("{} decoded into {}", text, translation);
- query.add(new BooleanClause(new TermQuery(new Term(FieldNames.FULLTEXT, translation.toString())), BooleanClause.Occur.SHOULD));
-
-
- // try phrase translation first
- List<StructuredTranslation> structuredTranslations = translation.getStructuredTranslations();
- log.debug("found {} structured translations", structuredTranslations.size());
- if (!structuredTranslations.isEmpty()) {
- log.debug("phrase translation");
- addTranslations(query, structuredTranslations);
- } else {
- // if phrase cannot be translated, perform token by token translation
- log.debug("per token translation");
-
- TokenStream tokenStream = analyzer.tokenStream(null, new StringReader(text));
- tokenStream.addAttribute(CharTermAttribute.class);
- tokenStream.reset();
- while (tokenStream.incrementToken()) {
- CharTermAttribute attribute = tokenStream.getAttribute(CharTermAttribute.class);
- String source = attribute.toString();
- Translation translatedToken = decoder.decode(new Sentence(source, source.hashCode(),
- decoder.getJoshuaConfiguration()));
- addTranslations(query, translatedToken.getStructuredTranslations());
- }
- tokenStream.end();
- }
-
- } catch (Exception e) {
- log.error("could not translate query", e);
- }
- return query.clauses().size() > 0 ? query : null;
- }
-
- private void addTranslations(BooleanQuery query, List<StructuredTranslation> structuredTranslations) {
- for (StructuredTranslation st : structuredTranslations) {
- String translationString = st.getTranslationString();
- float translationScore = st.getTranslationScore();
- log.debug("translation {} has score {}", translationString, translationScore);
- if (translationScore > minScore) {
- log.debug("translation score for {} is {}", translationString, translationScore);
- query.add(new BooleanClause(qp.createPhraseQuery(FieldNames.FULLTEXT, translationString),
- BooleanClause.Occur.SHOULD));
- log.debug("added query for translated phrase {}", translationString);
- List<String> translationTokens = st.getTranslationTokens();
- int i = 0;
- // if output is a phrase, look for tokens having a word alignment to the original sentence terms
- for (List<Integer> wa : st.getTranslationWordAlignments()) {
- if (!wa.isEmpty()) {
- String translatedTerm = translationTokens.get(i);
- Query termQuery = qp.parse(translatedTerm);
- query.add(new BooleanClause(termQuery, BooleanClause.Occur.SHOULD));
- log.debug("added query for translated token {}", translatedTerm);
- }
- i++;
- }
- }
- }
- }
-
- public void clearResources() {
- decoder.cleanUp();
- }
-
- @NotNull
- @Override
- public Set<String> getSupportedTypes() {
- return nodeTypes;
- }
-}
diff --git a/oak-search-mt/src/main/java/org/apache/jackrabbit/oak/plugins/index/mt/MTFulltextQueryTermsProviderFactory.java b/oak-search-mt/src/main/java/org/apache/jackrabbit/oak/plugins/index/mt/MTFulltextQueryTermsProviderFactory.java
deleted file mode 100644
index f3c373ea42..0000000000
--- a/oak-search-mt/src/main/java/org/apache/jackrabbit/oak/plugins/index/mt/MTFulltextQueryTermsProviderFactory.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.jackrabbit.oak.plugins.index.mt;
-
-import java.io.File;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.ConfigurationPolicy;
-import org.osgi.service.component.annotations.Deactivate;
-import org.osgi.service.metatype.annotations.AttributeDefinition;
-import org.osgi.service.metatype.annotations.AttributeType;
-import org.osgi.service.metatype.annotations.Designate;
-import org.osgi.service.metatype.annotations.ObjectClassDefinition;
-import org.apache.jackrabbit.oak.commons.PropertiesUtil;
-import org.apache.jackrabbit.oak.plugins.index.lucene.spi.FulltextQueryTermsProvider;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.joshua.decoder.Decoder;
-import org.apache.joshua.decoder.JoshuaConfiguration;
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.search.Query;
-import org.jetbrains.annotations.NotNull;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Factory for {@link MTFulltextQueryTermsProvider}
- * @deprecated see OAK-10694
- */
-@Component(
- service = { FulltextQueryTermsProvider.class },
- configurationPolicy = ConfigurationPolicy.REQUIRE
-)
-@Designate(
- ocd = MTFulltextQueryTermsProviderFactory.Configuration.class,
- factory = true )
-@Deprecated
-public class MTFulltextQueryTermsProviderFactory implements FulltextQueryTermsProvider {
-
- @ObjectClassDefinition(
- id = "org.apache.jackrabbit.oak.plugins.index.mt.MTFulltextQueryTermsProviderFactory",
- name = "Apache Jackrabbit Oak Machine Translation Fulltext Query Terms Provider"
- )
- @interface Configuration {
-
- @AttributeDefinition(
- name = "Joshua Config Path",
- description = "The absolute filesystem path to Apache Joshua configuration file"
- )
- String path_to_config();
-
- @AttributeDefinition(
- name = "Node types",
- description = "List of node types for which expanding the query via MT",
- cardinality = 10
- )
- String[] node_types();
-
- @AttributeDefinition(
- name = "Minimum score",
- description = "Minimum allowed score for a translated phrase/term to be used for expansion",
- type = AttributeType.FLOAT
- )
- float min_score() default DEFAULT_MIN_SCORE;
- }
-
- private static final float DEFAULT_MIN_SCORE = 0.5f;
-
- private final Logger log = LoggerFactory.getLogger(getClass());
-
- private MTFulltextQueryTermsProvider queryTermsProvider;
-
- @Activate
- public void activate(Configuration config) {
- String pathToJoshuaConfig = PropertiesUtil.toString(config.path_to_config(), ".");
- String[] nts = PropertiesUtil.toStringArray(config.node_types(), new String[]{"Oak:unstructured"});
- float minScore = (float) PropertiesUtil.toDouble(config.min_score(), DEFAULT_MIN_SCORE);
- log.info("activating MT FulltextQueryTermProvider from Joshua config at {} on {} nodetypes, minScore {}", pathToJoshuaConfig, nts, minScore);
- Decoder decoder = null;
- try {
- log.debug("reading joshua config");
- JoshuaConfiguration configuration = new JoshuaConfiguration();
- configuration.readConfigFile(pathToJoshuaConfig);
- configuration.setConfigFilePath(new File(pathToJoshuaConfig).getCanonicalFile().getParent());
- configuration.use_structured_output = true;
- decoder = new Decoder(configuration, pathToJoshuaConfig);
- log.debug("decoder initialized");
- Set<String> nodeTypes = new HashSet<>();
- nodeTypes.addAll(Arrays.asList(nts));
- queryTermsProvider = new MTFulltextQueryTermsProvider(decoder, nodeTypes, minScore);
- } catch (Exception e) {
- log.error("could not initialize MTFulltextQueryTermProvider", e);
- if (decoder != null) {
- decoder.cleanUp();
- }
- }
- }
-
- @Deactivate
- public void deactivate() {
- if (queryTermsProvider != null) {
- log.debug("clearing resources");
- queryTermsProvider.clearResources();
- }
- }
-
- @Override
- public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) {
- if (queryTermsProvider != null) {
- return queryTermsProvider.getQueryTerm(text, analyzer, indexDefinition);
- } else {
- return null;
- }
- }
-
- @NotNull
- @Override
- public Set<String> getSupportedTypes() {
- if (queryTermsProvider != null) {
- return queryTermsProvider.getSupportedTypes();
- } else {
- return Collections.emptySet();
- }
- }
-}
diff --git a/oak-search-mt/src/test/java/org/apache/jackrabbit/oak/plugins/index/mt/MTFulltextQueryTermsProviderTest.java b/oak-search-mt/src/test/java/org/apache/jackrabbit/oak/plugins/index/mt/MTFulltextQueryTermsProviderTest.java
deleted file mode 100644
index beeb6bb274..0000000000
--- a/oak-search-mt/src/test/java/org/apache/jackrabbit/oak/plugins/index/mt/MTFulltextQueryTermsProviderTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.jackrabbit.oak.plugins.index.mt;
-
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.joshua.decoder.Decoder;
-import org.apache.joshua.decoder.JoshuaConfiguration;
-import org.apache.joshua.decoder.StructuredTranslation;
-import org.apache.joshua.decoder.Translation;
-import org.apache.joshua.decoder.segment_file.Sentence;
-import org.apache.lucene.analysis.Analyzer;
-import org.junit.Test;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-/**
- * Tests for {@link MTFulltextQueryTermsProvider}
- * @deprecated see OAK-10694
- */
-@Deprecated
-public class MTFulltextQueryTermsProviderTest {
-
- @Test
- public void testGetQueryTermWithPhraseTranslation() throws Exception {
- Decoder decoder = mock(Decoder.class);
- Translation translation = mock(Translation.class);
- List<StructuredTranslation> translations = new LinkedList<>();
- StructuredTranslation structuredTranslation = mock(StructuredTranslation.class);
- when(structuredTranslation.getTranslationString()).thenReturn("fou bur");
- translations.add(structuredTranslation);
- when(translation.getStructuredTranslations()).thenReturn(translations);
- when(decoder.decode(any(Sentence.class))).thenReturn(translation);
- JoshuaConfiguration configuration = mock(JoshuaConfiguration.class);
- when(decoder.getJoshuaConfiguration()).thenReturn(configuration);
- Set<String> nodeTypes = new HashSet<>();
- MTFulltextQueryTermsProvider mtFulltextQueryTermsProvider = new MTFulltextQueryTermsProvider(decoder, nodeTypes, -1);
- Analyzer analyzer = mock(Analyzer.class);
- NodeState indexDefinition = mock(NodeState.class);
- mtFulltextQueryTermsProvider.getQueryTerm("foo bar", analyzer, indexDefinition);
- }
-}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 777f70f6d6..3eae842619 100644
--- a/pom.xml
+++ b/pom.xml
@@ -60,7 +60,6 @@
<module>oak-lucene</module>
<module>oak-solr-core</module>
<module>oak-solr-osgi</module>
- <module>oak-search-mt</module>
<module>oak-auth-external</module>
<module>oak-auth-ldap</module>
<module>oak-run-commons</module>