#Go ###资源汇集 首先我们把能找到的资源进行汇集

###阅读技术文档 通过阅读文档，我们大致了解了设计相关的信息：

• edx-search本质上是一个 Django application，用于与edx-platform通信
• 搜索的过程是通过先创建索引，然后在索引里检索匹配信息，如果你熟悉ElasticSearch，你会觉得这个过程理所当然
• Python包依赖：Django、pyMongo、pytz、elasticsearch
• 索引数据由index_dictionary()方法决定，当前被索引的数据有：
• Sequence
• Vertical
• Video
• HTML Block
• 也包括课程元信息，包括课程名、课程描述、以及课程开始、结束时间
• LMS和CMS里有好些可开启的开关和可定制的信息，我摘录几个觉得重要的：
• 指定引擎：SEARCH_ENGINE，当前支持ElasticSearchEngine和MockSearchEngine
• 增加可搜索信息：ELASTIC_FIELD_MAPPINGS，该对象是一个自定，可自定拓展
• 如果你想深度定制搜索：SEARCH_INITIALIZER、SEARCH_RESULT_PROCESSOR和SEARCH_FILTER_GENERATOR会是有用的接口

• edx中写搜索相关的业务逻辑，使用elasticsearch-py来操作elasticsearch
• edx的搜索用到了ElasticSearch，通过查阅edx/configuration,我们发现Birch、Cypress和Dogwood使用的版本都是0.90.11

###定制思路 通过前头的初步分析（注意我们还没有进入源码！我们已经初步了解课程搜索相关的设计了，可见阅读文档的重要性），我们大致知道了可以通过实现接口来实现自己的搜索逻辑，其中有三个接口是关键的，包括：

• SEARCH_INITIALIZER，源码见LmsSearchInitializer
• lms.lib.courseware_search.lms_search_initializer.LmsSearchInitializer
• SEARCH_RESULT_PROCESSOR,源码见LmsSearchResultProcessor
• lms.lib.courseware_search.lms_result_processor.LmsSearchResultProcessor
• SEARCH_FILTER_GENERATOR,源码见LmsSearchFilterGenerator
• lms.lib.courseware_search.lms_filter_generator.LmsSearchFilterGenerato」r

###眼见为实 我们首先将devstack跑起来（实际上是在生产环境下）： sudo -u www-data /edx/bin/python.edxapp /edx/app/edxapp/edx-platform/manage.py lms runserver 0.0.0.0:5000 --settings devstack

• course discovery
• all course search
• single course search

