Output XML file for sphinx or manticore search

Hello.
I just finished my website search function with manticoresearch.
I have been playing Hugo for about 10 days. It is a realy great tool.
I want to share the hugo part here.
I add the following code to config.toml

[outputFormats]
  [outputFormats.sphinx]
    baseName = "sphinx"
    isPlainText = true
    mediaType = "application/xml"
    path = "/"

[outputs]
home = [ "HTML", "RSS", "sphinx" ]

and on layout/_default/ folder I create a new file list.sphinx.xml. The content is below:

        <?xml version="1.0" encoding="utf-8"?>
        <sphinx:docset>
            <sphinx:schema>
              <sphinx:field name="title"/>
              <sphinx:attr name="title" type="string"/>
              <sphinx:attr name="link" type="string"/>
              <sphinx:field name="content"/>
              <sphinx:attr name="content" type="string"/>
              <sphinx:attr name="pubDate" type="timestamp"/>
              
            </sphinx:schema>
            {{ range $i, $e:= .Pages }}
            <sphinx:document id="{{ add $i 1080 }} ">
              <title><![CDATA[{{ .Title }}]]></title>
              <link><![CDATA[{{ .Permalink }}]]></link>
              <pubDate>{{ (time ( .Date)).Unix }}</pubDate>
              <content><![CDATA[{{ .Plain }}]]></content>
             </sphinx:document>
            {{ end }}
          
        </sphinx:docset>

That’s all. Hugo will generate a sphinx.xml on root folder. Then It can be indexed by sphinxsearch or manticoresearch.

This way, you can make a search function by your own.

2 Likes