2016-10-04 14 views
6

मैं अपनी साइट खोज को लागू करने के लिए अपाचे सोलर सर्च इंजन का उपयोग कर रहा हूं। मैं Apache Solr Search मॉड्यूल स्थापित करने में सक्षम हूं और अब मेरी खोज काम कर रही है जैसा कि मुझे चाहिए। अब मैं Apache Solr Autocomplete मॉड्यूल की मदद से एक खोज स्वत: पूर्ण करने की कोशिश कर रहा हूं, लेकिन बात यह है कि मैं कीवर्ड के बजाय सुझाव सूची के रूप में नोड शीर्षक दिखाने की कोशिश कर रहा हूं। अंत में मुझे यह tutorial मिला और मैंने कोशिश की, मुझे लगता है कि काम कर रहा है लेकिन अब मैं एक AJAX HTTP त्रुटि (500) से फंस गया हूं। और मैं अपने Drupal त्रुटि लॉग में 4 त्रुटि संदेश मिला: -अपाचे सोलर खोज स्वत: पूर्ण

Notice: Undefined index: facet.prefix in apachesolr_autocomplete_suggest() (line 461 of /home/test/webroot/sites/all/modules/apachesolr_autocomplete/apachesolr_autocomplete.module). 

Warning: Invalid argument supplied for foreach() in apachesolr_autocomplete_suggest() (line 470 of /home/test/webroot/sites/all/modules/apachesolr_autocomplete/apachesolr_autocomplete.module). 

Notice: Trying to get property of non-object in apachesolr_autocomplete_suggest() (line 470 of /home/test/webroot/sites/all/modules/apachesolr_autocomplete/apachesolr_autocomplete.module). 

Notice: Undefined property: stdClass::$payslip in apachesolr_autocomplete_suggest() (line 469 of /home/test/webroot/sites/all/modules/apachesolr_autocomplete/apachesolr_autocomplete.module). 

मुझे लगता है कि इस ट्यूटोरियल लगभग काम हम की तलाश कर रही है, दुर्भाग्य से वे अब समर्थन या टिप्पणी के लिए किसी भी प्रतिक्रिया प्रदान करते हैं। क्या कोई इस शांत कार्यक्षमता को लागू करने का तरीका समझने में सक्षम है? यहां तक ​​कि यदि कोई लाइसेंस संस्करण के साथ आता है, तो भी मुझे ख़ुशी मिलती है। धन्यवाद दोस्तों।

यह वर्तमान अपाचे सोलर स्वत: पूर्ण दिखता है (नीचे छवि), इस सुझाव सूची में वे खोज अनुक्रमणिका से खोज कीवर्ड सूचीबद्ध करते हैं। मैं जो करने की कोशिश कर रहा हूं वह इस सुझाव सूची में नोड शीर्षक सूचीबद्ध कर रहा है।

enter image description here

+0

मॉड्यूल किस संस्करण का उपयोग कर रहे हैं? क्या आपने मॉड्यूल संपादित किया था? अंतिम संस्करण में, लाइन 461 एक परिवर्तनीय असाइनमेंट ($ संदर्भ) से मेल खाती है। – EricLavault

+0

मैं 'अपाचे सोलर सर्च 7.x-1.8, अपाचे सोलर ऑटोकंपलेट 7.x-1.6, सोलर-4.5.1' का उपयोग कर रहा हूं। ट्यूटोरियल के अनुसार मैं अपने अनुकूलित एक के साथ 'function apachesolr_autocomplete_suggest() 'को प्रतिस्थापित करता हूं। – nanbatman

+0

मैंने अभी देखा है कि यह बदसूरत ओवरराइड है और मैं इस ट्यूटोरियल की अनुशंसा नहीं करता। इसके अलावा * लेबल_autocomplete * फ़ील्ड 'संग्रहित = सत्य' है, फ़ील्ड का वास्तविक मान क्वेरी द्वारा पुनर्प्राप्त किया जा सकता है ताकि लेखक को संरक्षित और निचले स्तर वाले शीर्षक को फ़ील्ड में कम करने के बजाय लोअरकेस फ़िल्टर के साथ चिपकना चाहिए। – EricLavault

