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/15 19:31:18 UTC

[GitHub] [maven-indexer] cstamas opened a new pull request #180: [MINDEXER-143] Implement Search API and backends for it.

cstamas opened a new pull request #180:
URL: https://github.com/apache/maven-indexer/pull/180


   High level changes:
   * "move level up" one single group `org.apache.maven.index.search.grouping` hence `org.apache.maven.index.search` is empty (as new package for Search API)
   * implement search-api
   * implement search-backend-indexer and search-backend-smo
   * currently they behave "nearly identical" but there are most probably more cases for tuning
   
   ---
   
   https://issues.apache.org/jira/browse/MINDEXER-143


-- 
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



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

Posted by GitBox <gi...@apache.org>.
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



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

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #180:
URL: https://github.com/apache/maven-indexer/pull/180#discussion_r835747775



##########
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:
       Ironically, my initial implementation did use Moshi, but I disliked the fact it had quite a lot of non-trivial dependencies (okio, kotlin libs). gson is simpler IMHO.




-- 
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



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

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #180:
URL: https://github.com/apache/maven-indexer/pull/180#discussion_r809791738



##########
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:
       As this is a special class (ontology) and only carries "naming" nothing else. Follows same principle that is already present for Maven Indexer ontologies.




-- 
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



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

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #180:
URL: https://github.com/apache/maven-indexer/pull/180#discussion_r809750277



##########
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:
       This is wrong, as IMHO 
   * GSON is quite lively project
   * best fitted to this use case (no OM needed, just picking string/number fields from response JSON) -- ideally would use `org.json` but license disallows 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



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

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #180:
URL: https://github.com/apache/maven-indexer/pull/180#discussion_r809791193



##########
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:
       WDYM?




-- 
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



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

Posted by GitBox <gi...@apache.org>.
cstamas commented on a change in pull request #180:
URL: https://github.com/apache/maven-indexer/pull/180#discussion_r809792524



##########
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:
       Am not encoding any URL with it, but am encoding query parameter values... Still there is `+` vs `%20` issue that will fix




-- 
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



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

Posted by GitBox <gi...@apache.org>.
DarthHater commented on a change in pull request #180:
URL: https://github.com/apache/maven-indexer/pull/180#discussion_r835569486



##########
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:
       I dunno I kinda think you should use Moshi (gson author, seems pretty awesome) https://proandroiddev.com/goodbye-gson-hello-moshi-4e591116231e
   
   PS Hi @cstamas !




-- 
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