我第一次使用Solr和Solrnet。
我已经成功地创建了一个模式,其中包含以下字段:
created_date DateTime
parent_id int
categories string multi-valued我已经能够对parent_id字段进行基本搜索,如下所示:
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<SolrNode>>();
ICollection<SolrNode> results = solr.Query(new SolrQueryByField("parent_id", currentNode.Id.ToString()));我已经想出了如何返回所有结果的方面,如下所示:
var solrFacet = ServiceLocator.Current.GetInstance<ISolrOperations<SolrNode>>();
var r = solrFacet.Query(SolrQuery.All, new QueryOptions
{
Rows = 0,
Facet = new FacetParameters
{
Queries = new[] {
//new SolrFacetDateQuery("created_date", DateTime.Now /* range start */, DateTime.Now.AddMonths(-6) /* range end */, "+1DAY" /* gap */) {
// HardEnd = true,
// Other = new[] {FacetDateOther.After, FacetDateOther.Before}
//}
new SolrFacetDateQuery("created_date", new DateTime(2011, 1, 1).AddDays(-1) /* range start */, new DateTime(2014, 1, 1).AddMonths(1) /* range end */, "+1MONTH" /* gap */) {
HardEnd = true,
Other = new[] {FacetDateOther.After, FacetDateOther.Before}
}
//,
//new SolrFacetFieldQuery("categories")
},
}
});
//foreach (var facet in r.FacetFields["categories"])
//{
// this.DebugLiteral.Text += string.Format("{0}: {1}{2}", facet.Key, facet.Value, "<br />");
//}
DateFacetingResult dateFacetResult = r.FacetDates["created_date"];
foreach (KeyValuePair<DateTime, int> dr in dateFacetResult.DateResults)
{
this.DebugLiteral.Text += string.Format("{0}: {1}{2}", dr.Key, dr.Value, "<br />");
}但我想不出的是如何把它们放在一起。我的要求如下:
页面加载-显示所有parent_id匹配的搜索结果。搜索结果的查询方面,并显示如下方面的勾选框:
类别
在
用户单击相关的勾选框,然后代码执行另一个solr查询,传递两个parent_id条件以及用户选择的方面。
我意识到,在我的描述中,我简化了这个过程,也许在StackOverflow上问它是一个相当大的问题,所以我当然不希望有一个有用的例子(尽管你觉得无聊,请随意),但是有人能提供任何指点或例子吗?SolrNet确实有一个MVC示例应用程序,但我使用的是WebForms,还不太适合使用MVC。
任何帮助都将不胜感激。
预先感谢Al
发布于 2013-07-29 06:41:58
您可以使用查询并将facet添加为查询操作。
ISolrQueryResults<TestDocument> r = solr.Query("product_id:XXXXX", new QueryOptions {
FacetQueries = new ISolrFacetQuery[] {
new SolrFacetFieldQuery("category")
}
});发布于 2015-05-16 14:49:04
我创建一个'fq‘字符串的方面被选中。例如,如果用户选择这些方面:
united states
california
almond growers而facet字段是'content_type',我生成这个查询字符串:
(content_type:"united states" AND content_type:california AND content_type:"almond growers")注意引号和打开和关闭的parenthesis...important!我将其存储在名为finalFacet的变量中。然后,我像这样将它提交给Solr,其中sQuery是用户正在搜索的文本,finalFacet是facet查询字符串,如下所示:
articles = solr.Query(sQuery, new QueryOptions
{
ExtraParams = new Dictionary<string, string> {
{"fq", finalFacet},
},
Facet = new FacetParameters
{
Queries = new[] { new SolrFacetFieldQuery("content_type")}
},
Rows = 10
Start = 1,
});https://stackoverflow.com/questions/17900848
复制相似问题