Suppose I have these fields in a document schema:
<field name="id" type="string" indexed="true" stored="true" multiValued="false" />
<field name="type" type="string" indexed="true" stored="true" multiValued="false" />
<field name="referenceDataValues" type="string" indexed="true" stored="true" multiValued="true" />
<field name="text" type="text" indexed="true" stored="false" multiValued="true" />
Document A has these values for the listed fields:
- id: "do not care"
- type: "SalesOrder"
- referenceDataValues: ["abcdefg" , "hijklmn", "opqrst"]
- text: ["do", "not", "care", "either"]
Document B has these values:
- id: "do not care"
- type: "SalesOrder"
- referenceDataValues: ["hijklmn", "opqrst"]
- text: ["red", "paint"]
Documen开发者_JAVA百科t C has these values:
- id: "abcdef"
- type: "Customer"
- referenceDataValues: (null)
- text: ["hello", "world", "how", "ya", "doing"]
Document D has these values:
- id: "hijklmn"
- type: "Customer"
- referenceDataValues: (null)
- text: ["hello", "world", "how", "ya", "doing"]
Default search is only on the text field.
If a user enters the query, "SalesOrder red paint Customer hello world", I want to construct a Solr query that returns only Document B. Meaning, get me the (SalesOrders whose text has red OR paint) who reference Customers whose text has hello OR world
The algorithm for reaching this would be like so:
First, the results of this query:
q="hello world"&fq=type:Customer&fl=id
which would be documents C and D, containing only the IDs. However, I want to actually get these values in each of the id fields, not the documents, so I can see if they exist in the referenceDataValues fields in the SalesOrders documents.
q="red paint"&fq=type:SalesOrder&fq=referenceDataValues:(nest here the id values from the previous query)
Is it possible to return the values of the ID fields in the first query? If yes, what would the syntax look like for this nested query?
Right now, the query I am attempting to use looks like this:
q=red paint&start=0&rows=25&fq=type:SalesOrder&fq=referenceDataValues:(_query_:"{!lucene fq=type:CustomerPartyMaster&fl=id} hello world")
What you are trying to achieve is a kind of join on the ids. The id of Document C and D is as a foreign key in the reference data values for Document A and B
You may want to check the join patch - https://issues.apache.org/jira/browse/SOLR-2272
If it doesn't work, you may end up indexing the documents and their reference data as a single entity, so that you can search across and filter accordingly.
Have you tried the FieldList parameter ??
You can specify which fields your query should return and then just do the second query where you filter by referenceDataValues:returnedID
But you need to test how it works (i am thinking about performance) when the result of the first query contains lots of IDs.
精彩评论