Solr query with repeating parameter - solr

I try to "extend" one of the examples from the Solr Query Parsing presentation ( http://www.slideshare.net/erikhatcher/sa-22830939 ). I'd like to extend it in a way that I'm able to retrieve multiple solr documents at once with a querystring which http://.../solr/docs?id=1&id=2&id=3
The original configuration for the requestHandler looks like this:
<requestHandler name="/docs" class="solr.SearchHandler">
<lst name="defaults">
<str name="q">{!term f=id v=$id}</str>
</lst>
<arr name="components">
<str>query</str>
<str>highlight</str>
<str>debug</str>
</arr>
</requestHandler>
But this works only for a single id parameter ( http://.../solr/docs?id=1 ) - which query parser or configuration would I have to use to match it against multiple id parameters?
Thanks for your help.

Related

Can we give boost to fields through solr config file?

Every time we mention in query to give boost. Is it possible to mention boost for any field name in solr config itself ?
in the requestHandler config :
<requestHandler name="/select" class="solr.SearchHandler">
....
<lst name="appends">
<str name="qf">my_col^1</str>
<!--str name="qf">my_col^boost_val</str-->
<!--str name="bq">my_col2^boost_val</str-->
</lst>
....
It is possible to individually boost fields in Solr.
There is an additional parameter qf (Query Fields) which introduce list of fields, each of which is assigned a boost factor to increase or decrease that particular field's importance in the query.
Below is the sample solrconfig.
<requestHandler name="/select" class="solr.SearchHandler">
<lst name="defaults">
<str name="defType">dismax</str>
<str name="qf">title^10 content^5</str>
</lst>
</requestHandler>
In above qf assigns title field a boost of 10 and content a boost of 5.
NOTE :- The qf (Query Fields) Parameter can't be used with the standard query parser. You can use it with the dismax or edismax query parser.

How to get the file name of index Word documents in Apache Solr?

I used to upload and index Word documents using the following url..
java -Durl=http://localhost:8983/solr/update/extract?literal.id=1 -Dtype=application/word -jar post.jar microfost_det.doc
When I query the Solr Index it returns XML as ..
http://localhost:8983/solr/collection1/select?q=microfost&wt=xml&indent=true
The Response was :
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">0</int>
<lst name="params">
<str name="indent">true</str>
<str name="q">microfost</str>
<str name="_">1389196238897</str>
<str name="wt">xml</str>
</lst>
</lst>
<result name="response" numFound="1" start="0">
<doc>
<str name="id">1</str>
<date name="last_modified">1601-01-01T00:00:00Z</date>
<str name="author">fazlan </str>
<str name="author_s">fazlan </str>
<arr name="content_type">
<str>application/msword</str>
</arr>
<arr name="content">
<str>
This is a MSWord document. Microfost.
</str>
</arr>
<long name="_version_">1456677821213573120</long></doc>
</result>
</response>
Now my problem is , I need the name of the document that contains the queried text "microfost" that is , microfost_det.doc ..
Is it possible to get the name of the Word file (that is filename.doc) that contains the queried text ..
.
In Solr, the default searchable field is "content". That's why you are getting the result as it's matching with content. First create a custom string field (e.g docname) modifying your schema.xml
Then restart your Solr instance. Execute the following command to update your Solr doc.
curl 'http://localhost:8983/solr/update?commit=true' -H 'Content-type:application/json' -d '[{"id":"1","docname":{"set":"microfost_det.doc"}}]'
After that execute the following query and you'll get the result.
http://localhost:8983/solr/collection1/select?q=docname:microfost*&wt=xml&indent=true
Otherwise, while extracting the document execute the following command
java -Durl="http://localhost:8983/solr/update/extract?literal.id=1&literal.docname=microfost_det.doc" -Dtype=application/word -jar post.jar microfost_det.doc
Any way, you have to store the document name in a separate field.

Solr: Facet one field with two outputs

I'm using Solr for indexing products and organising them into several categories. Each document has a taxon_names multi value field, where the categories are stored as human readable strings for a product.
Now I want to fetch all the categories from Solr and display them with clickable links to the user, without hitting the database again. At index time, I get the permalinks for every category from the MySQL database, which is stored as a multi value field taxon_permalinks. For generating the links to the products, I need the human readable format of the category and its permalink (otherwise you would have such ugly URLs in your browser, when just using the plain human readable name of the category, e.g. %20 for space).
When I do a facet search with http://localhost:8982/solr/default/select?q=*%3A*&rows=0&wt=xml&facet=true&facet.field=taxon_names, I get a list of human readable taxons with its counts. Based on this list, I want to create the links, so that I don't have to hit the database again.
So, is it possible to retrieve the matching permalinks from Solr for the different categories? For example, I get a XML like this:
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">0</int>
</lst>
<result name="response" numFound="6580" start="0"/>
<lst name="facet_counts">
<lst name="facet_queries"/>
<lst name="facet_fields">
<lst name="taxon_names">
<int name="Books">2831</int>
<int name="Music">984</int>
...
</lst>
</result>
And inside the taxon_names array I would need the name of the permalink.
Maybe it's possible by defining a custom field type in the config XMLs. But for this, I don't have enough experience with Solr.
Since it appears from your description that you are faceting permalink in the taxon_permalink field and the values in that field should correspond to the same category names in the taxon_names field. Solr allows you to facet on multiple fields, so you can just facet on both fields and walk the two facet results grabbing the display name from the taxon_names facet values and the permalink from the taxon_permalink facet values.
Query:
http://localhost:8982/solr/default/selectq=*%3A*&rows=0&wt=xml
&facet=true&facet.field=taxon_names&facet.field=taxon_permalink
Your output should then look like similar to the following:
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">0</int>
</lst>
<result name="response" numFound="6580" start="0"/>
<lst name="facet_counts">
<lst name="facet_queries"/>
<lst name="facet_fields">
<lst name="taxon_names">
<int name="Books">2831</int>
<int name="Music">984</int>
...
</lst>
<lst name="taxon_permalink">
<int name="permalink1">2831</int>
<int name="permalink2">984</int>
...
</lst>
</result>

Solr More Like This (MLT) using a different unique identifier than the default one id

I m trying to use MLT but I have as unique identifier doc_id instead of id and if I do this :
http://localhost:8983/solr/mlt/?q=doc_id:question#11 I have no results
where If I do this
http://localhost:8983/solr/mlt/?q=id:11 I have results
<requestHandler name="/mlt" class="solr.MoreLikeThisHandler">
<lst name="defaults">
<str name="mlt.fl">title,text</str>
<str name="mlt.mintf">1</str>
<str name="mlt.mindf">2</str>
<str name="mlt.minwl">2</str>
<str name="mlt.boost">true</str>
<int name="rows">5</int>
<str name="fl">id,doc_id,title,content_type,user_id,topic_id,score</str>
</lst>
</requestHandler>
How can I use MLT with doc_id as my unique identifier ?
What you have looks fine. MLT just users the query to find a doc and if found use that doc for the source document. Are you sure a document is returned with the query "doc_id:question#11". Put the value in quotes and see if that get you the document back, ex. doc_id:"question#11". What is the datatype for doc_id?

Can I restrict the search to a specific date range?

I want to get all results AFTER a given date, can you do this with solr?
(http://lucene.apache.org/solr/)
Right now the results are search the entire result set, I want to filter for anything after a given date.
Update
This isn't working for me yet.
My returned doc:
trying:
http://www.example.com:8085/solr/select/?q=test&version=2.2&start=0&rows=10&indent=on&indexed_at:2009-08-27T13%3A15%3A27.73Z
<doc>
<str name="apptype">Forum</str>
<str name="collapse">forum:334</str>
<str name="content"> testing </str>
<str name="contentid">357</str>
<str name="createdby">some_user</str>
<str name="date">20090819</str>
<str name="dummy_id">1</str>
<int name="group">5</int>
<date name="indexed_at">2009-08-25T16:48:45.121Z</date>
<str name="rating">000.0</str>
<str name="rawcontent"><p>testing</p></str>
−
<arr name="roles">
<str>1</str>
<str>2</str>
<str>3</str>
<str>4</str>
<str>14</str>
<str>15</str>
<str>16</str>
</arr>
<int name="section">79</int>
<int name="thread">334</int>
<str name="title">testing</str>
<str name="titlesort">testing</str>
<str name="type">forum</str>
−
<str name="unique_id">
BLAHBLAH|357
</str>
<str name="url">/blahey/f/79/p/334/357.aspx#357</str>
<str name="user">21625</str>
<str name="username">some_user</str>
</doc>
Yes you can I assume you have a field with the date value you want to filter on. Then you do
yourdatefield:[2008-08-27T23:59:59.999Z TO *]
a sample url would be localhost:8983/solr/select?q=yourdatefield:[2008-08-27T23:59:59.999Z TO *]
you want to submit the date part as a query so in the value of q like
localhost:8983/solr/select/q=(text:test+AND+indexed_at:`[2009-08-27T13:A15:A27.73Z TO *`])
So the entire query is contained within the q querystring paramter.
the format of the date is ISO 8601.
You can add a automatic timestamp to the documents as they are indexed using:
<field name="timestamp" type="date" indexed="true" stored="true" default="NOW" multiValued="false"/>
in the schema.xml. The default schema has this commented out so if you copied the default, you just need to uncomment it.
You could add that and use olle's suggested search pattern to find the documents indexed after a certain date. (You'd have to update yourdatefield with timestamp or whatever you name the field in the xml.
You will need to create a query that compares dates, here is the syntax for queries:
http://wiki.apache.org/solr/SolrQuerySyntax
And here is how you can make date comparisons in the query:
http://lucene.apache.org/solr/api/org/apache/solr/util/DateMathParser.html

Resources