1

您好我对 Solr 模块 MoreLikeThis 感兴趣,但我不知道如何使用它。我有一个字符串,我不想在文档中搜索类似的文本,所以我这样做:

        internal static List<SolrRecord> FindMoreLikeThis(int shopId, string myString)
    {
        var result = new List<SolrRecord>();
        //coś z moreLikeThis
        var query = string.Format("shopid: {0}",shopId);

        var solr = ServiceLocator.Current.GetInstance<ISolrOperations<SolrRecord>>();

        var results3 = solr.MoreLikeThis(
            new SolrMoreLikeThisHandlerQuery(new SolrQuery(query)),
            new MoreLikeThisHandlerQueryOptions(
                new MoreLikeThisHandlerParameters(new string[] { "description" })
                    {
                        MatchInclude = true,
                        MinWordLength = 3,
                    })
                {
                    Rows = 10,
                });
        var baseDocument = results3.Match;
        var interestingTerms = results3.InterestingTerms;
        result.AddRange(results3);
        return result;
    }

我想搜索包含 myString 的拍卖描述。我有没有 html 标签、样式和其他的拍卖描述。只有文字。

有人可以告诉我它是如何工作的吗?我需要将我的字符串索引到 Solr 吗?

@edit 我有这个

        internal static List<SolrRecord> FindMoreLikeThis(int shopId, string myString)
    {
        var result = new List<SolrRecord>();

        var query = string.Format("description: \"{0}\"", myString);
        var solr = ServiceLocator.Current.GetInstance<ISolrOperations<SolrRecord>>();

        ICollection<ISolrQuery> filters = new List<ISolrQuery>();
        filters.Add(new SolrQuery("shopid: 77777"));

        var results = solr.MoreLikeThis(
            new SolrMoreLikeThisHandlerQuery(new SolrQuery(query)),
            new MoreLikeThisHandlerQueryOptions(
                new MoreLikeThisHandlerParameters(new List<string>() { "description" })
                    {
                        MinTermFreq = 1,
                        MinDocFreq = 1
                    })
                {
                    Rows = 5,
                    Fields = new List<string>() { "score", "*" },
                    FilterQueries = filters
                });
        result.AddRange(results);             

        return result;
    }

在参数 myString 中,我添加:“对于运动驾驶”,在 XML 中,我有文档,其描述有:“对于运动驾驶梅赛德斯每个班级”.. 结果我没有看到这个命题,但 myString 中的所有单词都等于描述在本文档中..请帮助。

4

1 回答 1

1

首先,您应该索引 Solr 中的所有文档。

然后我建议通过直接向 Solr 调用请求来玩弄。在你让它工作之后,你可以编写你的客户端代码。

MoreLikeThis 的示例查询可能是这样的:

http://localhost:8983/solr/select?q=apache&mlt=true&mlt.fl=manu,cat&mlt.mindf=1&mlt.mintf=1&fl=id,score

请参阅文档:https ://wiki.apache.org/solr/MoreLikeThis

于 2015-09-22T14:34:12.400 回答