Retrieving specific fields in a Solr query? - lucene

I am running a Solr instance on Jetty and when I search using the Solr admin panel, it returns the entire document. What should I do to get only specified fields from each Solr document returned by the search?

/?q=query&fl=field1,field2,field3

From the Solr Admin home page, click on "Full Interface". On that page there is a box called "Fields to Return". You can list the you want here (comma-separated). "*" means all fields.

http://xx.xxx.xx.xx:8983/solr/corename/select?indent=on&q=*:*&wt=json&fl=ImageID,Imagepath,Category
This link has fl parameter:
fl is a field list, which will display the specified fields from the indexed list.

The best way is to run the query from Admin concole. When we run it, it also provides the actuall SQL query executed. Just copy the query and use it.
About the question: select specific fields from the table. In the admin console look for 'FL' text box. write the field names you want to retrieve, comma sapereted. Hit the 'Execute Query' button.
Top right side the SQL will be available.
Generated Query: ......select?fl=FIELDNAME&indent=on&q=:&wt=json

you can simply pass fl parameter with required fields name in your query.
&fl=field1,field2,field3&query=:
your response documents contains only mentioned fields.

Related

Apache Solr only return fields that value/query string was found in

I am just getting started with Apache Solr.
I have successfully run through the Apache tutorials and have now created my own collection and indexed my files.
Whilst the documentation is extensive I cannot find if there is a way to query all fields, but only return the fields that the search string/query was found in.
For example, if I have a file:
Filename: Weekly Report For Company X.pdf
Associated / indexed meta-data:
"id":"S:\\Weekly Reports\\JAN\\Weekly Report For Company X.PDF",
"date":["2017-11-02T19:14:07Z"],
"pdf_pdfversion":[1.6],
"company":["Microsoft"],
"access_permission_can_print_degraded":[true],
"subject":["weekly report; reports; weekly"],
"contenttypeid":["0x010100F29081EC69D67544A17D8172A093E42E"],
"dc_format":["application/pdf; version=1.6"],
If I query for "Weekly Report" I only want to return the 'id' and 'subject' fields as these are the only fields that contain the actual queried values. If other fields contained the string, I would want them returned too.
I'm leaning towards 'it cannot be done' (but hope I am wrong) as I liken it to a SQL query. It has to know what fields to return in the SQL statement and does not remove fields based on no matching string.
Since I don't know the matched fields before running the query I cannot use the filter list option at the point of executing the query.
Is this possible?
While this may be not precisely what you want, but you could mimic similar behaviour with highlighting.
All you need to do - is to create dismax query with qf being all fields that you have (e.g qf=id,subject,company)
Then you need to request highlighting, request all fields for it (hl.fl=id,subject,company) and enable hl.requireFieldMatch which would force Solr to return only fields which were matched for the query.
In this case you will have a highlighting section, that will contain ids of the matched documents and only highlighted contents of matched fields

Showing more feature attributes in Solr Highlight

How can I get more feature fields from Solr highlight output?
Currently the Highlight just returns the text snippet and docID.
During the indexing step I indexed the feature alongside with other fields I'd like to get back.
Thank you in advance!
You can specify other fields to return highlighting on using the hl.fl parameter. For multiple extra fields, just use that field repeatedly. For example, if you want to highlight in the fields author and title, you would append
&hl.fl=author&hl.fl=title
to your Solr query. Take a look at the linked page for other highlighting options.

How to avoid retrieve entire stored field from solr

I'm using sunspot and solr for a rails app to search ebook contens, for highlight feature I have to set the ebook_content as a stored filed, every time I queried solr for result, it sends back the entire document content about the book, which makes the query very slow.
How could I only get the result without the stored field?
The fl parameter of Solr allows you to specify which fields you want returned in the result. If you had fields id, title, ebook_content, then you could use fl=id,title to omit the ebook_content field. I don't think there's support in Solr for getting all fields except one (e.g. -ebook_content).
Update
If you don't want to return the field in the normal results, but still want highlighting on that field, exclude the field as I described above, then turn on the highlighter:
hl=true
set the field(s) which should be highlighted:
hl.fl=ebook_content
and set the size of the highlighting fragment (in characters):
hl.fragsize=50
your finished query looks something like this:
?q=search term&fl=id,title&hl=true&hl.fl=ebook_content&hl.fragsize=50

How to display search results in a new form

I've created a system and within that system i've a find/search page and a find/search results page. Basically, the find/search page consists of a number of text fields and the more the user completes, the more efficient the search will be.
I'm using SQL server 2005 to store the data and I can easily update/insert/save new data but I don't know how to search for the data ...
I want the user to fill out the fields in the find/search form and for the results to appear in the find/search results page. Can this be done?
It depends on what kind of Data you need to search.
If it's generic text data the best way is to use Full-Text Search
Yes. There are a number of ways you could achieve this. One possible way would be to pass the search criteria to the search results page via query string. Another way which is very similar is to store the search criteria in a session and redirect to the search results page. In either case on the search results page you'd want to take the data and build your SQL query. Depending on what you need you could utilize a full-text search like Kesty has suggested or you could simply use FIELD like '%user entered data%' in your queries. It really depends on your needs.

Filters in Lucene

Friends,
I am new to lucene full text search. i have developed page with full text seach. it works fine till. but now i want to add extra condition like where clause. how to do it.
The requirement given for me is, i have to list proposal which is created by logged in user. I have to add this condition in back end without user knowledge.
I heard about filter. Which filter is correct?how to apply that.Give me an sample. this evening i have demo. help me.
First, you need to ensure that the user id is being added to the document in the index in a field when you index, let's call it user_id.
In a pinch, you can add a field to the query string entered by the user behind the scenes before you send it to the query parser. So, take whatever query was entered and add " AND user_id:4" (where 4 is the value of the variable containing the current user id) onto the end of it.