response为：

 1  {"access_denied_count": 0, "total": 2, "max_score": 0.6223112, "took": 28, "results": [{"_type": "courseware_content", "score": 0.6223112, "_index": "courseware_index", "_score": 0.6223112, "_id": "block-v1:edX+DemoX+Demo_Course+type@html+block@2bee8c4248e842a19ba1e73ed8d426c2", "data": {"course_name": "edX Demonstration Course", "url": "/courses/course-v1:edX+DemoX+Demo_Course/jump_to/block-v1:edX+DemoX+Demo_Course+type@html+block@2bee8c4248e842a19ba1e73ed8d426c2", "excerpt": "Labs and Demos Professors that create courses on edX are able to", "start_date": "2013-02-05T00:00:00+00:00", "content": {"html_content": "Labs and Demos Professors that create courses on edX are able to implement highly interactive experiences that allow you as a student to experiment using easy to use online web applications. These labs are customized to each class and subject area. We have collected a couple of the more popular lab environments here for you to experience and play with. Please be patient with yourself as you take a look around at these lab environments. You probably will not be able to answer these questions without taking a course on the topic first! ", "display_name": "Labs and Demos"}, "course": "course-v1:edX+DemoX+Demo_Course", "location": ["Example Week 2: Get Interactive", "Homework - Labs and Demos", "Labs and Demos"], "content_type": "Text", "org": "edX", "content_groups": null, "id": "block-v1:edX+DemoX+Demo_Course+type@html+block@2bee8c4248e842a19ba1e73ed8d426c2"}}, {"_type": "courseware_content", "score": 0.16797835, "_index": "courseware_index", "_score": 0.16797835, "_id": "block-v1:edX+DemoX+Demo_Course+type@html+block@Lab_5B_Mosfet_Amplifier_Experiment", "data": {"course_name": "edX Demonstration Course", "url": "/courses/course-v1:edX+DemoX+Demo_Course/jump_to/block-v1:edX+DemoX+Demo_Course+type@html+block@Lab_5B_Mosfet_Amplifier_Experiment", "excerpt": "There are no responses that need to be checked.In the lab below, you", "start_date": "1970-01-01T05:00:00+00:00", "content": {"html_content": "MOSFET AMPLIFIER EXPERIMENTThis demonstration is to develop your intuition about amplifiers and biasing, and to have fun with music! There are no responses that need to be checked.In the lab below, you will find:A circuit schematic of the MOSFET amplifier. You can use the sliders to the left of the circuit to control various parameters of the MOSFET and the amplifier.A plot (as a function of time) of selected voltages from the amplifier circuit. You can select the input waveform (e.g., sine wave, square wave, various types of music) by using the \$$v_\\mathrm{IN}\$$ drop-down menu and the associated sliders. (The parameter \$$V_\\mathrm{MAX}\$$ sets the maximum range on the plots.)The \"Play\" button which lets you listen to the selected voltage waveform as sound. Try it out!Listen to:vINvOUTvRGraph:vINvOUTvRvIN:Zero InputUnit ImpulseUnit StepSine WaveSquare WaveClassical MusicFolk MusicJazz MusicReggae MusicYour browser must support the Canvas element and have JavaScript enabled to view this tool.Your browser must support the Canvas element and have JavaScript enabled to view this tool.Experiment 1: Distorted outputBegin by selecting a sine wave input in the drop-down menu for \$$v_\\mathrm{IN}\$$. Then, adjust the sliders to the baseline (default) setting shown below.Baseline setting of sliders:Peak to peak voltage: \$$v_\\mathrm{IN}=3~\\mathrm{V}\$$,Frequency: \$$f = 1000~\\mathrm{Hz}\$$,Supply voltage: \$$V_\\mathrm{S}=1.6~\\mathrm{V}\$$,Input bias voltage: \$$V_\\mathrm{BIAS}=2.5~\\mathrm{V}\$$,Pull-up resistor: \$$R = 10~\\mathrm{k}\\Omega\$$,MOSFET parameter: \$$K=\\frac{1~\\mathrm{mA}}{\\mathrm{V}^2}\$$,MOSFET threshold voltage: \$$V_\\mathrm{T} = 1~\\mathrm{V}\$$,Vertical plot range: \$$V_\\mathrm{MAX} = 2~\\mathrm{V}\$$.You should observe in the plot that with the baseline settings, the amplifier produces a distorted sine wave signal for \$$v_{OUT}\$$. Next, go ahead and select one of the music signals as the input and listen to each of \$$v_{IN}\$$ and \$$v_{OUT}\$$, and confirm for yourself that the output sounds degraded at the chosen slider settings. You will notice that the graph now plots the music signal waveforms. Think about the reasons why the amplifier is producing a distorted output.Experiment 2: Linear regimeWe now study the amplifier's small signal behavior. Select a sine wave as the input signal. To study the small signal behavior, reduce the value of \$$v_{IN}\$$ to 0.1V (peak-to-peak) by using the \$$v_{IN}\$$ slider. Keeping the rest of the parameters at their baseline settings, derive an appropriate value of \$$V_{BIAS}\$$ that will ensure saturation region operation for the MOSFET for the 0.1V peak-to-peak swing for \$$v_{IN}\$$. Make sure to think about both positive and negative excursions of the signals.Next, use the \$$V_{BIAS}\$$ slider to choose your computed value for \$$V_{BIAS}\$$ and see if the observed plot of \$$v_{OUT}\$$ is more-or-less distortion free. If your calculation was right, then the output will indeed be distortion free.Next, select one of the music signals as the input and listen to each of \$$v_{IN}\$$ and \$$v_{OUT}\$$, and confirm for yourself that the output sounds much better than in Experiment 1. Also, based on sound volume, convince yourself that \$$v_{OUT}\$$ is an amplified version of \$$v_{IN}\$$.Experiment 3: Your settingsNow go ahead and experiment with various other settings while listening to the music signal at \$$v_{OUT}\$$. Observe the plots and listen to \$$v_{OUT}\$$ as you change, for example, the bias voltage \$$V_{BIAS}\$$. You will notice that the amplifier distorts the input signal when \$$V_{BIAS}\$$ becomes too small, or when it becomes too large. You can also experiment with various values of \$$v_{IN}\$$, \$$R_{L}\$$, etc., and see how they affect the amplification and distortion.", "display_name": "Electronic Sound Experiment"}, "course": "course-v1:edX+DemoX+Demo_Course", "location": ["Example Week 2: Get Interactive", "Lesson 2 - Let's Get Interactive!", "Electronic Sound Experiment"], "content_type": "Text", "org": "edX", "content_groups": null, "id": "block-v1:edX+DemoX+Demo_Course+type@html+block@Lab_5B_Mosfet_Amplifier_Experiment"}}]}

