如何从方案中向 Sphinx 索引添加属性?
How add attribute to Sphinx index from scheme?
我使用 PHP XMLWriter:
$xmlwriter->startElement('sphinx:schema');
$xmlwriter->startElement('spinx:attribute');
$xmlwriter->writeAttribute("name", "path");
$xmlwriter->writeAttribute("type", "string");
$xmlwriter->endElement(); // attr
$xmlwriter->startElement('sphinx:field');
$xmlwriter->writeAttribute("name", "content");
$xmlwriter->endElement(); // field
$xmlwriter->endElement(); // schema
$xmlwriter->startElement('sphinx:document');
$xmlwriter->writeAttribute("id", 1);
$xmlwriter->writeAttribute("path", "TEST_ATTRIBUTE");
$xmlwriter->startElement("content");
$xmlwriter->text("TEST_CONTENT");
$xmlwriter->endElement(); // field
$xmlwriter->endElement(); // doc
$xmlwriter->endElement(); // docset
所以我得到:
<?xml version="1.0" encoding="UTF-8"?>
<sphinx:docset>
<sphinx:schema>
<spinx:attribute name="path" type="string"/> - why there is '/>' not '>'?
<sphinx:field name="content"/>
</sphinx:schema>
<sphinx:document id="1" path="TEST_ATTRIBUTE">
<content>TEST_CONTENT</content>
</sphinx:document>
</sphinx:docset>
所以我尝试:indexer --rotate --all --config /etc/sphinxsearch/sphinx.conf
狮身人面像 2.2.11-id64-release (95ae9a6)
使用配置文件 'sphinx.conf'...
索引指数 'test1'...
警告:属性计数为 0:切换到 none docinfo
所以我在索引中没有得到属性。
好像打错了...
$xmlwriter->startElement('spinx:attribute');
-----^
why there is '/>' not '>'?
https://www.google.com/search?q=XML+closing+tags
Each tag opened has to be closed. XML is pedantic about this. However,
if a tag is empty (no content), a single tag can serve as both the
opening and closing tag if it ends with /> rather than with > . XML -
Libxml2 http://www.xmlsoft.org/XMLinfo.html
这是正确的代码!!!
$xmlwriter = new xmlWriter();
$xmlwriter->openMemory();
$xmlwriter->setIndent(true);
$xmlwriter->startDocument('1.0','UTF-8');
$xmlwriter->startElement('sphinx:docset');
$xmlwriter->startElement('sphinx:schema');
$xmlwriter->startElement('sphinx:field');
$xmlwriter->writeAttribute("name", "content");
$xmlwriter->endElement(); // field
$xmlwriter->startElement('sphinx:attr');
$xmlwriter->writeAttribute("name", "path");
$xmlwriter->writeAttribute("type", "string");
$xmlwriter->endElement(); // attr
$xmlwriter->endElement(); // schema
$xmlwriter->startElement('sphinx:document');
$xmlwriter->writeAttribute("id", 1);
$xmlwriter->startElement("content");
$xmlwriter->text("TEST_CONTENT2");
$xmlwriter->endElement(); // field
$xmlwriter->startElement("path");
$xmlwriter->text("TEST_ATTRIBUTE2");
$xmlwriter->endElement(); // field
$xmlwriter->endElement(); // doc
$xmlwriter->endElement(); // docset
print $xmlwriter->outputMemory(true);
我使用 PHP XMLWriter:
$xmlwriter->startElement('sphinx:schema');
$xmlwriter->startElement('spinx:attribute');
$xmlwriter->writeAttribute("name", "path");
$xmlwriter->writeAttribute("type", "string");
$xmlwriter->endElement(); // attr
$xmlwriter->startElement('sphinx:field');
$xmlwriter->writeAttribute("name", "content");
$xmlwriter->endElement(); // field
$xmlwriter->endElement(); // schema
$xmlwriter->startElement('sphinx:document');
$xmlwriter->writeAttribute("id", 1);
$xmlwriter->writeAttribute("path", "TEST_ATTRIBUTE");
$xmlwriter->startElement("content");
$xmlwriter->text("TEST_CONTENT");
$xmlwriter->endElement(); // field
$xmlwriter->endElement(); // doc
$xmlwriter->endElement(); // docset
所以我得到:
<?xml version="1.0" encoding="UTF-8"?>
<sphinx:docset>
<sphinx:schema>
<spinx:attribute name="path" type="string"/> - why there is '/>' not '>'?
<sphinx:field name="content"/>
</sphinx:schema>
<sphinx:document id="1" path="TEST_ATTRIBUTE">
<content>TEST_CONTENT</content>
</sphinx:document>
</sphinx:docset>
所以我尝试:indexer --rotate --all --config /etc/sphinxsearch/sphinx.conf 狮身人面像 2.2.11-id64-release (95ae9a6) 使用配置文件 'sphinx.conf'... 索引指数 'test1'...
警告:属性计数为 0:切换到 none docinfo
所以我在索引中没有得到属性。
好像打错了...
$xmlwriter->startElement('spinx:attribute');
-----^
why there is '/>' not '>'?
https://www.google.com/search?q=XML+closing+tags
Each tag opened has to be closed. XML is pedantic about this. However, if a tag is empty (no content), a single tag can serve as both the opening and closing tag if it ends with /> rather than with > . XML - Libxml2 http://www.xmlsoft.org/XMLinfo.html
这是正确的代码!!!
$xmlwriter = new xmlWriter();
$xmlwriter->openMemory();
$xmlwriter->setIndent(true);
$xmlwriter->startDocument('1.0','UTF-8');
$xmlwriter->startElement('sphinx:docset');
$xmlwriter->startElement('sphinx:schema');
$xmlwriter->startElement('sphinx:field');
$xmlwriter->writeAttribute("name", "content");
$xmlwriter->endElement(); // field
$xmlwriter->startElement('sphinx:attr');
$xmlwriter->writeAttribute("name", "path");
$xmlwriter->writeAttribute("type", "string");
$xmlwriter->endElement(); // attr
$xmlwriter->endElement(); // schema
$xmlwriter->startElement('sphinx:document');
$xmlwriter->writeAttribute("id", 1);
$xmlwriter->startElement("content");
$xmlwriter->text("TEST_CONTENT2");
$xmlwriter->endElement(); // field
$xmlwriter->startElement("path");
$xmlwriter->text("TEST_ATTRIBUTE2");
$xmlwriter->endElement(); // field
$xmlwriter->endElement(); // doc
$xmlwriter->endElement(); // docset
print $xmlwriter->outputMemory(true);