Search code examples
laravelelasticsearchmathjaxmathml

How to use elasticsearch for indexing formulas in MathML?


I have a Q&A website that use Elasticsearch on it and also use MathML to type formulas. For example

<math xmlns="http://www.w3.org/1998/Math/MathML">
    <mi>d</mi>
    <mi>e</mi>
    <mi>t</mi>
    <mo> </mo>
    <mi>A</mi>
    <mo>≠</mo>
    <mn>0</mn>
</math>

is the MathML code for det A ≠ 0.

the problem is that elasticsearch is indexing it like a simple text(not formula), so the result of searching "det" is nothing.


Solution

  • Your MathML is not semantically correct for what you are doing. It doesn't mean det A ≠ 0, but rather d * e * t A ≠ 0; that is the product of d, e, and t followed by A ≠ 0 (I'm not sure what the empty <mo> represents, but the space is ignored by MathML.)

    A better representation would be

    <math xmlns="http://www.w3.org/1998/Math/MathML">
        <mi>det</mi>
        <mo>&#x2061;</mo>
        <mi>A</mi>
        <mo>≠</mo>
        <mn>0</mn>
    </math>
    

    That might resolve your issue with searching as well, since now det will match something.