Text index of quotes in memory in Go

Recently I needed to implement search by the beginning of a string, in fact WHERE name LIKE '%'. It was a search by the name of exchange symbols (AAPL, AMZN, EUR / USD, etc.). I wanted the search to work quickly and not load the database again. As a result, I came to the implementation of tree search in memory, and I'll tell you about this.

55000 ( ). . , .

. , BTree, ( , ,  , trie), — . , .

. , .

.

, , . , , : 

  • AAA (BetaShares Australian High Interest Cash ETF, ASX), 

  • AAA (All Active Asset Capital LTD, LSE).

Index.Data , Index.Data AAA.

SearchIndex.Data . , .

, .

.

  1. .

  2. .

  3. .

  4. .

  5. , , ã → a.

  6. - ().

, — , .

, Index.Data .

. — Index.Children , ( — ). , AAPL, ( ):

[A], [A], [P], [L]. , . , .

, . , . , .

.

, — . .

  1. (. ).

  2. , . 

  3. .

, AA, :

  • AAL

  • AAALF

  • AAAP

  • AAB

  • AAP

  • AAPJ

  • AAPL

  • AAPT

, AA. .

WHERE name LIKE '%'. , , .

  • “EUR”, “EUR”, “EUR/USD”, “USD/EUR”. , .

  • , . , “APL”, “APL”, “AAPL” (Apple).

  • .

“EUR”, “EUR”, “EUR/USD”, “USD/EUR”, : . , “USD/EUR”, : “usd eur”, “eur”. “Grupo Financiero Galicia SA” “Grupo Financiero Galicia SA”, “Financiero Galicia SA”, “Galicia SA”, “SA”.

, 4 .

  1. .

  2. , .

  3. , .

  4. , .

, . .

  1. SearchSymbolIndex .

  2. SearchPopularIndex (10% ).

  3. SearchInstrumentIndex .

— .

var searchedData []searchindex.SearchData

searchedData = r.SearchSymbolIndex.Search(searchindex.SearchParams{
    Text: key,
    OutputSize: outputSize,
    Matching: searchsymbol.Strict,
})

searchedData = r.SearchPopularIndex.Search(searchindex.SearchParams{
    Text: key,
    OutputSize: outputSize,
    Matching: searchsymbol.Beginning,
    StartValues: searchedData,
})

searchedData = r.SearchSymbolIndex.Search(searchindex.SearchParams{
    Text: key,
    OutputSize: outputSize,
    Matching: searchindex.Beginning,
    StartValues: searchedData,
})

searchedData = r.SearchInstrumentIndex.Search(searchindex.SearchParams{
    Text: key,
    OutputSize: outputSize,
    Matching: searchindex.Beginning,
    StartValues: searchedData,
})

StartValues — , , , , , (OutputSize).

searchindex.Strict —  . 

searchindex.Beginning — .

, . 300 . , .

, 55000 2 , . 4 100-200 ( http ), .

This search is currently used in the financial api for developers, an example can be viewed on this page where you can try it live.




All Articles