How to search for an exact sub-string in aws cloudsearch?

1.7k views Asked by At

When I search for 'bcde' I would like to get all of the following matches:

  • 'abcde'
  • 'bcdef'
  • 'abcdef'

What is the way to achieve this result in AWS cloudsearch (preferably with a simple query parser)? Prefix will not give me the first result. Is there any other way?

2

There are 2 answers

0
Vishwanath gowda k On

If your index field is of type "text", A simple structured query will return all the matches which include your query string.

Example

Query : ( and part_part_number:'009' )

Result:

1   _score  10.379914
part_part_number    009

2   _score  10.379914
part_part_number    A-009-DY

 3      _score  10.379914
part_part_number    BY-009
0
arllondias On

After a few attempts at examples and without success. I decided as follows:

I created a text-array field and stored it part by part of the string from back to front and it worked.

example: my string is "abcde" and i search bcde. this would not work but in my field text-field will be the following strings: e, de, cde, bcde, abcde. So you will find "abcde" because he will find the term in the text-array field.

Oh man, but if i search bcd this term not in text-array field. All right but the string "bcde" starts with "bcd" so IT WORKS! =)

my php file to insert looks like this:

$term = "abcde";

$arrStr = str_split($term);
$arrTerms = [];
$aux = 1;
foreach($arrStr as $str){
    $arrTerms[] = substr($term,($aux * -1));
    $aux++;
}

$data = [
    'type'   => 'add',
    'id'=> [your_id],
    'fields' => [
        'id'=> [your_id],
        'field-text' => $term
        'field-text-array' => $arrTerms

    ],
];