Posted by karma.code on September 24, 2010 at 6:02pm
Hey all,
A wildcard question... I am trying to do an autocomplete text field implementation of SOLR. So, when the user starts typing in a term or a phrase, it will request SOLR results. For example, if a person types in 'car' it should return 'car', 'cars', 'cardigan'.
Now I try doing this:
<?php
function apachesolr_modify_query(){
$query->add_filter('fieldname', $value.'*');
}
?>but no partial term results come back to me. Now I've heard that the DisMax could help but I cannot find any good documentation on this. Can you please lead me to this. Thank you.

Comments
Check out the
Check out the apachesolr_autocomplete module. Either it will already do what you want, or you can use it as a reference implementation: http://drupal.org/project/apachesolr_autocomplete
Drupal issues
You can also review issue on d.o regarding partial search http://drupal.org/node/270412
Another approach is to enable edismax search handler and do queries with wildcards. See http://drupal.org/node/713142
I looked at
I looked at apachesolr_autocomplete first but it only returns facets. I want it to return searches on terms and phrases. I'll take a look at the two issues above though.
What I did
One of my colleagues figured this one out and I wanted to share the solution:
<?php
// Query Solr for $keys so that suggestions will always return results.
$query = apachesolr_drupal_query($keys);
// Allow other modules to modify query.
apachesolr_modify_query($query, $params, 'solr_ui_autocomplete');
if (!$query) {
return array();
}
// Try to contact Solr.
try {
// coming from apachesolr.module
$solr = apachesolr_get_solr();
}
catch (Exception $e) {
watchdog('Apache Solr', $e->getMessage(), NULL, WATCHDOG_ERROR);
return array();
}
// Query Solr and set the wildcard for SOLR
$params['qt'] = 'standard';
$params['defType'] = 'lucene';
$wildcard = "*";
// strip out all the usual crap
$keys = str_replace(array(':', '/'), '', $keys);
$keys = 'title:'.strtolower($keys);
$response = $solr->search($keys.$wildcard, $params['start'], $params['rows'], $params);
?>
Changing the params['qt'] to standard and defType to lucene was the critical part of this solution. Thanks to all who tried.
A better solution as
A better solution as suggested above is to backport the edismax handler from Solr 3.1 to Solr 1.4 and recompile Solr - there are instructions at: http://drupal.org/node/713142
Your solution will not work as you expect, since only the default field will be searched, and the query-time boosts will not work.