Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

database - How to return column that matched the query in Solr..?

I am using apache Solr for searching my database..!!

Suppose i have indexed 4 columns from one of my table..!!..I just want that only those columns that contains my query term are returned in response..!!..is that possible..??

For example :

I have a table cars with columns : name, displayName, description, extra ..!!

Now i make a query , something like :

localhost:8983/solr/select?q=maruti&wt=json

Now some in some rows only name may contain the word "maruti"

So, In return, i want only name (along with some other fixed fields like ID) ..

Similarly, If description contains this word, then only description should be returned..and not other columns..!!

How can i acheive this..??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You may be able to do this with Solr 4 and a custom transformer - my reading of the documentation would seem to indicate as much. But it would be quite a bit of work, I think. Ultimately you may have to write a front-end filter, but that would be difficult with complex queries.

Update: Here's how to do this in Solr without custom transformers, etc. Enable highlighting for all four columns:

hl=on&hl.fl=name,displayName,description,extra

Solr will return a "highlighting" structure containing the key and the field(s) that match the query. You will also get highlighted snippets, whether you use them is up to you. See here for additional params: http://wiki.apache.org/solr/HighlightingParameters


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...