2013-04-08 152 views
0

enter image description here搜索結果SOLR Drupal的

嗨,

我有一個Drupal 7,Apache Solr實現集成模塊與Solr的附件模塊。我從未收到過此通知,但我很疑惑爲什麼搜索片段沒有顯示出來。看着通知中提到的代碼,並執行了print_r($ snippets),發現代碼片段在變量中並且沒有顯示在搜索結果中。這可能是什麼原因?

solrconfig.xml中

<requestHandler name="drupal" class="solr.SearchHandler" default="true"> 
<lst name="defaults"> 
    <str name="defType">dismax</str> 
    <str name="echoParams">explicit</str> 
    <bool name="omitHeader">true</bool> 
    <float name="tie">0.01</float> 
    <str name="pf"> 
     content^2.0 
    </str> 
    <int name="ps">15</int> 
    <!-- Abort any searches longer than 4 seconds --> 
    <!-- <int name="timeAllowed">4000</int> --> 
    <str name="mm">1</str> 
    <str name="q.alt">*:*</str> 

    <!-- example highlighter config, enable per-query with hl=true --> 
    <str name="hl">true</str> 
    <str name="hl.fl">content</str> 
    <int name="hl.snippets">1</int> 
    <str name="hl.mergeContiguous">true</str> 
    <!-- instructs Solr to return the field itself if no query terms are 
    found --> 
    <str name="f.content.hl.alternateField">teaser</str> 
    <str name="f.content.hl.maxAlternateFieldLength">256</str> 
    <!-- JS: I wasn't getting good results here... I'm turning off for now 
    because I was getting periods (.) by themselves at the beginning of 
    snippets and don't feel like debugging anymore. Without the regex is 
    faster too --> 
    <!--<str name="f.content.hl.fragmenter">regex</str>--> <!-- defined below --> 

    <!-- By default, don't spell check --> 
    <str name="spellcheck">false</str> 
    <!-- Defaults for the spell checker when used --> 
    <str name="spellcheck.onlyMorePopular">false</str> 
    <str name="spellcheck.extendedResults">false</str> 
    <!-- The number of suggestions to return --> 
    <str name="spellcheck.count">1</str> 
    </lst> 
    <arr name="last-components"> 
    <str>spellcheck</str> 
    </arr> 
</requestHandler> 

這是從通知的代碼這是在apachesolr_attachments.module

enter code here 
function theme_apachesolr_search_snippets__file($vars) { 
    $doc = $vars['doc']; 
    $snippets = $vars['snippets']; 
    $parent_entity_links = array(); 

    // Retrieve our parent entities. They have been saved as 
    // a small serialized entity 
foreach ($doc->zm_parent_entity as $parent_entity_encoded) { 
$parent_entity = (object) drupal_json_decode($parent_entity_encoded); 
$parent_entity_uri = entity_uri($parent_entity->entity_type, $parent_entity); 
$parent_entity_uri['options']['absolute'] = TRUE; 
$parent_label = entity_label($parent_entity->entity_type, $parent_entity); 
$parent_entity_links[] = l($parent_label, $parent_entity_uri['path'],  $parent_entity_uri['options']); 
} 

if (module_exists('file')) { 
    $file_type = t('!icon @filemime', array('@filemime' => $doc->ss_filemime, '!icon' => theme('file_icon', array('file' => (object) array('filemime' => $doc->ss_filemime))))); 
} 
else { 
    $file_type = t('@filemime', array('@filemime' => $doc->ss_filemime)); 
} 
//print_r($snippets);echo "\n"; 
return implode(' ... ', $snippets) . '<span>' . $file_type . ' <em>attached to:</em>' . implode(', ', $parent_entity_links) . '</span>'; 

}

schema.xml中

<field name="id" type="string" indexed="true" stored="true" required="true" /> 
<field name="name" type="string" stored="true" indexed="true"/> 
<!-- entity_id is the numeric object ID, e.g. Node ID, File ID --> 
<field name="entity_id" type="long" indexed="true" stored="true" /> 
<!-- entity_type is 'node', 'file', 'user', or some other Drupal object type --> 
<field name="entity_type" type="string" indexed="true" stored="true" /> 
<!-- bundle is a node type, or as appropriate for other entity types --> 
<field name="bundle" type="string" indexed="true" stored="true"/> 
<field name="bundle_name" type="string" indexed="true" stored="true"/> 
<field name="text" type="text" stored="true" indexed="true"/> 
<field name="site" type="string" indexed="true" stored="true"/> 
<field name="hash" type="string" indexed="true" stored="true"/> 
<field name="url" type="string" indexed="true" stored="true"/> 
<!-- label is the default field for a human-readable string for this entity (e.g. the title of a node) --> 
<field name="label" type="text" indexed="true" stored="true" termVectors="true" omitNorms="true"/> 
<!-- The string version of the title is used for sorting --> 
<copyField source="label" dest="sort_label"/> 
<!-- content is the default field for full text search - dump crap here --> 
<field name="content" type="text" indexed="true" stored="true" termVectors="true"/> 
<field name="content_type" type="string" indexed="true" stored="true" multiValued="true"/> 
<field name="teaser" type="text" indexed="false" stored="true"/> 
<field name="language" type="text_en" stored="true" indexed="true"/> 
<field name="path" type="string" indexed="true" stored="true"/> 
<field name="path_alias" type="text" indexed="true" stored="true" termVectors="true" omitNorms="true"/> 
<field name="created" type="string" indexed="true" stored="true" termVectors="true"/> 
<field name="Question" type="text" indexed="true" stored="true" termVectors="true"/> 
<field name="Response" type="text" indexed="true" stored="true" termVectors="true"/> 
<field name="Module" type="text" indexed="true" stored="true" termVectors="true"/> 
<field name="Meets" type="text" indexed="true" stored="true" termVectors="true"/> 
<field name="cat" type="string" indexed="true" stored="true" termVectors="true"/> 

任何建議通知以擺脫通知以及顯示片段?

回答

0

我將return implode(' ... ', $snippets)替換爲return implode(' ... ', $snippets['content']),它適用於我。

我不能保證不會出現問題。 無論如何值得一試。