以及技术文档:Enabling Open edX Search,如你所料,它一如既往地变更频繁和不够完备。怎么说呢,如果你和我一样乐观,你大概会觉得这是好事吧,它意味着这个项目在被持续、迅猛地推进

#Ready 关于edx search(这里重点谈论的是课程/内容搜索相关的部分),我们有个很有趣的想法,为了实现它,我们需要深入了解这个机制。而后在网上发现一些人也需要深度定制它。所以我将自己的分析过程分享出来,抛装引玉。也许能引来有趣的讨论,也许能帮到后来者,也许能给自己以启发

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

###眼见为实 我们首先将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

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": "<b>Lab</b>s 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 <b>lab</b> 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"}}]}

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

 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": "<b>Lab</b>s 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 <b>lab</b> 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
}

以上这个技巧对我们做调试十分有帮助,因为输出在命令行所以我们可以尽情使用grep和jq等工具来筛选信息。只要数据能流向命令行,我们的linux工具箱就将发挥作用,工具的组合威力每次都能让我大吃一惊。管道大概是Unix工具箱最美妙的特性之一

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