Note that there are some explanatory texts on larger screens.

plurals
  1. POHow are efficient consecutive word searches implemented?
    primarykey
    data
    text
    <p>Search engines and databases allow you to use consecutive string search (such as <code>"this is a test"</code>), which matches <code>this is a test that will match</code>, but won't match <code>test this is a</code>.</p> <p>I know that some databases have built-in features that allow you to use the same functionality without writing a single line of code (e.g. MySQL's full text search). That's not the kind of answer I am looking for.</p> <p>What I want to know is what kind of algorithm and database structures are used to enable this fast searching of strings.</p> <p>What would the indexed table look like given the above example? Would it be something similar to this?</p> <pre><code>// IndexedItemID | Position | Word 1 | 0 | this 1 | 1 | is 1 | 2 | a 1 | 3 | test 1 | 4 | that 1 | 5 | will 1 | 6 | match 2 | 0 | test 2 | 1 | this 2 | 2 | is 2 | 3 | a </code></pre> <p>Now that there are indexed items, how do you efficiently create a SQL statement that matches those items?</p> <p>Here's one example I can think of:</p> <pre><code>select IndexedItemID form (select IndexedItemID, Position from indexedWords where Word = "this") as word1Position where exists(select * from indexedWords where IndexedItemID = word1Position.IndexedItemID AND Word = "is" AND Position = word1Position.Position + 1) AND exists(select * from indexedWords where IndexedItemID = word1Position.IndexedItemID AND Word = "a" AND Position = word1Position.Position + 2) AND exists(select * from indexedWords where IndexedItemID = word1Position.IndexedItemID AND Word = "test" AND Position = word1Position.Position + 3) </code></pre> <p>I'm sure there is probably a more standardized way that's more efficient.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload