You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/02/18 07:04:39 UTC

[GitHub] [maven-indexer] michael-o commented on a change in pull request #180: [MINDEXER-143] Implement Search API and backends for it.

michael-o commented on a change in pull request #180:
URL: https://github.com/apache/maven-indexer/pull/180#discussion_r809721297



##########
File path: search-api/src/main/java/org/apache/maven/index/search/SEARCH.java
##########
@@ -0,0 +1,54 @@
+package org.apache.maven.index.search;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.index.search.request.Field.NumberField;
+import org.apache.maven.index.search.request.Field.StringField;
+
+/**
+ * The ontology of Search API, "meta" fields.
+ */
+public final class SEARCH

Review comment:
       Why is this uppercase?

##########
File path: search-backend-smo/src/main/java/org/apache/maven/index/search/backend/smo/internal/SmoSearchBackendImpl.java
##########
@@ -0,0 +1,230 @@
+package org.apache.maven.index.search.backend.smo.internal;
+
+/*
+ * 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.
+ */
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonPrimitive;
+import org.apache.maven.index.search.MAVEN;
+import org.apache.maven.index.search.SEARCH;
+import org.apache.maven.index.search.SearchRequest;
+import org.apache.maven.index.search.backend.smo.SmoSearchBackend;
+import org.apache.maven.index.search.backend.smo.SmoSearchResponse;
+import org.apache.maven.index.search.request.BooleanQuery;
+import org.apache.maven.index.search.request.Field;
+import org.apache.maven.index.search.request.FieldQuery;
+import org.apache.maven.index.search.request.Paging;
+import org.apache.maven.index.search.request.Query;
+import org.apache.maven.index.search.support.SearchBackendSupport;
+import org.jetbrains.annotations.NotNull;
+
+import static java.util.Objects.requireNonNull;
+
+public class SmoSearchBackendImpl extends SearchBackendSupport implements SmoSearchBackend

Review comment:
       Never ever use `URLEncoder`!. This class is totally broken. It is not URL-encoding, but form encoding.

##########
File path: search-backend-indexer/src/main/java/org/apache/maven/index/search/backend/indexer/internal/IndexerCoreSearchBackendImpl.java
##########
@@ -0,0 +1,236 @@
+package org.apache.maven.index.search.backend.indexer.internal;
+
+/*
+ * 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.
+ */
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.StreamSupport;
+
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.Query;
+import org.apache.maven.index.ArtifactAvailability;
+import org.apache.maven.index.ArtifactInfo;
+import org.apache.maven.index.GroupedSearchRequest;
+import org.apache.maven.index.GroupedSearchResponse;
+import org.apache.maven.index.Indexer;
+import org.apache.maven.index.IteratorSearchRequest;
+import org.apache.maven.index.IteratorSearchResponse;
+import org.apache.maven.index.SearchType;
+import org.apache.maven.index.context.IndexingContext;
+import org.apache.maven.index.expr.SourcedSearchExpression;
+import org.apache.maven.index.grouping.GAGrouping;
+import org.apache.maven.index.search.MAVEN;
+import org.apache.maven.index.search.SEARCH;
+import org.apache.maven.index.search.SearchRequest;
+import org.apache.maven.index.search.backend.indexer.IndexerCoreSearchBackend;
+import org.apache.maven.index.search.backend.indexer.IndexerCoreSearchResponse;
+import org.apache.maven.index.search.request.Field;
+import org.apache.maven.index.search.request.Paging;
+import org.apache.maven.index.search.support.SearchBackendSupport;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * An engine to perform search trough single repository index (endpoint).
+ */
+public class IndexerCoreSearchBackendImpl extends SearchBackendSupport implements IndexerCoreSearchBackend
+{
+    private static final Map<Field, org.apache.maven.index.Field> FIELD_TRANSLATION;
+
+    static
+    {
+        HashMap<Field, org.apache.maven.index.Field> map = new HashMap<>();
+        map.put( MAVEN.GROUP_ID, org.apache.maven.index.MAVEN.GROUP_ID );
+        map.put( MAVEN.ARTIFACT_ID, org.apache.maven.index.MAVEN.ARTIFACT_ID );
+        map.put( MAVEN.VERSION, org.apache.maven.index.MAVEN.VERSION );
+        map.put( MAVEN.CLASSIFIER, org.apache.maven.index.MAVEN.CLASSIFIER );
+        map.put( MAVEN.PACKAGING, org.apache.maven.index.MAVEN.PACKAGING );
+        map.put( MAVEN.CLASS_NAME, org.apache.maven.index.MAVEN.CLASSNAMES );
+        map.put( MAVEN.FQ_CLASS_NAME, org.apache.maven.index.MAVEN.CLASSNAMES );
+        map.put( MAVEN.SHA1, org.apache.maven.index.MAVEN.SHA1 );
+        FIELD_TRANSLATION = Collections.unmodifiableMap( map );
+    }
+
+    private final Indexer indexer;
+
+    private final IndexingContext indexingContext;
+
+    /**
+     * Creates backend instance using provided indexer and context.
+     */
+    public IndexerCoreSearchBackendImpl( Indexer indexer, IndexingContext indexingContext )
+    {
+        super( indexingContext.getId(), indexingContext.getRepositoryId() );
+        this.indexer = requireNonNull( indexer );
+        this.indexingContext = indexingContext;
+    }
+
+    @NotNull
+    @Override
+    public IndexingContext getIndexingContext()
+    {
+        return indexingContext;
+    }
+
+    @NotNull
+    @Override
+    public IndexerCoreSearchResponse search( SearchRequest searchRequest ) throws IOException
+    {
+        // if GA present in query: doing flat, otherwise grouped search to mimic SMO
+        HashSet<Field> searchedFields = new HashSet<>();

Review comment:
       why is this typed and the upcoming collections not?

##########
File path: search-backend-smo/README.md
##########
@@ -0,0 +1,13 @@
+Indexer Search SMO Backend
+==========================
+
+Search API SMO (https://search.maven.org/) backend implementation.
+
+By default uses GSON only, so is Java8, Android and GraalVM (untested) friendly.

Review comment:
       GSON is deprecated. Move to Jackson. Google has abandoned it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org