###做个试验 使用httpie做实验，在里我们从外部发起请求，ajax的方式让人不方便直接观察数据，而且总感觉耦合在一起，不干净

http -f POST http://209.9.106.99:5000/search/course-v1:edX+DemoX+Demo_Course search_string=edx page_size=20 page_index=0 'Cookie:sessionid=pzjqyf6kdoo8jj96ng753xhr1isvstm3;csrftoken=sjPry3O5UpFFp3N3izrIVvd9ZMDEWA7V' X-CSRFToken:sjPry3O5UpFFp3N3izrIVvd9ZMDEWA7V

url的格式为 DEMAIN/search/

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62  { "access_denied_count": 0, "max_score": 0.6223112, "results": [ { "_id": "block-v1:edX+DemoX+Demo_Course+type@html+block@2bee8c4248e842a19ba1e73ed8d426c2", "_index": "courseware_index", "_score": 0.6223112, "_type": "courseware_content", "data": { "content": { "display_name": "Labs and Demos", "html_content": "Labs and Demos Professors that create courses on edX are able to implement highly interactive experiences that allow you as a student to experiment using easy to use online web applications. These labs are customized to each class and subject area. We have collected a couple of the more popular lab environments here for you to experience and play with. Please be patient with yourself as you take a look around at these lab environments. You probably will not be able to answer these questions without taking a course on the topic first! " }, "content_groups": null, "content_type": "Text", "course": "course-v1:edX+DemoX+Demo_Course", "course_name": "edX Demonstration Course", "excerpt": "Labs and Demos Professors that create courses on edX are able to", "id": "block-v1:edX+DemoX+Demo_Course+type@html+block@2bee8c4248e842a19ba1e73ed8d426c2", "location": [ "Example Week 2: Get Interactive", "Homework - Labs and Demos", "Labs and Demos" ], "org": "edX", "start_date": "2013-02-05T00:00:00+00:00", "url": "/courses/course-v1:edX+DemoX+Demo_Course/jump_to/block-v1:edX+DemoX+Demo_Course+type@html+block@2bee8c4248e842a19ba1e73ed8d426c2" }, "score": 0.6223112 }, { "_id": "block-v1:edX+DemoX+Demo_Course+type@html+block@Lab_5B_Mosfet_Amplifier_Experiment", "_index": "courseware_index", "_score": 0.16797835, "_type": "courseware_content", "data": { "content": { "display_name": "Electronic Sound Experiment", "html_content": "MOSFET AMPLIFIER EXPERIMENTThis demonstration is to develop your intuition about amplifiers and biasing, and to have fun with music! There are no responses that need to be checked.In the lab below, you will find:A circuit schematic of the MOSFET amplifier. You can use the sliders to the left of the circuit to control various parameters of the MOSFET and the amplifier.A plot (as a function of time) of selected voltages from the amplifier circuit. You can select the input waveform (e.g., sine wave, square wave, various types of music) by using the \$$v_\\mathrm{IN}\$$ drop-down menu and the associated sliders. (The parameter \$$V_\\mathrm{MAX}\$$ sets the maximum range on the plots.)The \"Play\" button which lets you listen to the selected voltage waveform as sound. Try it out!Listen to:vINvOUTvRGraph:vINvOUTvRvIN:Zero InputUnit ImpulseUnit StepSine WaveSquare WaveClassical MusicFolk MusicJazz MusicReggae MusicYour browser must support the Canvas element and have JavaScript enabled to view this tool.Your browser must support the Canvas element and have JavaScript enabled to view this tool.Experiment 1: Distorted outputBegin by selecting a sine wave input in the drop-down menu for \$$v_\\mathrm{IN}\$$. Then, adjust the sliders to the baseline (default) setting shown below.Baseline setting of sliders:Peak to peak voltage: \$$v_\\mathrm{IN}=3~\\mathrm{V}\$$,Frequency: \$$f = 1000~\\mathrm{Hz}\$$,Supply voltage: \$$V_\\mathrm{S}=1.6~\\mathrm{V}\$$,Input bias voltage: \$$V_\\mathrm{BIAS}=2.5~\\mathrm{V}\$$,Pull-up resistor: \$$R = 10~\\mathrm{k}\\Omega\$$,MOSFET parameter: \$$K=\\frac{1~\\mathrm{mA}}{\\mathrm{V}^2}\$$,MOSFET threshold voltage: \$$V_\\mathrm{T} = 1~\\mathrm{V}\$$,Vertical plot range: \$$V_\\mathrm{MAX} = 2~\\mathrm{V}\$$.You should observe in the plot that with the baseline settings, the amplifier produces a distorted sine wave signal for \$$v_{OUT}\$$. Next, go ahead and select one of the music signals as the input and listen to each of \$$v_{IN}\$$ and \$$v_{OUT}\$$, and confirm for yourself that the output sounds degraded at the chosen slider settings. You will notice that the graph now plots the music signal waveforms. Think about the reasons why the amplifier is producing a distorted output.Experiment 2: Linear regimeWe now study the amplifier's small signal behavior. Select a sine wave as the input signal. To study the small signal behavior, reduce the value of \$$v_{IN}\$$ to 0.1V (peak-to-peak) by using the \$$v_{IN}\$$ slider. Keeping the rest of the parameters at their baseline settings, derive an appropriate value of \$$V_{BIAS}\$$ that will ensure saturation region operation for the MOSFET for the 0.1V peak-to-peak swing for \$$v_{IN}\$$. Make sure to think about both positive and negative excursions of the signals.Next, use the \$$V_{BIAS}\$$ slider to choose your computed value for \$$V_{BIAS}\$$ and see if the observed plot of \$$v_{OUT}\$$ is more-or-less distortion free. If your calculation was right, then the output will indeed be distortion free.Next, select one of the music signals as the input and listen to each of \$$v_{IN}\$$ and \$$v_{OUT}\$$, and confirm for yourself that the output sounds much better than in Experiment 1. Also, based on sound volume, convince yourself that \$$v_{OUT}\$$ is an amplified version of \$$v_{IN}\$$.Experiment 3: Your settingsNow go ahead and experiment with various other settings while listening to the music signal at \$$v_{OUT}\$$. Observe the plots and listen to \$$v_{OUT}\$$ as you change, for example, the bias voltage \$$V_{BIAS}\$$. You will notice that the amplifier distorts the input signal when \$$V_{BIAS}\$$ becomes too small, or when it becomes too large. You can also experiment with various values of \$$v_{IN}\$$, \$$R_{L}\$$, etc., and see how they affect the amplification and distortion." }, "content_groups": null, "content_type": "Text", "course": "course-v1:edX+DemoX+Demo_Course", "course_name": "edX Demonstration Course", "excerpt": "There are no responses that need to be checked.In the lab below, you", "id": "block-v1:edX+DemoX+Demo_Course+type@html+block@Lab_5B_Mosfet_Amplifier_Experiment", "location": [ "Example Week 2: Get Interactive", "Lesson 2 - Let's Get Interactive!", "Electronic Sound Experiment" ], "org": "edX", "start_date": "1970-01-01T05:00:00+00:00", "url": "/courses/course-v1:edX+DemoX+Demo_Course/jump_to/block-v1:edX+DemoX+Demo_Course+type@html+block@Lab_5B_Mosfet_Amplifier_Experiment" }, "score": 0.16797835 } ], "took": 15, "total": 2 }

###分析源码 ####类继承关系

waiting… 具体的源码分析留到之后有时间再折腾。今天大体上已经将search服务干净地分离出来了，据此可以做许多有趣的东西

###Elasticsearch Elasticsearch 是一个分布式可扩展的实时搜索和分析引擎。它能帮助你搜索、分析和浏览数据。edx中的相关搜索都是基于它写的