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.
Related
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.
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
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.
I have a really large (5000+ characters) text field in SOLR named Description. So far it works great for searching and highlighting. If I perform a search and there are no highlighted portions then I just show the first 300 characters. What I would like to do is just return the 300 characters in the result from SOLR.
I would like to do this because when testing I get improved performance if I return a smaller result. This is probably because the XML doc is smaller so less time on the wire and then the processing is faster because the doc is smaller.
I have thought of using a new field that just stored the first 300 characters. I think this would work, but I was wondering if there was a better or more native solution.
What you're looking for is the highlighting hl.maxAlternateFieldLength (http://wiki.apache.org/solr/HighlightingParameters#hl.maxAlternateFieldLength).
You will need to define the field as its own alternate field. If you want to highlight the field Description, the highlight query parameters would be:
hl=true
hl.fl=Description
f.Description.hl.alternateField=Description
hl.maxAlternateFieldLength=300
Finally, to omit the Description field from the query result, you will have to exclude it from the fl query parameter:
fl=score,url,title,date,othermetadata
When using the Unified Highlighter, hl.alternateField is not available as a query parameter. Instead you can use the hl.defaultSummary query parameter (available since Solr 4.5)
hl.defaultSummary
If true, use the leading portion of the text as a snippet if a proper highlighted snippet can’t otherwise be generated. The default is false.