将柯南搜索查询传递给联系弹性搜索

时间:2019-04-25 12:44:45

标签: elasticsearch nexus conan

我正在为nexus-conan-repository实现柯南搜索功能: https://github.com/sonatype-nexus-community/nexus-repository-conan

我已经实现了其余的api端点。其余api匹配以下请求:

res=[contractions.get(w,w) for w in abc]

print(res)

“ 1”基于柯南客户的以下请求:

1. (http://localhost:8081/repository/conan-hosted/v1/conans/zlib/[>1.0<1.8]/conan/stable/search?"})
2. http://localhost:8081/repository/conan-hosted/v1/conans/search?q=zlib"

对于“ 1”,搜索请求是一个完整的请求,并且没有“?q =”参数。 但是,对于“ 2”,该请求基于以下柯南客户请求:

conan search 'zlib/[>1.0<1.8]@conan/stable' -r nxrm-conan-hosted 

因此,对于不完整的程序包名称,查询基于?q。

搜索的主要大脑如下:

conan search zlib -r nxrm-conan-hosted

对于像1这样的请求,我们希望提供整个软件包信息,例如:

package org.sonatype.repository.conan.internal.hosted.search;

import org.sonatype.goodies.common.ComponentSupport;

import javax.inject.Named;
import javax.inject.Singleton;
import javax.inject.Inject;

import org.sonatype.nexus.repository.FacetSupport;
import org.sonatype.nexus.repository.view.Context;
import org.sonatype.nexus.repository.view.Parameters;
import org.sonatype.nexus.repository.search.SearchService;
import org.sonatype.nexus.repository.view.Request;

import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.index.query.QueryStringQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

import java.io.IOException;

import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Collections.singletonList;

@Named
public class ConanSearchFacetHosted extends FacetSupport implements ConanSearchFacet {

    private final SearchService nexusSearchService;

    @Inject
    public ConanSearchFacetHosted(final SearchService nexusSearchService) {
        this.nexusSearchService = checkNotNull(nexusSearchService);
    }

    public void searchRecipes(final Context context, String pattern) throws IOException {

        System.out.println("Searching Recipes");

        Request request = context.getRequest();
        Parameters paramsObj = request.getParameters();

        System.out.println("SIZE: " + paramsObj.get("size"));
        System.out.println("FROM: " + paramsObj.get("from"));
        // int size = 

        // String queryText = paramsObj.extractText(paramsObj);

        QueryStringQueryBuilder query = QueryBuilders.queryStringQuery(pattern)
            .allowLeadingWildcard(true)
            .analyzeWildcard(true);

        SearchResponse searchResponse = nexusSearchService.searchUnrestrictedInRepos(query,
            null,
            1,
            19,
            singletonList(getRepository().getName()));


        // System.out.println("Query Text: " + queryText);

    }

    public static void searchPackages() {
         System.out.println("Search Packages");
    }

}

对于类似2的请求,输出如下:

Existing packages for recipe zlib/1.2.11@conan/stable:    

    Package_ID: 51b39bbf59d48fe09b7ac83ddab65ed9b30af19c                                                                        

    [options]                                                                                                                   
        fPIC: True                                                                                                              
        minizip: False                                                                                                            
       shared: True                                                                                                        
    [settings]                                                                                                                  
        arch: x86_64                                                                                                            
        build_type: Release                                                                                                     
        compiler: clang                                                                                                         
        compiler.version: 6.0                                                                                                   
        os: Linux                                                                                                           
     Outdated from recipe: False 

如果我是正确的,则使用弹性搜索进行搜索查询。柯南Web客户端可能正在使用相同的方法。我认为可以使用:

Existing package recipes:

  zlib/1.2.11@conan/stable 

此类具有以下发出搜索请求的方法: (https://github.com/sonatype/nexus-public/blob/a4e21c25d7a24c1395c85a745b4318a6edaa7399/components/nexus-repository/src/main/java/org/sonatype/nexus/repository/search/SearchService.java

org.sonatype.nexus.repository.search.SearchService

如果是发出搜索请求的情况,那么我想了解诸如QueryBuilder之类的参数,以及如何基于http请求中的信息来形成查询。 使用Context对象,我可以获取有关传入请求以及提供的参数的信息。

就目前而言,我没有研究如何生成用于搜索所有程序包的完整响应的特定详细信息,而只是研究如何使用SearchService获得结果。例如,根据包名称,组,版本,格式等查询SearchService。

0 个答案:

没有答案