كيف تعمل مربعات البحث في المتصفحات؟ [مغلق

StackOverflow https://stackoverflow.com/questions/1058275

  •  21-08-2019
  •  | 
  •  

سؤال

أحتاج إلى معرفة بالضبط كيف تعمل صناديق البحث على المتصفحات. أرغب في استبدال أشياء البحث ، مثل ويكيبيديا وجوجل ، مع محركات بحث مخصصة هنا في الرياضيات. يمكنك رؤيتها في Igoogle. لذا:

كيف يمكنني إضافة Google CSEs إلى مربعات البحث في المتصفحات؟

هل كانت مفيدة؟

المحلول

يمكنك إنشاء ما يسمى "مقدمي البحث" لمواقعك. يجب أن يكون لديك صفحة بحث على موقعك تقبل الكلمات الرئيسية للبحث كسلسلة استعلام في عنوان URL الخاص بك ، مثل

  http://www.example.com/search?q=meaning+of+life

هذا يجب أن يعمل Google Search Custom أيضًا.

سيكون عليك إنشاء ملف XML خاص (اتصل به SearchProvider.xml, ، على سبيل المثال) ووضعه على خادم الويب الخاص بك:

<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
   <ShortName>Example Search Provider</ShortName>
   <Description>Finds answers to the most important question of the universe</Description>
   <InputEncoding>UTF-8</InputEncoding>
   <Url type="text/html" template=" http://www.example.com/search?q={searchTerms}"/>
</OpenSearchDescription>

بعد ذلك ، ستحتاج إلى إدراج علامة ارتباط خاصة في قسم رأس صفحتك:

 <link title="Example Search Provider" rel="search"
     type="application/opensearchdescription+xml"
     href="http://www.example.com/SearchProvider.xml" />

يمكنك أيضًا إدخال رابط إلى صفحتك ، مما يتيح للمستخدمين إضافة مزود البحث إلى المتصفح:

<a href="#"
   onclick="javascript:window.external.AddSearchProvider('http://www.example.com/SearchProvider.xml');">
Example Search Provider</a>

نصائح أخرى

يتم تنفيذ مربعات البحث في المتصفح في تقنية تسمى OpenSearch. نرى: http://www.opensearch.org/ (الموقع أسفل؟)

لدى Mozilla صفحة جيدة تشرح كيفية تنفيذ هذا لمتصفحاتهم: https://developer.mozilla.org/en/creating_opensearch_plugins_for_firefox على الرغم من وجود عدد قليل من التفاصيل الخاصة بـ Mozilla ، إلا أن هذه الصفحة يمكن أن تكون بمثابة نقطة انطلاق جيدة لتنفيذ المتصفح.

أضف الإكمال التلقائي إلى مربع البحث أكثر صعوبة بعض الشيء. أضف أولاً عنوان URL للاستعلام التلقائي كما هو موضح من قبل Mozilla. ثم يجب عليك صياغة استجابة على الخادم الخاص بك والتي تتوافق مع ما تتوقعه المتصفحات المختلفة.

ألقِ نظرة على ما يعيده Google للمتصفحات المختلفة التي تدعمها:

* Firefox: http://suggestqueries.google.com/complete/search?client=firefox&hl=en-US&q=xmarks
      o Content-Type: text/javascript
      o Response body: ["xmarks",["xmarksthaspot","xmarksthescot","foxmarks safari","xmark.com","gmarks firefox","x marks foxmarks","xmarksthespot","xmarks ie","foxmarks addon","foxmarks for ie"]] 
* Safari: http://suggestqueries.google.com/complete/search?client=safari&hl=en-US&q=xmarks
      o Content-Type: application/json
      o Response body: ["xmarks",[["xmarksthaspot","18,400 results","0"],["xmarksthescot","196,000 results","1"],["foxmarks safari","148,000 results","2s"],["xmark.com","336,000 results","3s"],["gmarks firefox","50,700 results","4s"],["x marks foxmarks","13,500 results","5s"],["xmarksthespot","20,500 results","6"],["xmarks ie","96,400 results","7"],["foxmarks addon","210,000 results","8s"],["foxmarks for ie","191,000 results","9s"]]]
* Others: http://suggestqueries.google.com/complete/search?client=ie&hl=en-US&q=xmarks
      o Content-Type: text/javascript
      o Response body: I'm not sure it's relevant. It's essentially the exact same format as Safari above, but it's wrapped by a JavaScript call to window.google.ac.h(). I'm not 100% certain, but that looks like the callback to their HTML-page version of auto-completion and suggests to me that they don't really support opensearch auto-completion in anything but Firefox and Safari.

ربما يعتمد الأمر على المتصفح إلى المتصفح ، ولكن مع Firefox ، من السهل تخصيصه: انظر شريط البحث وكيفية إضافة محرك بحث مخصص إلى شريط بحث Firefox بسهولة.

توفر Microsoft أداة لإضافة مقدمي بحث مخصص إلى IE ، ويتيح لك Add to Search Bar Extension القيام بنفس الشيء مع Firefox.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top