Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...