반응형
Recent Posts
Recent Comments
관리 메뉴

개발잡부

[900gle] Java High Level REST Client Query 4 본문

카테고리 없음

[900gle] Java High Level REST Client Query 4

닉의네임 2022. 2. 4. 22:06
반응형

 

python 으로 테스트 했을때 쓸만해 보여서 작업해봐야겠다. 

script_query = {
        "function_score": {
            "query": {
                "bool": {
                    "must": [
                        {
                            "multi_match": {
                                "query": query,
                                "fields": [
                                    "name",
                                    "category"
                                ]
                            }
                        }],
                    "should": [
                        {
                            "multi_match": {
                                "query": query,
                                "fields": [
                                    "category1",
                                    "category2",
                                    "category3",
                                    "category4",
                                    "category5"
                                ]
                            }
                        }
                    ]
                }
            },
            "boost_mode": "multiply",
            "functions": [
                {
                    "script_score": {
                        "script": {
                            "source": "cosineSimilarity(params.query_vector, 'feature_vector') * doc['weight'].value * doc['popular'].value / doc['name.keyword'].length + doc['category.keyword'].length",
                            "params": {
                                "query_vector": query_vector
                            }
                        }
                    },
                    "weight": 0.1
                }
            ]
        }
    }

 

High Level REST Client JAVA 로 변경하면  

            FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(
                    QueryBuilders.boolQuery().must(
                            QueryBuilders.multiMatchQuery(searchWord, "name", "category")
                    ).should(
                            QueryBuilders.multiMatchQuery(searchWord, "category1", "category2", "category3", "category4", "category5")
                    ),
                    new FunctionScoreQueryBuilder.FilterFunctionBuilder[]{
                            new FunctionScoreQueryBuilder.FilterFunctionBuilder(
                                    new ScriptScoreFunctionBuilder(
                                            new Script(
                                                    ScriptType.INLINE,
                                                    Script.DEFAULT_SCRIPT_LANG,
                                                    "cosineSimilarity(params.query_vector, 'feature_vector') * doc['weight'].value * doc['popular'].value / doc['name.keyword'].length + doc['category.keyword'].length",
                                                    map)
                                    ).setWeight(0.1f)
                            )
                    }
            );

 

일단 테스트 해보고 

searchword 에대한 전처리 필요 

 

 

음..  좋은 결과다

 

아이폰 케이스로 검색 

 

반응형
Comments