SolrNet : How do I search a Multi-valued Field in Solr? - search

I am using SolrNet and my schema looks something like the following:
<int name="prodId">Id</prodid>
<str name="prodname">Name</prodname>
<arr name="categories"><str>Cat1</str><str>Cat2</str></categories
....
</doc>
Now I want to perform a search by Category. That is retrieve product whose category collection has "Cat1" for example. Please let me know how I can do this using SolrNet. Thanks!

You do not need to do anything special for searching a multivalued field. The following should work just fine:
var query = new SolrQueryByField("categories","Cat1");
or
var query = new SolrQuery("categories:Cat1");

Related

How get value with soapui (groovy) from a xml with equals tags but differents attributes

I'm making an automated script in groovy that gets data from a SOLR and then set that data in properties for future use.
I'm using the script assertion to do this 'cause reduce the quantity of steps in the suit.
The problem is: the XML received from SOLR has the same name in all the data, the only difference is the attribute "name".
I want to get the values by the attribute.
I've tried with xmlSlurper and XmlHolder but I can't get only one value, only get an array of data (SOLR can answer in randomly order the doc, so I can't use this solution).
The answer of SOLR is like this:
<response>
<doc>
<str name="Destination">6</str>
<str name="BUS">0</str>
<str name="Tax">N</str>
<str name="Passage">N</str>
<str name="Vendor">2301</str>
<str name="id">1135XV942220</str>
</doc>
</response>
I've tried:
def resp = new XmlSlurper().parseText(context.response)
def results = resp.response.doc.find {it.name()=="BUS"}?.text()
this get me nothing.
def results = resp.response.doc.str.'#name'.text().equals('BUS')
Get me the value false (?)
I want to get, for example, the id and transfer it to a property at test suite level.
Any possible solutions?
With XmlHolder...
import com.eviware.soapui.support.XmlHolder
resp = new XmlHolder(context.response)
log.info resp.getNodeValue("//response/doc/str[#name='BUS']")

Highlighter.net returns no matches

I am using lucene.net 2.9.4 and lucene.net contrib 2.9.4 my lucene query looks like:
+contents:umbraco*
I get results for this query. My highlighter code to get fragments looks like:
public string GetHighlight(string value, string highlightField, IndexSearcher searcher, string luceneRawQuery)
{
var query = GetQueryParser(highlightField).Parse(luceneRawQuery);
var scorer = new QueryScorer(searcher.Rewrite(query));
var highlighter = new Highlighter(HighlightFormatter, scorer);
var tokenStream = HighlightAnalyzer.TokenStream(highlightField, new StringReader(value));
return highlighter.GetBestFragments(tokenStream, value, MaxNumHighlights, Separator);
}
In my scorer object the property termsToFind is 0 I would expect that to at least be one? Anyone any ideas or suggestions on how to fix / debug?
Regards
Ismail
Ok figured this out I was passing in the wrong values to the highlighter function. I was passing the query search term and field name. What i needed to pass in was the content of the contents field for each document match and the query term. All working now.

How to add Count() method on my content type in orchard?

I have a content type named "News" with Title, Body, Autoroute and a TextField. I have 2 problems:
To Count value of content items by text field named Author (can't use taxonomy terms).
To Count total sum of content items by Date (from 2017-01-01 to 2017-12-31)
Now, I want to add a Count() method on my content type, so I can filter, sort and use Projection.
How can I do this?
Or do you have a better method for it?
Thanks!
I'd use Orchards ISearchService for this. Just add your ContentType to a search index (you can have multiple indices) and check the fields you want to include, like created and author.
Then you can search like this and use the TotalItemCount property of the ISearchService:
var pager = new Pager(this.OrchardServices.WorkContext.CurrentSite, page, pageSize);
var searchSettingsPart = this.OrchardServices.WorkContext.CurrentSite.As<SearchSettingsPart>();
// Orchard.Search.Services.ISearchService
var searchHits = this.searchService.Search.Query(
searchText,
pager.Page,
pager.PageSize,
searchSettingsPart.FilterCulture,
searchSettingsPart.SearchIndex,
searchSettingsPart.GetSearchFields(searchSettingsPart.SearchIndex),
searchHit => searchHit);
var count = searchHits.TotalItemCount;
As far as the description of your ContentType goes, I think Orchard already provides all the necessary filters for a projection.
If you need something special you'd need to implement your own FilterProvider. The ContentTypesFilter is a good example on how to do this.

Solr/Lucene get the field in which the result is found

When I query multiple fields for a string, is it possible to retrieve information in which field the query term was found ?
I want to query description, information, additional information ... But then I need to know which field gave the result As I want to give different layouts.
Lucene way: look at IndexSearcher.explain(...). This will give an Explanation that describes how doc scored against query.
Solr way: add &debugQuery=true. I queried for collection:61 and got this document:
<doc>
<str name="collection">61</str>
...other fields...
<long name="uuid">1111</long>
</doc>
And then below comes this
<lst name="explain">
<str name="1111">
0.882217 = (MATCH) fieldWeight(collection:61 in 0), product of: 1.0 =
tf(termFreq(collection:61)=1) 0.882217 = idf(docFreq=8, maxDocs=8) 1.0 =
fieldNorm(field=collection, doc=0)
</str>
...
</lst>
Above basically tells that item 1111 had field collection with value 61. You can also request for debug.explain.structured to get this explanation string in a more structured format.

How can I write a SPQuery to filter items based on a LinkFieldValue?

I need to select a single value from a SharePoint list based on a field value. The type of the field is LinkFieldValue. How should I write the CAML query?
When I select the items with an empty query, I receive all the items in the list as expected.
When I add constraints to the query, it returns an empty result. I have tried constructing the query as follows:
string.Format("<Where><Eq><FieldRef Name=\"PollInstancePoll\" /><Value "
+"Type=\"Text\">{0}</Value></Eq></Where>",
new LinkFieldValue { NavigateUrl = "/az/Lists/Polls/DispForm.aspx?ID=1",
Text = "example poll" });
which results in the following query text:
<Where><Eq><FieldRef Name="PollInstancePoll" />
<Value Type="Text">example poll</Value>
</Eq></Where>
I have solved my problem with the following query:
new SPQuery
{
Query =
CAML.Where(
CAML.And(
CAML.Contains(
CAML.FieldRef("PollInstancePoll"),
CAML.Value(pollPath)),
CAML.Contains(
CAML.FieldRef("PollInstancePage"),
CAML.Value(pagePath))))
};
Essentially I am checking only the URL part of the Link field, and providing the value for comparison as Type="Text". It is important to remember that SharePoint stores the values in database always as server-relative URLs.

Resources