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.
Related
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']")
I am using solr to get results based on the search text entered by the user.
I want to order the results based on proximity to the calories field of the document as shown below.
I have used Range (calories:[0 TO 300]) however that doesnt fulfill my needs.
{
"food_group":"Proteins",
"carbs":"6.295",
"protein":"13.729",
"fat":"2.551",
"calories":103.0
}
For example if user enters 100 as calories i want to show the document with 101 before the document with 97 and so on...(There is no sorting logic in this)
You can use abs(sub(user_calories, calories)) function as sort
Example for user input 100 :
q = "calories:[0 TO 300]",
sort = "abs(sub(100,calories)) asc"
Example Url :
http://127.0.0.1:8983/solr/test/select?q=calories%3A%5B0+TO+300%5D&sort=abs(sub(100%2Ccalories))+asc
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");
I have incoming queries and I want to only search in certains fields (author, book title) not in field (book content). How can I achieve this in Lucene?
another questions is that if how can I give a higher rank to documents that have matches in the author field. For example, doc1 have match in "book content", and doc2 has match in "author", how can I rank higher for doc2
You can combine multiple queries using BooleanQuery, and have Occur.Should (meaning OR). I also believe that you can boost specific queries in such a scenario, which means that matches in a specific field has higher relevance that for instance, content.
Example (C#):
var query = new BooleanQuery();
query.Add(new TermQuery("author", searchTerm), Occur.Should);
query.Add(new TermQuery("book title", searchTerm), OCcur.Should);
I have documents like this in my CouchDB:
{
"_id": "0cb35be3cc73d6859c303fa3200011d2",
"_rev": "1-f6e356bbf6ab09290aae11132af50d66",
"adresse": "Bohrgaß 10 /",
"plz": 56814,
"ort": "Faid /",
"kw": 2.32,
"traeger": "SOL"
...
}
There are predefined categories for certain attributes e.g. traeger: "SOL", "BIO", "WAS"; kw: <2, 2-5, 5-20, 20-100; plz: 56814, plz: 56815; ...
I have to be able to efficiently query the total number of docs for every category and
the total number of docs and the docs itself under certain conditions. E.g.
How many docs are in the category kw <2 (and all other kw categories) under the condition traeger = "SOL"
How many docs are in the category traeger = "SOL" (and all other traeger categories) under the conditions plz=56814 AND kw < 2
The user can select which catagories he likes to combine. The categories are fix. There also will be more attributes and catagories.
How would map/ reduce functions for this look like?
Marcel
Since you are going to count documents, your reduce function is simply the built-in count. Your map function needs to emit the appropriate keys your users are going to search for. Finally, when the view is queried, the appropriate group level has to be picked.
Example: You can create a view with a composite key ["traeger", "kw"]. If you query that view with group_level = 2, you get the number of documents for each combination of traeger and kw.
If you only care about the traeger "SOL", you can restrict the output with the start_key and end_key parameters.
If you want to know the number of documents in each "traeger" category no matter their "kw", you can query that view with group_level 1.
For your second example, you can create a view with the key ["plz","kw","traeger"] and query it using start_key and end_key to restrict the results to plz=56814 AND kw < 2 and set group_level to 3.
Querying options for views are listed here:
http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options