从最简单的索引开始建立好了(此处省去了sphinx的安装过程)。
<code class="language-sql hljs has-numbering"><span class="hljs-comment">-- 建立索引表</span> <span class="hljs-operator"><span class="hljs-keyword">create</span> <span class="hljs-keyword">table</span> sphinx_searchs( id <span class="hljs-keyword">int</span>(<span class="hljs-number">10</span>) unsigned auto_increment, <span class="hljs-keyword">key</span> <span class="hljs-keyword">varchar</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">not</span> <span class="hljs-keyword">null</span>, <span class="hljs-keyword">primary</span> <span class="hljs-keyword">key</span> id) enginer=innodb;</span></code><ul style="" class="pre-numbering"><li>1</li><li>2</li></ul>
<code class="hljs avrasm has-numbering"><span class="hljs-preprocessor"># 全局设置</span> source src1 { type = mysql sql_host = <span class="hljs-number">192.</span><span class="hljs-built_in">x</span><span class="hljs-preprocessor">.x</span><span class="hljs-preprocessor">.x</span> sql_user = xxxxxx sql_pass = xxxxxx sql_db = search sql_port = <span class="hljs-number">3306</span> sql_query_pre = <span class="hljs-keyword">SET</span> NAMES utf8 } <span class="hljs-preprocessor"># 继承数据库设置</span> source product : src1 { sql_query = SELECT `id`,`key` FROM sphinx_searchs } <span class="hljs-preprocessor"># 索引文件设置</span> index product { source = product path = /webroot/database/sphinx/product docinfo = extern dict = keywords mlock = <span class="hljs-number">0</span> morphology = none min_word_len = <span class="hljs-number">1</span> charset_table = U+FF10.<span class="hljs-preprocessor">.U</span>+FF19-><span class="hljs-number">0.</span><span class="hljs-number">.9</span>, <span class="hljs-number">0.</span><span class="hljs-number">.9</span>, U+FF41.<span class="hljs-preprocessor">.U</span>+FF5A->a.<span class="hljs-preprocessor">.z</span>, U+FF21.<span class="hljs-preprocessor">.U</span>+FF3A->a.<span class="hljs-preprocessor">.z</span>,A.<span class="hljs-preprocessor">.Z</span>->a.<span class="hljs-preprocessor">.z</span>, a.<span class="hljs-preprocessor">.z</span>, U+<span class="hljs-number">0149</span>, U+<span class="hljs-number">017</span>F, U+<span class="hljs-number">0138</span>, U+<span class="hljs-number">00</span>DF, U+<span class="hljs-number">00</span>FF, U+<span class="hljs-number">00</span>C0.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">00</span>D6->U+<span class="hljs-number">00E0</span>.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">00</span>F6,U+<span class="hljs-number">00E0</span>.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">00</span>F6, U+<span class="hljs-number">00</span>D8.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">00</span>DE->U+<span class="hljs-number">00</span>F8.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">00</span>FE, U+<span class="hljs-number">00</span>F8.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">00</span>FE, U+<span class="hljs-number">0100</span>->U+<span class="hljs-number">0101</span>, U+<span class="hljs-number">0101</span>,U+<span class="hljs-number">0102</span>->U+<span class="hljs-number">0103</span>, U+<span class="hljs-number">0103</span>, U+<span class="hljs-number">0104</span>->U+<span class="hljs-number">0105</span>, U+<span class="hljs-number">0105</span>, U+<span class="hljs-number">0106</span>->U+<span class="hljs-number">0107</span>, U+<span class="hljs-number">0107</span>, U+<span class="hljs-number">0108</span>->U+<span class="hljs-number">0109</span>,U+<span class="hljs-number">0109</span>, U+<span class="hljs-number">010</span>A->U+<span class="hljs-number">010</span>B, U+<span class="hljs-number">010</span>B, U+<span class="hljs-number">010</span>C->U+<span class="hljs-number">010</span>D, U+<span class="hljs-number">010</span>D, U+<span class="hljs-number">010</span>E->U+<span class="hljs-number">010</span>F, U+<span class="hljs-number">010</span>F,U+<span class="hljs-number">0110</span>->U+<span class="hljs-number">0111</span>, U+<span class="hljs-number">0111</span>, U+<span class="hljs-number">0112</span>->U+<span class="hljs-number">0113</span>, U+<span class="hljs-number">0113</span>, U+<span class="hljs-number">0114</span>->U+<span class="hljs-number">0115</span>, U+<span class="hljs-number">0115</span>, U+<span class="hljs-number">0116</span>->U+<span class="hljs-number">0117</span>,U+<span class="hljs-number">0117</span>, U+<span class="hljs-number">0118</span>->U+<span class="hljs-number">0119</span>, U+<span class="hljs-number">0119</span>, U+<span class="hljs-number">011</span>A->U+<span class="hljs-number">011</span>B, U+<span class="hljs-number">011</span>B, U+<span class="hljs-number">011</span>C->U+<span class="hljs-number">011</span>D, U+<span class="hljs-number">011</span>D,U+<span class="hljs-number">011</span>E->U+<span class="hljs-number">011</span>F, U+<span class="hljs-number">011</span>F, U+<span class="hljs-number">0130</span>->U+<span class="hljs-number">0131</span>, U+<span class="hljs-number">0131</span>, U+<span class="hljs-number">0132</span>->U+<span class="hljs-number">0133</span>, U+<span class="hljs-number">0133</span>, U+<span class="hljs-number">0134</span>->U+<span class="hljs-number">0135</span>,U+<span class="hljs-number">0135</span>, U+<span class="hljs-number">0136</span>->U+<span class="hljs-number">0137</span>, U+<span class="hljs-number">0137</span>, U+<span class="hljs-number">0139</span>->U+<span class="hljs-number">013</span>A, U+<span class="hljs-number">013</span>A, U+<span class="hljs-number">013</span>B->U+<span class="hljs-number">013</span>C, U+<span class="hljs-number">013</span>C,U+<span class="hljs-number">013</span>D->U+<span class="hljs-number">013</span>E, U+<span class="hljs-number">013</span>E, U+<span class="hljs-number">013</span>F->U+<span class="hljs-number">0140</span>, U+<span class="hljs-number">0140</span>, U+<span class="hljs-number">0141</span>->U+<span class="hljs-number">0142</span>, U+<span class="hljs-number">0142</span>, U+<span class="hljs-number">0143</span>->U+<span class="hljs-number">0144</span>,U+<span class="hljs-number">0144</span>, U+<span class="hljs-number">0145</span>->U+<span class="hljs-number">0146</span>, U+<span class="hljs-number">0146</span>, U+<span class="hljs-number">0147</span>->U+<span class="hljs-number">0148</span>, U+<span class="hljs-number">0148</span>, U+<span class="hljs-number">014</span>A->U+<span class="hljs-number">014</span>B, U+<span class="hljs-number">014</span>B,U+<span class="hljs-number">014</span>C->U+<span class="hljs-number">014</span>D, U+<span class="hljs-number">014</span>D, U+<span class="hljs-number">014</span>E->U+<span class="hljs-number">014</span>F, U+<span class="hljs-number">014</span>F, U+<span class="hljs-number">0150</span>->U+<span class="hljs-number">0151</span>, U+<span class="hljs-number">0151</span>, U+<span class="hljs-number">0152</span>->U+<span class="hljs-number">0153</span>,U+<span class="hljs-number">0153</span>, U+<span class="hljs-number">0154</span>->U+<span class="hljs-number">0155</span>, U+<span class="hljs-number">0155</span>, U+<span class="hljs-number">0156</span>->U+<span class="hljs-number">0157</span>, U+<span class="hljs-number">0157</span>, U+<span class="hljs-number">0158</span>->U+<span class="hljs-number">0159</span>, U+<span class="hljs-number">0159</span>,U+<span class="hljs-number">015</span>A->U+<span class="hljs-number">015</span>B, U+<span class="hljs-number">015</span>B, U+<span class="hljs-number">015</span>C->U+<span class="hljs-number">015</span>D, U+<span class="hljs-number">015</span>D, U+<span class="hljs-number">015</span>E->U+<span class="hljs-number">015</span>F, U+<span class="hljs-number">015</span>F, U+<span class="hljs-number">0160</span>->U+<span class="hljs-number">0161</span>,U+<span class="hljs-number">0161</span>, U+<span class="hljs-number">0162</span>->U+<span class="hljs-number">0163</span>, U+<span class="hljs-number">0163</span>, U+<span class="hljs-number">0164</span>->U+<span class="hljs-number">0165</span>, U+<span class="hljs-number">0165</span>, U+<span class="hljs-number">0166</span>->U+<span class="hljs-number">0167</span>, U+<span class="hljs-number">0167</span>,U+<span class="hljs-number">0168</span>->U+<span class="hljs-number">0169</span>, U+<span class="hljs-number">0169</span>, U+<span class="hljs-number">016</span>A->U+<span class="hljs-number">016</span>B, U+<span class="hljs-number">016</span>B, U+<span class="hljs-number">016</span>C->U+<span class="hljs-number">016</span>D, U+<span class="hljs-number">016</span>D, U+<span class="hljs-number">016</span>E->U+<span class="hljs-number">016</span>F,U+<span class="hljs-number">016</span>F, U+<span class="hljs-number">0170</span>->U+<span class="hljs-number">0171</span>, U+<span class="hljs-number">0171</span>, U+<span class="hljs-number">0172</span>->U+<span class="hljs-number">0173</span>, U+<span class="hljs-number">0173</span>, U+<span class="hljs-number">0174</span>->U+<span class="hljs-number">0175</span>, U+<span class="hljs-number">0175</span>,U+<span class="hljs-number">0176</span>->U+<span class="hljs-number">0177</span>, U+<span class="hljs-number">0177</span>, U+<span class="hljs-number">0178</span>->U+<span class="hljs-number">00</span>FF, U+<span class="hljs-number">00</span>FF, U+<span class="hljs-number">0179</span>->U+<span class="hljs-number">017</span>A, U+<span class="hljs-number">017</span>A, U+<span class="hljs-number">017</span>B->U+<span class="hljs-number">017</span>C,U+<span class="hljs-number">017</span>C, U+<span class="hljs-number">017</span>D->U+<span class="hljs-number">017</span>E, U+<span class="hljs-number">017</span>E, U+<span class="hljs-number">0410.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">042</span>F->U+<span class="hljs-number">0430.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">044</span>F, U+<span class="hljs-number">0430.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">044</span>F,U+<span class="hljs-number">05</span>D0.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">05</span>EA, U+<span class="hljs-number">0531.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0556</span>->U+<span class="hljs-number">0561.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0586</span>, U+<span class="hljs-number">0561.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0587</span>, U+<span class="hljs-number">0621.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">063</span>A, U+<span class="hljs-number">01</span>B9,U+<span class="hljs-number">01</span>BF, U+<span class="hljs-number">0640.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">064</span>A, U+<span class="hljs-number">0660.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0669</span>, U+<span class="hljs-number">066</span>E, U+<span class="hljs-number">066</span>F, U+<span class="hljs-number">0671.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">06</span>D3, U+<span class="hljs-number">06</span>F0.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">06</span>FF,U+<span class="hljs-number">0904.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0939</span>, U+<span class="hljs-number">0958.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">095</span>F, U+<span class="hljs-number">0960.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0963</span>, U+<span class="hljs-number">0966.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">096</span>F, U+<span class="hljs-number">097</span>B.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">097</span>F,U+<span class="hljs-number">0985.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">09</span>B9, U+<span class="hljs-number">09</span>CE, U+<span class="hljs-number">09</span>DC.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">09E3</span>, U+<span class="hljs-number">09E6</span>.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">09</span>EF, U+<span class="hljs-number">0</span>A05.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>A39, U+<span class="hljs-number">0</span>A59.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>A5E,U+<span class="hljs-number">0</span>A66.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>A6F, U+<span class="hljs-number">0</span>A85.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>AB9, U+<span class="hljs-number">0</span>AE0.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>AE3, U+<span class="hljs-number">0</span>AE6.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>AEF, U+<span class="hljs-number">0</span>B05.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>B39,U+<span class="hljs-number">0</span>B5C.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>B61, U+<span class="hljs-number">0</span>B66.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>B6F, U+<span class="hljs-number">0</span>B71, U+<span class="hljs-number">0</span>B85.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>BB9, U+<span class="hljs-number">0</span>BE6.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>BF2, U+<span class="hljs-number">0</span>C05.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>C39,U+<span class="hljs-number">0</span>C66.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>C6F, U+<span class="hljs-number">0</span>C85.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>CB9, U+<span class="hljs-number">0</span>CDE.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>CE3, U+<span class="hljs-number">0</span>CE6.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>CEF, U+<span class="hljs-number">0</span>D05.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>D39, U+<span class="hljs-number">0</span>D60,U+<span class="hljs-number">0</span>D61, U+<span class="hljs-number">0</span>D66.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>D6F, U+<span class="hljs-number">0</span>D85.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0</span>DC6, U+<span class="hljs-number">1900.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">1938</span>, U+<span class="hljs-number">1946.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">194</span>F, U+A800.<span class="hljs-preprocessor">.U</span>+A805,U+A807.<span class="hljs-preprocessor">.U</span>+A822, U+<span class="hljs-number">0386</span>->U+<span class="hljs-number">03</span>B1, U+<span class="hljs-number">03</span>AC->U+<span class="hljs-number">03</span>B1, U+<span class="hljs-number">0388</span>->U+<span class="hljs-number">03</span>B5, U+<span class="hljs-number">03</span>AD->U+<span class="hljs-number">03</span>B5,U+<span class="hljs-number">0389</span>->U+<span class="hljs-number">03</span>B7, U+<span class="hljs-number">03</span>AE->U+<span class="hljs-number">03</span>B7, U+<span class="hljs-number">038</span>A->U+<span class="hljs-number">03</span>B9, U+<span class="hljs-number">0390</span>->U+<span class="hljs-number">03</span>B9, U+<span class="hljs-number">03</span>AA->U+<span class="hljs-number">03</span>B9,U+<span class="hljs-number">03</span>AF->U+<span class="hljs-number">03</span>B9, U+<span class="hljs-number">03</span>CA->U+<span class="hljs-number">03</span>B9, U+<span class="hljs-number">038</span>C->U+<span class="hljs-number">03</span>BF, U+<span class="hljs-number">03</span>CC->U+<span class="hljs-number">03</span>BF, U+<span class="hljs-number">038</span>E->U+<span class="hljs-number">03</span>C5,U+<span class="hljs-number">03</span>AB->U+<span class="hljs-number">03</span>C5, U+<span class="hljs-number">03</span>B0->U+<span class="hljs-number">03</span>C5, U+<span class="hljs-number">03</span>CB->U+<span class="hljs-number">03</span>C5, U+<span class="hljs-number">03</span>CD->U+<span class="hljs-number">03</span>C5, U+<span class="hljs-number">038</span>F->U+<span class="hljs-number">03</span>C9,U+<span class="hljs-number">03</span>CE->U+<span class="hljs-number">03</span>C9, U+<span class="hljs-number">03</span>C2->U+<span class="hljs-number">03</span>C3, U+<span class="hljs-number">0391.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">03</span>A1->U+<span class="hljs-number">03</span>B1.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">03</span>C1,U+<span class="hljs-number">03</span>A3.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">03</span>A9->U+<span class="hljs-number">03</span>C3.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">03</span>C9, U+<span class="hljs-number">03</span>B1.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">03</span>C1, U+<span class="hljs-number">03</span>C3.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">03</span>C9, U+<span class="hljs-number">0E01</span>.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0E2</span>E,U+<span class="hljs-number">0E30</span>.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0E3</span>A, U+<span class="hljs-number">0E40</span>.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0E45</span>, U+<span class="hljs-number">0E47</span>, U+<span class="hljs-number">0E50</span>.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">0E59</span>, U+A000.<span class="hljs-preprocessor">.U</span>+A48F, U+<span class="hljs-number">4E00</span>.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">9</span>FBF,U+<span class="hljs-number">3400.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">4</span>DBF, U+<span class="hljs-number">20000.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">2</span>A6DF, U+F900.<span class="hljs-preprocessor">.U</span>+FAFF, U+<span class="hljs-number">2</span>F800.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">2</span>FA1F, U+<span class="hljs-number">2E80</span>.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">2</span>EFF,U+<span class="hljs-number">2</span>F00.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">2</span>FDF, U+<span class="hljs-number">3100.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">312</span>F, U+<span class="hljs-number">31</span>A0.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">31</span>BF, U+<span class="hljs-number">3040.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">309</span>F, U+<span class="hljs-number">30</span>A0.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">30</span>FF,U+<span class="hljs-number">31</span>F0.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">31</span>FF, U+AC00.<span class="hljs-preprocessor">.U</span>+D7AF, U+<span class="hljs-number">1100.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">11</span>FF, U+<span class="hljs-number">3130.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">318</span>F, U+A000.<span class="hljs-preprocessor">.U</span>+A48F,U+A490.<span class="hljs-preprocessor">.U</span>+A4CF ngram_chars = U+<span class="hljs-number">4E00</span>.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">9</span>FBF, U+<span class="hljs-number">3400.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">4</span>DBF, U+<span class="hljs-number">20000.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">2</span>A6DF, U+F900.<span class="hljs-preprocessor">.U</span>+FAFF,U+<span class="hljs-number">2</span>F800.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">2</span>FA1F, U+<span class="hljs-number">2E80</span>.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">2</span>EFF, U+<span class="hljs-number">2</span>F00.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">2</span>FDF, U+<span class="hljs-number">3100.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">312</span>F, U+<span class="hljs-number">31</span>A0.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">31</span>BF,U+<span class="hljs-number">3040.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">309</span>F, U+<span class="hljs-number">30</span>A0.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">30</span>FF,U+<span class="hljs-number">31</span>F0.<span class="hljs-preprocessor">.U</span>+<span class="hljs-number">31</span>FF, U+AC00.<span class="hljs-preprocessor">.U</span>+D7AF, U+<span class="hljs-number">1100.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">11</span>FF,U+<span class="hljs-number">3130.</span><span class="hljs-preprocessor">.U</span>+<span class="hljs-number">318</span>F, U+A000.<span class="hljs-preprocessor">.U</span>+A48F, U+A490.<span class="hljs-preprocessor">.U</span>+A4CF html_strip = <span class="hljs-number">1</span> min_prefix_len = <span class="hljs-number">0</span> min_infix_len = <span class="hljs-number">1</span> ngram_len = <span class="hljs-number">1</span> }</code><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li><li>27</li><li>28</li><li>29</li><li>30</li><li>31</li><li>32</li><li>33</li><li>34</li></ul>
下面对以上的设置进行说明。
source product : src1
数据源设置
创建一个数据源,他的信息继承自 src1
,继承和程序类的继承一样,子对象可以对父对象的值进行覆盖。使用继承可以省略我们编写重复的设置信息。
index product
索引的设置:
source
:指向数据源(这里我们指向source product : src1
);path
:索引文件存放的目录;charset_table
:接受的字符表和大小写转换规则,更多的信息可以参考官方文档,以上我们已经设置为亚洲语言编码区域,可以直接复制使用;ngram_chars
:同上,不多做解释;min_word_len
:非英文词组最小字符数(也就是单个汉字)html_strip
:过滤HTML元素<code class="language-shell hljs brainfuck has-numbering"><span class="hljs-comment">/opt/sphinx/bin/indexer</span> <span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-comment">config</span> <span class="hljs-comment">/opt/sphinx/config</span><span class="hljs-string">.</span><span class="hljs-comment">conf</span> <span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-comment">all</span> <span class="hljs-comment">/opt/sphinx/bin/searchd</span> <span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-comment">config</span> <span class="hljs-comment">/opt/sphinx/config</span><span class="hljs-string">.</span><span class="hljs-comment">conf</span></code><ul style="" class="pre-numbering"><li>1</li><li>2</li></ul>
进行搜索
<code class="language-php hljs has-numbering"><span class="hljs-preprocessor"><?php</span> <span class="hljs-variable">$sphinx</span> = <span class="hljs-keyword">new</span> SphinxClient; <span class="hljs-variable">$sphinx</span>->setServer(<span class="hljs-string">'127.0.0.1'</span>,<span class="hljs-number">9312</span>); <span class="hljs-variable">$result</span> = <span class="hljs-variable">$sphinx</span>->query(<span class="hljs-string">'树脂摆饰'</span>,<span class="hljs-string">'product'</span>);</code><ul style="" class="pre-numbering"><li>1</li><li>2</li><li>3</li><li>4</li></ul>
到此,无需太多的设置,暂时抛弃复杂,繁琐的过滤功能,简简单单的实现了索引引擎核心功能——标题检索。
除此,大家可以试试var_dump($result)
以下方式检索之间,结果有什么区别?
$result = $sphinx->query('*树脂摆饰','product');
$result = $sphinx->query('树脂摆饰*','product');
$result = $sphinx->query('*树脂摆饰*','product');