A
A
andrei20182018-06-10 13:43:30
PHP
andrei2018, 2018-06-10 13:43:30

How to correctly add an attribute to the Sphinx index?

I form the XML:

$xmlwriter = new xmlWriter();
$xmlwriter->openMemory();
$xmlwriter->setIndent(true);
$xmlwriter->startDocument('1.0','UTF-8');
$xmlwriter->startElement('sphinx:docset');

  $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

print $xmlwriter->outputMemory(true);

The result is:
<?xml version="1.0" encoding="UTF-8"?>
<sphinx:docset>
 <sphinx:schema>
  <spinx:attribute name="path" type="string"/>
  <sphinx:field name="content"/>
 </sphinx:schema>
 <sphinx:document id="1" path="TEST_ATTRIBUTE">
  <content>TEST_CONTENT</content>
 </sphinx:document>
</sphinx:docset>

Import into index:
# indexer --rotate --all 
Sphinx 2.2.11-id64-release (95ae9a6)
indexing index 'test1'...
WARNING: Attribute count is 0: switching to none docinfo
collected 3 docs, 0.0 MB

The search works, but the attribute does not get into the index.
How to add an attribute correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
andrei2018, 2018-06-11
@andrei2018

Understood:

$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(); // attr
   $xmlwriter->endElement(); // doc

$xmlwriter->endElement(); // docset

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question