Looking for an index were order matters

I am looking for an index that takes into account the order of the search terms. For example, I have the following documents:
1:"bla bla A B bla C bla"
2: "C A bla bla C D"

The search string: "bla A" should only return document 1 but not document 2 because the order isn't identical.

Welcome to our community! :smiley:

What is the mapping you are using here, because things like analysis will matter, as will the actual query.

1 Like

Thanks for the quick responds.
I actually think my example is not that good. Let me try to explain it again. My documents are chapters from books and the search queries are strings from the chapter with small errors (missing words, spelling errors).
I am currently working with the default bm25 and the results are decent for the books I have but they also return something for books that I don't have. This is often the case when the book belongs to series with reoccurring characters (star trek novels).
Now I thought that taking into account the order could help me out because it would make it unique for a book.

New example:
documents;{"star trek1": chapter:1, text:"...",
"star trek1": chapter:2, text:"...",
"star trek2": "...",
"star trek5": "..."
}
Search query: "Kirk asked Spoook for adviise"
Expected result star trek2 chapter 2 (this works fine with the bm25

Search query: "Kirk asked Bones help him out"
Expected result: None because this sentence is part of star trek 4 which not part of my index.

What you're looking for is an index that supports phrase search or proximity search. This type of index takes into account the relative positions of terms within a document. Traditional keyword-based indexes do not consider the order of terms in a search query.

To achieve the desired behavior, you can use an inverted index with positional information. In this type of index, each term is associated with its position within a document. When performing a phrase search, you can specify that the terms must appear in the same order and within a certain proximity of each other.

There are search engines and libraries that support phrase search, such as Elasticsearch, Apache Lucene, and Sphinx. These tools allow you to create an index and perform complex search queries, including proximity-based searches.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.