Reputation: 79
Hello i'm interested in Solr module MoreLikeThis, but I don't know how to use it. I have one string and i wan't search similar text in documents so i do this:
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;
}
I want to search the auction description that will include myString. Auction description i have without html tags, styles and other. Only text.
Can someone tell me how it works? I need to index my string to Solr ?
@edit I've this
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;
}
To parametr myString i add: "For sport driving" and in XML i have document whose in description have: "For sport driving mercedes each class".. in result i don't see this proposition but all words in myString are equal to description in this document.. Help please.
Upvotes: 1
Views: 532
Reputation: 14930
First you should index all documents in Solr.
Then I suggest to play around by calling requests to Solr directly. After you have get it to work you may write your client code.
An example query for MoreLikeThis could be like this:
http://localhost:8983/solr/select?q=apache&mlt=true&mlt.fl=manu,cat&mlt.mindf=1&mlt.mintf=1&fl=id,score
See the documentation: https://wiki.apache.org/solr/MoreLikeThis
Upvotes: 1