3

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?

  • You can use your prefix search and boolean 'or' it with a search term for `*bcde`. You may be able to replace the entire query with just `*bcde*` although I think that would fail to include matches that have bcde at the start or end, so you'd also need to include terms for `*bcde` and `bcde*` in your query – alexroussos Dec 30 '16 at 17:34
  • Thanx a lot for your help Alex. So, I'm trying to follow your advice here, but I might be missing something. In the test search tool of aws console, I use: Query Parser "Simple" and Default Operator "or". So I enter the search term: `*AHOO* *AHOO AHOO*` and I get results such as: AHOO, AHOORA, FOO@AHOO.COM but I don't get results like: FOO@YAHOO.COM My second observation is that I get exactly the same results if I enter: `*AHOO AHOO*` which implies that `*AHOO*` adds nothing to my query? Thanx a lot and have a great Year! – Vaggelis Fotis Jan 02 '17 at 10:02
  • If you're using boolean operators, I think you need to be using the structured query parser. Take a look at the url/querystring that cloudsearch is generating and make sure that makes sense. If using the structured parser doesn't help, feel free to paste that query string here and I'll sanity check it – alexroussos Jan 03 '17 at 15:36
  • I'm trying to do the same and can't find solution. For example : if people search `ing` I'd like to return string like `inglorious`, `sharing` or `sharingblabla`...any example how my query should looks like? I used the query tester on cloudsearch but can't return what I'd like :/ – Mickaël Leger Jul 12 '18 at 09:02

2 Answers2

1

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

    ],
];
braaterAfrikaaner
  • 1,072
  • 10
  • 20
arllondias
  • 111
  • 6
-2

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
Vishwanath gowda k
  • 1,675
  • 24
  • 26