I need to make a solr query through url and I do:
Query has to be
name:john AND id:5
Filter Query
byr:75 OR byr:90
I tried doesn't seem to work
url.....?q=name:john+id:5&fq=(byr:75 OR byr:90)
I know that AND is + but what is the symbol for OR? Couldn't find much online so seeking help here
+ is not the symbol for AND - it means that the clause is required for the document to be considered a match. And in this case, it seems to only be the escape code for a space in the URL.
Use " AND " if both clauses are required (the default behavior is affected by q.op and mm if you're using dismax).
fq=byr:(75 90) will give you a search against byr field with two possible values. This is sort of described right at the end of the Standard Query Parser documentation.
I would recommend reading that whole article. And don't confuse + sign used in the query and + used in URL to escape special characters.
Related
All:
I am new to Solr, when I play with solr example with importing some random document, I use a search query in q like:
fund+report
There is no space between fund and +, and I thought it will search a word "fund+report" in the document, which rarely happen in document, but a lot results return, thequery url is:
http://localhost:8983/solr/collection1/select?q=fund%2Breport&fl=id+filename+%5Bexplain%5D&wt=xml&indent=true
I thought Solr treat my query just like:
fund report
or
fund OR report
Could anyone tell me why solr treat my query like that? And how can I make solr treat fund+report as a single word?
Thanks
The HTTP call will simply translate the + to a space . If you need an actual + sign then you need to use the URL-encoded value for + (which I think is %2B). If you are looking for the phrase fund report then you want to put double quotes around the phrase, e.g., "fund report". These should also be URL-encoded (I think the value for that is %22).
Keep in mind that if you're using stemming then a search for "fund report" will find results for "funds reports", "funding reports", etc. But maybe that is what you want.
So after all is said and done, your URL might look like the following:
http://localhost:8983/solr/collection1/select?q=%22fund%20report%22&fl=id,filename,%5Bexplain%5D&wt=xml&indent=true
Note that the fields listed for the fl parameter should be comma-delimited. I am not sure why you have the square brackets around the explain field.
I wish to query a Lucene index and ask the question "..does the string ABC occur in Field A AND string DEF in Field B ..."
BOTH conditions (ABC in Field A and DEF in Field B) must be true ....I've fooled around
with a few searches and don't seem to be hit the proper combination.
Any ideas / examples ...seems that the MultiFieldQueryParser may be the answer but I've had no luck so far.
The standard query parser supports this sort of query, like:
+fielda:ABC +fieldb:DEF
The + character is the required operator, so this query will require a match on both fielda:ABC and fieldb:XYZ.
See the query parser syntax documentation, for more information.
MultiFieldQueryParser is used to automatically search for the same content in multiple fields, so not quite what you are looking for.
Turns out on a SOLR browser search, the q.OP=AND on the URL will provide the ANDING condition I was looking for.
I'm a newbie to solr.
Here is my problem:
When I search 天天爱消除,my tokenizer will split it to: 天天 & 爱 & 消除.
I use disMax mode, and the query goes like this:
http://search.dev/solr/collection1/select?q=%E7%88%B1%E6%B6%88%E9%99%A4&defType=dismax&qf=name&wt=json&indent=true&omitHeader=true&rows=500&hl=true&hl.fl=name&hl.simple.pre=<em>&hl.simple.post=<%2Fem>&sort=score+desc
This would match results like this: 我爱记单词 & 我爱读书. For me, the relevances of them are to low, so I don't want to show them in the results.
In conclusion, I want to ditch the results that match one term and the term length is 1;
Hope to get some help. Thanks.
update:
Need I to set a custom Collector?
If you are talking about having at least 2 term matches from your query , I do not think you need a special collector for this.
You need to use &mm=2 with the rest of your URL/query, here is the documentation with example => http://wiki.apache.org/solr/DisMaxQParserPlugin
Is there any way I can user a NOT or other negation operator before a text search keyword for example,
NOT program
When I do such a search there are 0 records returned.
Please let me know some way to achieve this option.
In Solr you can use the '-' minus sign as a NOT operator, so you would change your query to be
*:* - program
If you are using SolrNet, since that is how your question is tagged, you can do the following
solr.Query(new SolrQuery("*:*") && !new SolrQuery("program"));
Please see Querying in SolrNet for more details.
Updated: Per comment from Mauricio Scheffer
There aren't any search operators that perform the search parameters you are describing. My advice is to use the Google advanced search features. You can make your search much more specific in a number of ways, its really advanced.
Solr newbie here.
I have created a Solr index and write a whole bunch of docs into it. I can see
from the Solr admin page that the docs exist and the schema is fine as well.
But when I perform a search using a test keyword I do not get any results back.
On entering * : *
into the query (in Solr admin page) I get all the results.
However, when I enter any other query (e.g. a term or phrase) I get no results.
I have verified that the field being queried is Indexed and contains the values I am searching for.
So I am confused what I am doing wrong.
Probably you don't have a <defaultSearchField> correctly set up. See this question.
Another possibility: your field is of type string instead of text. String fields, in contrast to text fields, are not analyzed, but stored and indexed verbatim.
I had the same issue with a new setup of Solr 8. The accepted answer is not valid anymore, because the <defaultSearchField> configuration will be deprecated.
As I found no answer to why Solr does not return results from any fields despite being indexed, I consulted the query documentation. What I found is the DisMax query parser:
The DisMax query parser is designed to process simple phrases (without complex syntax) entered by users and to search for individual terms across several fields using different weighting (boosts) based on the significance of each field. Additional options enable users to influence the score based on rules specific to each use case (independent of user input).
In contrast, the default Lucene parser only speaks about searching one field. So I gave DisMax a try and it worked very well!
Query example:
http://localhost:8983/solr/techproducts/select?defType=dismax&q=video
You can also specify which fields to search exactly to prevent unwanted side effects. Multiple fields are separated by spaces which translate to + in URLs:
http://localhost:8983/solr/techproducts/select?defType=dismax&q=video&qf=features+text
Last but not least, give the fields a weight:
http://localhost:8983/solr/techproducts/select?defType=dismax&q=video&qf=features^20.0+text^0.3
If you are using pysolr like I do, you can add those parameters to your search request like this:
results = solr.search('search term', **{
'defType': 'dismax',
'qf': 'features text'
})
In my case the problem was the format of the query. It seems that my setup, by default, was looking and an exact match to the entire value of the field. So, in order to get results if I was searching for the sit I had to query *sit*, i.e. use wildcards to get the expected result.
With solr 4, I had to solve this as per Mauricio's answer by defining type="text_en" to the field.
With solr 6, use text_general.