The "freq" psuedo-field you are seeing in your example query is coming from a DocTransformer that is decorating the documents as part of the QueryResponseWriter phase -- this is happening much later then any of the SearchComponents that are executed.
If you wnat the same information in a SearchComponent you need to execute the underlying functionality yourself using the docid (no need to fetch the Document from the Searcher). You could either construct & use an instance of TermFreqValueSource class as is, and ask it for each docid in your DocList, or you could peek under the covers and just take the bits of TermFreqValueSource that you need and use them directly in your custom class. In general though: i'm not sure that the effort you are looking at is really worth the payoff of doing this logic in a SearchCOmponent -- you're only going ot be getting the sum of the the termfreq for the N documents included in teh response (ie: the rows param) which would be even easier to sum up in your client code as it would be on the server side. : Date: Mon, 15 Jul 2013 16:01:57 +0500 : From: Tony Mullins <[email protected]> : Reply-To: [email protected] : To: [email protected] : Subject: FunctionQuery result field in SearchComponent code ? : : Hi , : : I have written my custom Solr 4.3.0 SearchComponent and purpose of this : component is to sum the result of FunctionQuery (termfreq) of some term of : each doc and them embed the result in final output. : : This is my query: : : http://localhost:8080/solr/collection2/demoendpoint?q=spider&wt=xml&indent=true&fl=*,freq:termfreq%28product,%27spider%27%29 : : This is sample result doc on browser: : : <doc><str name="id">11</str><str name="type">Video Games</str><str : name="format">xbox 360</str><str name="product">The Amazing : Spider-Man</str><int name="popularity">11</int><long : name="_version_">1439994081345273856</long><int name="freq">1</int></doc> : : : Here is my code from SearchComponent : : DocList docs = rb.getResults().docList; : DocIterator iterator = docs.iterator(); : int sumFreq = 0; : String id = null; : : for (int i = 0; i < docs.size(); i++) { : try { : int docId = iterator.nextDoc(); : : // Document doc = searcher.doc(docId, fieldSet); : Document doc = searcher.doc(docId); : : In 'doc' object I can see the schema fields like 'id', 'type','format' etc. : but I cannot find the field 'freq' which I needed. : : Is there any way to get the FunctionQuery fields in doc object ? : : Thanks, : Tony : -Hoss --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
