0

動的クエリを使用して SOLR を検索していますが、ストア ロケーター機能に対して複雑な位置情報クエリを実行しようとしています。場所 (ポイント) から距離 D 以内に最大 5 つの場所を取得する必要があります。また、距離でソートし、結果で距離を返す必要があります。

ただし、API に正しいクエリを出力させる方法がわかりません。

Spring SOLR Data API を使用してこのクエリ出力を正しく取得する方法を教えてください。

SOLR 4+ ジオフィルター機能を使用しています。

私が必要とするSOLRクエリはこれです(直接作業しています):

http://localhost:8983/solr/aust/select?q={!func}geodist()&fl=*,score,geodist()&fq={!geofilt}&pt=-37.818635,145.0014704&sfield=location&d=15&fq=docType:LOCATION&rows=5&wt=json&indent=true&sort=score asc

そして、これまでの私のコードは次のようになります(動作していません):

@Override
    public SimpleSearchResults searchByRegion (SimpleSearchForm searchForm, RegionDocument region)
    {
        logger.entry();


        SimpleQuery query = new SimpleQuery();
        query.addCriteria(new Criteria("text").contains(Criteria.WILDCARD));
        int distance = 5;
        Point point = new org.springframework.data.solr.core.geo.Point(region.getLat(), region.getLng());

        GeoDistanceFunction geo = GeoDistanceFunction.distanceFrom("location").to(point);
        query.addFilterQuery(new SimpleFilterQuery(Criteria.where(geo)));
        SimpleFilterQuery typeQuery = new SimpleFilterQuery();
        typeQuery.addCriteria(new Criteria("docType").is("LOCATION"));

        Sort sort = new Sort(Sort.Direction.ASC, "score");
        query.addFilterQuery(typeQuery);

        // add paging to request
        PageRequest page = new PageRequest(0, 5, sort);
        query.setPageRequest(page);

        // we build the search request without facets initially
        //search.setPageRequest(page);
        Page<LocationDocument> results = solrTemplate1.queryForPage(query, LocationDocument.class);

        logger.exit();

        SimpleSearchResults dto2 = new SimpleSearchResults();
        dto2.setSearchTerm(searchForm.getSearchTerm());
        dto2.setPage(results);

        return dto2;
    }
4

1 に答える 1

0

参考までに、ここに投稿されたソリューションのバリエーションの後に、これを機能させることができました:Spring-data-solrを使用して空間検索で距離とスコアを返す方法

SOLR 4 タイプの location_rpt を使用しているため、geodist() 関数はこのタイプをサポートしていません。そのため、ドキュメントでは、スコアパラメーターを使用して距離を返す代わりの方法を提案しています。(度として返され、変換する必要があることに注意してください=誰かがSOLRでその変換を行う方法を知っている場合は、ここに投稿してください)。

そのため、単純な文字列基準を使用して、score=distance フレーズを Geofilter 式に追加することになりました。

Spring Data SOLR API と location_rpt スキーマ タイプを使用して、距離で並べ替えられたジオフィルターの結果を取得するコードを次に示します。

@Override
    public SimpleSearchResults searchByRegion(SimpleSearchForm searchForm, RegionDocument region) {
        logger.entry();


        SimpleQuery query = new SimpleQuery();
        query.addProjectionOnField("*");
        query.addProjectionOnField("score");

        StringBuffer buf = new StringBuffer("");
        buf.append("{!geofilt pt=");
        buf.append(region.getLat());
        buf.append(",");
        buf.append(region.getLng());
        buf.append(" sfield=location d=");
        buf.append(5.0);
        buf.append(" score=distance}");

        query.addCriteria(new SimpleStringCriteria(buf.toString()));

        FilterQuery docType = new SimpleFilterQuery();
        docType.addCriteria(new Criteria("docType").is("LOCATION"));

        query.addFilterQuery(docType);

        query.addSort(new Sort(Sort.Direction.ASC, "score"));

        Page<LocationDocument> results = solrTemplate1.queryForPage(query, LocationDocument.class);


        SimpleSearchResults dto2 = new SimpleSearchResults();
        dto2.setSearchTerm(searchForm.getSearchTerm());

        if (results.getContent().isEmpty()) {
            logger.debug("results were empty.");
        } else {
            dto2.setPage(results);
        }

        logger.exit();

        return dto2;
    }
于 2014-08-24T06:56:58.933 に答える