The ExternalFileField field type is very useful for things like rankings since the rankings can be updated at different intervals than the documents they are associated with without having to reindex those documents.
For an example use case, let's say we implement Facebook-style "like" functionality using the Flag module and want to adjust the relevancy based on how many people "liked" a piece of content. Without using ExternalFileField, we would have to create an index field for the flag count and reindex the entire document every time somebody liked it causing a lot of unnecessary updates to the search index. Using ExternalFileField, we could occasionally regenerate a flat file with the document id / like count mappings without having to reindex any documents.
Developers will have to generate the flat files themselves in order to utilize external file fields in their Drupal application, however the out-of-the-box schema should support this type as there is no apparent drawback if the field is not used.
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | support-1586320-18.patch | 6.45 KB | killua99 |
| #18 | support-1586320-18.patch | 6.45 KB | killua99 |
| #9 | 1586320-9.patch | 1.55 KB | pwolanin |
| #1 | external-file-field-1586320-1.patch | 1.63 KB | cpliakas |
Comments
Comment #1
cpliakas commentedAttached is the patch that adds the ExternalFileField field to the schema.xml file. The dynamic field is prefixed with "eff_". A simple example of how this works is illustrated below.
Let's say we wanted to add additional boosts to a few nodes. We could add a flat file to Solr's data directory named
external_eff_ranking, which follows the external_{field_name} nomenclature Solr expects. It would contain the following data, replacing {site_id} with the site's apachesolr_site_hash():In a custom module, we could boost the respective nodes by these values by implementing the following code:
The results will then rank node 2 higher than node 3, and node 3 higher than node 1. This is a very simple example, but in the case of the Facebook-style "like" counts mentioned in the original post, we could either do the normalizing math when generating the flat file or leverage solr's function queries to convert the raw counts to a boost that makes sense when calculating the relevancy.
Comment #2
cpliakas commentedChanging component and status accordingly.
Comment #2.0
cpliakas commentedUpdated issue summary.
Comment #2.1
cpliakas commentedUpdated issue summary.
Comment #3
nick_vhThat's a very edgy case actually. How will drupal benefit from this if most sites are not able to create this text file and send it to the righteous solr core?
Do you have a usecase that actually used this? Aren't boost fields more dynamic? I don't have anything against schema changes but I'm doubting if this one is really one that will be correctly used?
Comment #4
cpliakas commentedI would say this is an edge case right now for the Drupal community, however it is far from an edge case in the Solr community and is the accepted method of boosting by user generated ranking data (i.e. voting, thumbs up, this is helpful, etc.) for larger datasets. This assertion is based on presentations delivered by Lucid Imagination and others at Lucene / Solr conferences. Below are a few worth highlighting:
Sure you could do this on the client side, but let's say you are a news site has 50k articles and you want to boost based on Radioactivity and a "thumbs up" count provided by the Flag module. Every time someone clicks on a flag or does something that effects radioactivity like view a page, it would trigger the effected node being re-queued for indexing. This adds a ton of processing on the Drupal side during cron runs and produces a lot of unnecessary updates. Using the ExternalFileField technique, all you would have to do is regenerate the file every so often, i.e. 5 or 10 minutes, so that the ranking data could be up to date without having to reindex a ton of documents. It would be great to have the option to do the client side thing for smaller sites, but at least allow for using this benefit of Solr for larger sites.
To me, it would be an arbitrary limitation to prevent this just because the solution isn't 100% contained to Drupal. There is no drawback of exposing this field, and most people won't even know that this change has been made. However, at least opening up the door for the possibility of leveraging techniques that others in the Solr community are implementing could facilitate some interesting innovations for Drupal + Solr.
As an example, there are a lot of companies that offer hosted Solr solutions targeted specifically towards Drupal such as Acquia Search, Pantheon, A12 Search, Midwestern Mac, DrupalCONCEPT, and others (sorry for leaving anyone off the list). One of the value-added benefits they could provide beyond just hosting a Solr instance would be to offer these rank boosting as a service based on this technique. How cool would it be for people using these services to say "Boost documents based on relevancy X, Y, and Z refreshing every X minutes" without having to tax the Drupal site and Solr server with excessive updates? There could be a common module that collects the data generically, and then has a pluggable connection piece to make an API call to the service or take some action that reflects the change. Anyways, just some ideas here, but they are only possible if the EmbeddedFileField door is open.
Comment #5
pwolanin commentedLooks good to me to add support for this field type - I can even imagine implementing a click-boosting approach that for small sites does mark the docs for re-index at some interval (e.g. hourly) and puts the boost directly in a field, or even easier (perhaps) applies a document-level boost so the query doesn't need to be altered at all.
Comment #6
pwolanin commentedtaking a look at the javadoc: http://lucene.apache.org/solr/api/org/apache/solr/schema/ExternalFileFie...
in 3.6 at least valType isn't needed - do 3.4 and 3.5 barf without it?
Also what's the pfloat type? Looks like you could use tfloat without adding that?
Comment #7
cpliakas commentedTotally agree. I think that the logic could be reused, but for larger sites using the external file filed is at least an option so that your side can leverage the same code but provide more real-time boosting.
Hm, maybe. Let me try it out. My experience is that yes, Solr barfs hard when valType isn't defined. I can validate this further though. Marking as needs work based I these two items.
Comment #8
pwolanin commentedDespite what the javadoc says, it fails with tfloat with Solr 3.5.
Comment #9
pwolanin commentedThis is basically the same as the patch above, but puts the file field in the group of Solr 3.4+ fields
Comment #10
cpliakas commentedNice. I effectively played around with different configurations until I found the "magic" combination. I found the
<fieldType name="pfloat" class="solr.FloatField" omitNorms="true"/>technique in a support forum somewhere.Comment #11
pwolanin commentedYes, the stack trace indicated it had to be a solr.FloatField
Comment #12
cpliakas commentedHm, accidental change of status to "needs work" in #10. Ignore that.
Comment #13
nick_vhComment #14
nick_vhCommitted to D7
Comment #15
cpliakas commentedWoo-hoo! Thanks, Nick. I foresee some really cool things coming from this. Can't wait to start playing around with solutions.
Comment #16
nick_vhAnd now a solution so Drupal can send this file to the solr index dir and we'd all be happy!
I hope solr really supports the posting of these files soon, so we can elevate stuff from in the module, add boosts to this external document field type. Maybe in Solr 4.0
Until then, I doubt that this feature will see many use cases but I hope you prove me wrong ;-)
Because it is tricky to always copy the file to the correct location.
Comment #17
mstiHi!
Sorry for the offtopic, but could not find any information anywhere else.
I have used cpliakas example to boost the results returned from solr using radioactivity. This works perfect.
The problem is that solr does not pick up the new boost parameters from the external_ file. I found out that I need to commit the changes back to solr but have not figured out how. I tried something like curl http://localhost:8983/solr/update?commit=true but did not work.
Any ideas?
Thanks,
Mike
Comment #18
killua99 commentedNeed review 6.x-3.x
Comment #19
killua99 commented:/ forgot change the status sorry about it
Comment #20
nick_vhSeems that your patch is grouped with another patch
Committed only the schema changes, please pay attention next time ;-)
Comment #21
nick_vhComment #21.0
nick_vhUpdated issue summary.