My parameters query:
q = (subject:zielone AND subject:aaaaa) OR subject:czerwone
hl=true
hl.fl=subject,description
First part query: (subject:zielone AND subject:aaaaa) return 0 results (it's ok)
Second part query: OR subject:czerwone return many documents (it's ok)
but when I look to highlight section, I have:
"4037903":{
"subject":["<em>zielone</em> <em>czerwone</em>"]},
"4040790":{
"subject":["<em>zielone</em> <em>czerwone</em>"]},
"4228003":{
"subject":["<em>zielone</em> <em>czerwone</em>"]},
I wants only the words highlighted have been found:
"4037903":{
"subject":["zielone <em>czerwone</em>"]},
"4040790":{
"subject":["zielone <em>czerwone</em>"]},
"4228003":{
"subject":["zielone <em>czerwone</em>"]},
How did it get?
The same problem (but no answer):
How to prevent solr from highlighting unmatched terms?
I think you can use the requireFieldMatch:
If true, then a field will only be highlighted if the query matched in
this particular field (normally, terms are highlighted in all
requested fields regardless of which field matched the query). This
only takes effect if "hl.usePhraseHighlighter" is "true".
The default value is "false".
To see all the highlighting parameters, you can go to the Solr documentation.
Check on the link for highlighting
https://wiki.apache.org/solr/HighlightingParameters#hl.requireFieldMatch
Related
I have a document which is
{'remaining': 'planet holly wood las vegas','id': 'c6d8e7e5-7ba9-4b68-ae0b-bb31ec4872f3'}
my query is remaining:(((mirage OR *holly* OR (planet AND hollywood)) AND (las AND vegas)) AND id:c6d8e7e5-7ba9-4b68-ae0b-bb31ec4872f3)
in the highlighting result:
{'c6d8e7e5-7ba9-4b68-ae0b-bb31ec4872f3': {'remaining': ['<em>planet</em> <em>holly</em> wood <em>las</em> <em>vegas</em>']}}
Why is planet being highlighted? I'm using solr 8.4
Thanks.
It's being highlighted because it's part of your query.
In general highlighting works across all the tokens being matched by the query, not just those giving a hit (and by default, a hit isn't even necessary in the field you're highlighting on - just that the token from the query is present in the highlighted value).
You can tweak this slightly by using hl.requireFieldMatch, but I'm not sure if that'll work with the optional clauses in your OR statement.
hl.requireFieldMatch
By default, false, all query terms will be highlighted for each field to be highlighted (hl.fl) no matter what fields the parsed query refer to. If set to true, only query terms aligning with the field being highlighted will in turn be highlighted.
The full list of highlighting options is available in the reference guide.
How can i highlight a specif term in a specif field?
For example, imagine the following query:
foo TITLE("bar")
, what i want to achieve is the highlight of foo in all fields and bar only in the field TITLE.
Until now the following has not worked:
q=<TITLE_field_internal_name>:"bar"hl.fl=&&hl.requireFieldMatch=true
Note: In the above example TITLE is re-mapped correctly to a solr field.
Most highlighting parameters supports the per-field parameter syntax:
f.TITLE.hl.<parameter>
Seeing as your syntax isn't valid Solr syntax and there is no way it'll know that TITLE("bar") refers to a field named TITLE, you'll have to extract that (or provide) that metadata yourself.
If you're querying different fields and only want to highlight the terms hit in those fields (i.e. if your query had been title:bar to only search for bar in the field title), you don't have to use per field settings, but can set hl.requireFieldMatch to true instead.
By default, false, all query terms will be highlighted for each field to be highlighted (hl.fl) no matter what fields the parsed query refer to. If set to true, only query terms aligning with the field being highlighted will in turn be highlighted.
Note: if the query references fields different from the field being highlighted and they have different text analysis, the query may not highlight query terms it should have and vice versa. The analysis used is that of the field being highlighted (hl.fl), not the query fields.
Finally, after much trial and error, i managed to have this thing working Here are a few snippets:
fq=(_query_:"{!edismax+qf%3D'container_title_en'+v%3D'hormones'}"+OR+_query_:"{!edismax+qf%3D$fqf+v%3D'cancer'}")
fqf=authors_tnss+etc+etc+...
hl.q=(_query_:"{!edismax+qf%3D'container_title_en'+v%3D'hormones'}"+OR+_query_:"{!edismax+qf%3D$fqf+v%3D'cancer'}")
hl.fl=id,external_id_s,etc,etc,...
hl.requireFieldMatch=true
, notice that if hl.fl fields are separated by , and in my custom fqf field in fq they are separated by +.
As I am trying to do highlighting in apache solar. I see it highlights even single words in lines. I want to highlight if all query matches. how can i set parameters for that?
I do not want to highlight single words in a query. Highlight only if all query matches in a line.
query - What is synchronization and why is it important
result
1) What is <em>synchronization</em> and why is it <em>important</em>?
2) What is typically the MOST <em>important</em> reason to use risk to drive testing efforts?
iIdon't want to highlight queries with single word match i want to highlight only those with exact match. so how can I configure highlight in solar.
and is there another way i can get field name for matched text.
Simple answer: All you need to know about configuring the Solr highlighter are in the Wiki.
Long answer: You should configure the hl.usePhraseHighlighter Parameter to true. Solr will highlight phrase queries accurately as phrases. Normally, the parts of the phrase will be highlighted everywhere instead of only when it forms the given phrase.
I am trying to query Solr with following requirement:
_ I would like to get all documents which not have a particular field
-exclusivity:[* TO *]
I would like to get all document which have this field and got the specific value
exclusivity:(None)
so when I am trying to query Solr 4 with:
fq=(-exclusivity:[* TO *]) OR exclusivity:(None)
I have only got results if the field exists in document and the value is None but results not contain results from first query !!
I cannot understand why it is not working
To explain your results, the query (-exclusivity:[* TO *]) will always get no results, because you haven't specified any result to retrieve. By default, Lucene doesn't retrieve any results, unless you tell it to get them. exclusivity:(None) isn't a limitation placed on the full result set, it is the key used to find the documents to retrieve. This differs from a database, which by default returns all records in a table, and allows you to limit the set.
(-exclusivity:[* TO *]) only specifies what NOT to get, but doesn't tell it to GET anything at all.
Solr has logic to handle Pure negative queries (I believe, in much the same way as below, by implicitly retrieving all documents first), but from what I gather, only as the top level query, and it does not handle queries like term1 OR -term2 documented here.
I believe with solr you should be able to use the query *:* to get all docs (though that would not be available in raw lucene), so you could use the query:
(*:* -exclusivity:[* TO *]) exclusivity:(None)
which would mean, get (all docs except those with a value in exclusivity) or docs where exclusivity = "None"
I have founded answer to this problem. I have made bad assumption how "-" works in solr.I though that
-exclusivity:[* TO *]
add everything without exclusivity field to the data set but it is not the case. The '-' could only exclude things from data set. BTW femtoRgon you are right but I am using it as fq (filter query) not as a master query I have forgotten to mention that.
So the solution is like
-exclusivity:([* TO *] AND -(None))
and full query looks like
/?q=*:*&fq=-exclusivity:([* TO *] AND -(None))
so that means I will get everything does not have field exclusivity or has this field and it is populated with value None.
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.