उत्तर

5

यह सिर्फ एक चाल, नहीं नहीं सही तरीका है, लेकिन आप कोशिश कर सकते हैं।

सबसे पहले आपको सोलर क्वेरी कैप्चर करना चाहिए, जिसे आपने खोजते समय निष्पादित किया था।

मैं क्वेरी को पकड़ने के लिए सौर स्तर मॉड्यूल का उपयोग करता हूं। फिर हुक के साथ अपना खुद का मॉड्यूल बनाएं।

/** 
* Implements hook_menu(). 
*/ 

function mymodule_menu() { 
    $items = array(); 

    //create a call back for autocomplete search box 
    $items['searchauto/autocomplete'] = array(
    'page callback' => 'mymodule_search_autocomplete', 
    //'access arguments' => array('access search autocomplete'), 
    'type' => MENU_CALLBACK, 
    'access arguments' => array('access content'), 
); 

    return $items; 
} 
/** 

* hook_form_FORM_ID_alter 
* solr search form text box autocomplete 
**/ 
function mymodule_form_search_block_form_alter(&$form, &$form_state, $form_id) { 

    $form['search_block_form'] = array(
    '#type' => 'textfield', 
    '#autocomplete_path' => 'searchauto/autocomplete', 
); 
} 
/** 
a* call back function for autocomplete 
**/ 
function mymodule_search_autocomplete($string) { 

    unset($results); 
    $results = array(); 
    $matches = array(); 

    //replace the space with %20 
    $key = preg_replace('/[[:space:]]+/', '%20', $string); 
    //number of results you want to show 
    $num_result = 15; 
    //your Solr server path 
    $solr_server = "http://locathost/solr"; 

//this is the trick. first you should capture the Solr query, which executed when you hit search. I use the Solr level module to catch the query. you can change parameters if you want, I'm only changing the search keyword and number of results 
$request_url = $solr_server."/select?start=0&rows=$num_result&&spellcheck=true&q=$key&fl=id%2Centity_id%2Centity_type%2Cbundle%2Cbundle_name%2Clabel%2Css_language%2Cis_comment_count%2Cds_created%2Cds_changed%2Cscore%2Cpath%2Curl%2Cis_uid%2Ctos_name%2Czm_parent_entity%2Css_filemime%2Css_file_entity_title%2Css_file_entity_url&mm=1&pf=content%5E2.0&ps=15&hl=true&hl.fl=content&hl.snippets=3&hl.mergeContigious=true&f.content.hl.alternateField=teaser&f.content.hl.maxAlternateFieldLength=256&spellcheck.q=$key&qf=content%5E40&qf=label%5E21.0&qf=tags_h1%5E3.0&qf=tags_h2_h3%5E3.0&qf=tags_inline%5E1.0&qf=taxonomy_names%5E2.0&qf=tos_name%5E3.0&facet=true&facet.sort=count&facet.mincount=1&facet.field=im_field_taxonomy_app_cat&f.im_field_taxonomy_app_cat.facet.limit=50&f.im_field_taxonomy_app_cat.facet.mincount=1&boost=eff_popularity&debugQuery=on&wt=json&json.nl=map"; 
//exit; 
// Retrieve data from the external API 
$response = drupal_http_request($request_url); 

// Check the HTTP response code to see if a valid response was received 
if($response->code >= 200 && $response->code < 300) 
{ 

    //make sure response has values 
    if(isset($response)){ 
     $results = (array) json_decode($response->data); 
    } 
    if(isset($results)){ 
     //dsm($results); 
     //store the values into an array 
     if(isset($results['response']->docs)){ 
     $arrResults = $results['response']->docs; 
     } 
    } 

    //check array count 
    if(count($arrResults) > 0){ 
     //loop the results and add to array for json return data 
     foreach($arrResults as $row){ 
      //dsm($row); 
      //print $row->label; 
      //print "<br>"; 
      $matches[$row->url] = $row->label; 
     } 

    } 
    else{ 
     $matches[''] = "No Results Found!"; 
    } 
} 
else{ 
    $matches[''] = "Check server settings!"; 
} 

drupal_json_output($matches); 

}

संबंधित मुद्दे